Wednesday, April 21, 2010

Username Token security call on web service

Code snippet:
SAD_ADMISSIONS sAD_ADMISSIONS;
SADCREATEAPPLRESP respCreateAppl = new SADCREATEAPPLRESP();
System.out.println("Before Try..in Create Appl");
try {

// Security Policy is set to User Name Token
SecurityPolicyFeature[] securityFeatures =
new SecurityPolicyFeature[] { new SecurityPolicyFeature("oracle/wss_username_token_client_policy") };

sAD_ADMISSIONS = new SAD_ADMISSIONS();

// port object is created passing in the security policy
SAD_ADMISSIONS_PortType sAD_ADMISSIONS_PortType = sAD_ADMISSIONS.getSAD_ADMISSIONS_Port(securityFeatures);

// request context object created
Map requestContext = ((BindingProvider) sAD_ADMISSIONS_PortType).getRequestContext();
SAD_ADMISSIONS_PortClient.setPortCredentialProviderList(requestContext);

System.out.println("Username/password:" + username + "/" +password);
requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);

// service operation called
respCreateAppl = sAD_ADMISSIONS_PortType.sadCREATEAPPL(reqCreateAppl);

} catch (Exception ex) {
ex.printStackTrace();
}

No comments:

Post a Comment