Example of WSO2 Service with HTTP Basic Authentication Over SSL Using Axis2 Client
Here i use RemoteUserStoreManagerService which is available in WSO2 identity server to demonstrate above scenario.
First go to "CARBON_HOME/repository/conf" folder and open "carbon.xml" file.
Change
<HideAdminServiceWSDLs>true</HideAdminServiceWSDLs>
to
<HideAdminServiceWSDLs>false</HideAdminServiceWSDLs>
Then you can access the RemoteUserStoreManagerService from following path.
https://{Hostname}:{port}/services/RemoteUserStoreManagerService?wsdl
Then include following jars to your classpath.
axis2-xmlbeans-1.6.2 axis2-transport-http-1.6.2 axis2-transport-local-1.6.2 axis2-adb-1.6.2 axis2-kernel-1.6.2 axiom-api-1.2.13 axiom-impl-1.2.13 neethi-3.0.2 XmlSchema-1.4.7 httpcore-4.0 mail-1.4 commons-httpclient-3.1 commons-codec-1.3 commons-logging-1.1.1 wsdl4j-1.6.2
Then create the stubs for above web service using axis2 wsdl2java tool. Type following code in a command prompt.
wsdl2java -uri {URL OF RemoteUserStoreManagerService} -pn {PORT NAME}
** -pn is optional
We can use following code snippet to access web service through above created stub using basic authentication.
RemoteUserStoreManagerServiceStub remoteUserStoreStub = new RemoteUserStoreManagerServiceStub(); SSLContext sslCntx = SSLContext.getInstance("SSL"); sslCntx.init(null, new TrustManager[] {new TrustAllTrustManager()}, new SecureRandom()); Options options = remoteUserStoreStub._getServiceClient().getOptions(); options.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER, new Protocol("HTTPS", (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslCntx), 443)); HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); List<String> auth = new ArrayList<String>(); auth.add(Authenticator.BASIC); authenticator.setUsername(ADMIN_USER); authenticator.setPassword(ADMIN_PWD); authenticator.setAuthSchemes(auth); options.setProperty(HTTPConstants.AUTHENTICATE, authenticator); options.setProperty(HTTPConstants.SO_TIMEOUT, TIME_OUT); options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, 1 * 60 * 1000);
Here ADMIN_USER is a username which has admin role assigned to, and ADMIN_PWD is that user's password.










