You can load the standard UsernameToken over https policy [1] from a file with the following :
StAXOMBuilder builder = new StAXOMBuilder(/path/to/policyfile);org.apache.neethi.Policy policy = PolicyEngine.getPolicy(builder.getDocumentElement());
And then set this policy object in the Options instance of the ServiceClient instance:
options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,policy);
Now set the user name and password in the Options instance:
options.setUserName("foo");
options.setPassword("bar");
Thats it!
If we want to get rid of the part where we load the standard security
policy from a file, we can do that as well. Here we will have to
construct the policy using policy assertions from org.apache.ws.secpolicy*
Thanks, Ruchith1. http://wso2.org/repos/wso2/trunk/wsas/java/modules/core/conf/rampart/scenario1-policy.xml
Sean Conlon wrote:
I am using the deprecated class OutflowConfiguration in order to set my dynamic usernames and passwords in the OutflowSecurity parameter. Beloware the methods that I use to do this.What is an alternative approach for me to set my username and passworddynamically? Why was the OutflowConfiguration class deprecated?Others have documented this problem, but I have not found a viablesolution that makes sense. Thanks!//////////////////////////////////////////////////////////////////////////////// getStub () ////////////////////////////////////////////////////////////////////////////private PartnerAPIStub getStub() throws EmailException { PartnerAPIStub myStub = null;try { EndpointReference endPointReference = new EndpointReference(endpoint); ConfigurationContext configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem( null, ABSOLUTE_AXIS2_CLIENT_CONFIG_PATH);myStub = new PartnerAPIStub(configurationContext, endpoint); ServiceClient serviceClient = myStub._getServiceClient();Options options = serviceClient.getOptions();options.setTo(endPointReference);this.updateOutflowSecurity(myStub); } catch (AxisFault e) { // TODO JL - temp code throw new EmailException(e); }return myStub; }////////////////////////////////////////////////////////////////////////// updateOutflowSecurity() /////////////////////////////////////////////////////////////////////private void updateOutflowSecurity(PartnerAPIStub stub) {ServiceClient serviceClient = stub._getServiceClient(); Options options = serviceClient.getOptions();OutflowConfiguration ofc = new OutflowConfiguration(); ofc.setActionItems("UsernameToken");ofc.setUser(apiUsername);ofc.setPasswordType("PasswordText");options.setProperty(WSSHandlerConstants.OUTFLOW_SECURITY, ofc.getProperty());//pwcbhandler is of type PWCBHandler that is injected via Springoptions.setProperty(WSHandlerConstants.PW_CALLBACK_REF, pwcbhandler); }
signature.asc
Description: OpenPGP digital signature
