Metro UsernameToken Policy
Posted
by Rodney
on Stack Overflow
See other posts from Stack Overflow
or by Rodney
Published on 2010-01-13T02:40:38Z
Indexed on
2010/04/01
0:03 UTC
Read the original article
Hit count: 644
I created a web services client prototype using api's available in weblogic 10.3. I've been told I need to use Metro 2.0 instead (it's already being used for other projects). The problem I have encounter is that the WSDL does not include any Security Policy information but a UsernameToken is required for each method call. In weblogic I was able to write my own policy xml file and instantiate my service with it (see below), however I can not seem to figure out how to do the same using Metro.
Policy.xml
<?xml version="1.0"?>
<wsp:Policy
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512">
<sp:SupportingTokens>
<wsp:Policy>
<sp:UsernameToken
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10/>
<sp:HashPassword/>
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SupportingTokens>
</wsp:Policy>
Client.java (Weblogic)
ClientPolicyFeature cpf = new ClientPolicyFeature();
InputStream asStream = WebServiceSoapClient.class.getResourceAsStream("Policy.xml");
cpf.setEffectivePolicy(new InputStreamPolicySource(asStream));
try
{
webService = new WebService(new URL("http://192.168.1.10/WebService/WebService.asmx?wsdl"), new QName("http://testme.com", "WebService"));
}
catch ( MalformedURLException e )
{
e.printStackTrace();
}
WebServiceSoap client = webService.getWebServiceSoap(new WebServiceFeature[] {cpf});
List<CredentialProvider> credProviders = new ArrayList<CredentialProvider>();
String username = "user";
String password = "pass";
CredentialProvider cp = new ClientUNTCredentialProvider(username.getBytes(), password.getBytes());
credProviders.add(cp);
Map<String, Object> rc = ((BindingProvider) client).getRequestContext();
rc.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);
...
I am able to generate my Proxy classes using Metro however I can not figure out how to configure it to send the UsernameToken. I have attempted several different examples from the web which have not worked. Any help would be appreciated.
© Stack Overflow or respective owner