title: Metro UsernameToken Policy
body: <p>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.</p>
  
  <p>Policy.xml</p>
  
  <pre><code> &lt;?xml version="1.0"?&gt;  
       &lt;wsp:Policy  
         xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"  
         xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512"&gt;  
         &lt;sp:SupportingTokens&gt;  
           &lt;wsp:Policy&gt;  
             &lt;sp:UsernameToken  
               sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512/IncludeToken/AlwaysToRecipient"&gt;  
               &lt;wsp:Policy&gt;  
                 &lt;sp:WssUsernameToken10/&gt;
                 &lt;sp:HashPassword/&gt;
               &lt;/wsp:Policy&gt;  
             &lt;/sp:UsernameToken&gt;  
           &lt;/wsp:Policy&gt;  
         &lt;/sp:SupportingTokens&gt;  
       &lt;/wsp:Policy&gt;
  </code></pre>
  
  <p>Client.java (Weblogic)</p>
  
  <pre><code>      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&lt;CredentialProvider&gt; credProviders = new ArrayList&lt;CredentialProvider&gt;();    
        String username = "user";
        String password = "pass";
        CredentialProvider cp = new ClientUNTCredentialProvider(username.getBytes(), password.getBytes());     
        credProviders.add(cp);
  
        Map&lt;String, Object&gt; rc = ((BindingProvider) client).getRequestContext();  
        rc.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);
  
  ... 
  </code></pre>
  
  <p>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.</p>