You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Shaan Jayaratna <ja...@predic8.de> on 2009/12/08 11:37:53 UTC

Problem using WSSPolicy with generated client stubs

Hi.

I want to use WSSPolicy with Axis2 1.5.1 and Rampart 1.4. Deploying the 
service with an attached Policy works fine. Creating the stubs with 
WSDL2Java don't cause an error. But when I send a request there are no 
WSSHeaders generated.

Rampart is engaged. Using the OutflowSecurity parameter WSS works on the 
client side.

Without the OutflowSecurity parameter I use the RampartConfig class to 
configure the client:

  RampartConfig rampartConfig = new RampartConfig();
  rampartConfig.setUser("client");
  rampartConfig.setPwCbClass("PWDCallback");
       
  CryptoConfig sigCrypto = new CryptoConfig();
  sigCrypto.setProvider("org.apache.ws.security.components.crypto.Merlin");
       
  Properties props = new Properties();
  
props.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", 
"JKS");
  
props.setProperty("org.apache.ws.security.crypto.merlin.file","client.jks");
  
props.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", 
"apache");
       
  sigCrypto.setProp(props);
       
  rampartConfig.setSigCryptoConfig(sigCrypto);
       
  Policy policy = new Policy();
  policy.addAssertion(rampartConfig);
  
stub._getServiceClient().getAxisService().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_SERVICE_POLICY, 
policy);

Thanks,
Shaan


Re: Problem using WSSPolicy with generated client stubs

Posted by Thilina Mahesh Buddhika <th...@gmail.com>.
a typo in the last line of code snippet.

options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy);

thanks.
/thilina

Thilina Mahesh Buddhika
http://blog.thilinamb.com


On Wed, Dec 9, 2009 at 6:27 PM, Thilina Mahesh Buddhika <thilinamb@gmail.com
> wrote:

> Hi Shaan,
>
> This is the widely used approach of attaching a security policy to a
> client.
>
>                 StAXOMBuilder builder = new
> StAXOMBuilder("/path/to/policy");
>         Policy policy
> = PolicyEngine.getPolicy(builder.getDocumentElement());
>
>         RampartConfig rc = new RampartConfig();
>         // set the parameters to rampart config.
>
>         policy.addAssertion(rc);
>
>         ServiceClient client = stub._getServiceClient();
>         Options option = client.getOptions();
>         options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
> loadPolicy(policy));
>
> HTH.
>
> Thanks.
> /thilina
>
> Thilina Mahesh Buddhika
> http://blog.thilinamb.com
>
>
>
> On Tue, Dec 8, 2009 at 4:07 PM, Shaan Jayaratna <ja...@predic8.de>wrote:
>
>> Hi.
>>
>> I want to use WSSPolicy with Axis2 1.5.1 and Rampart 1.4. Deploying the
>> service with an attached Policy works fine. Creating the stubs with
>> WSDL2Java don't cause an error. But when I send a request there are no
>> WSSHeaders generated.
>>
>> Rampart is engaged. Using the OutflowSecurity parameter WSS works on the
>> client side.
>>
>> Without the OutflowSecurity parameter I use the RampartConfig class to
>> configure the client:
>>
>>  RampartConfig rampartConfig = new RampartConfig();
>>  rampartConfig.setUser("client");
>>  rampartConfig.setPwCbClass("PWDCallback");
>>       CryptoConfig sigCrypto = new CryptoConfig();
>>  sigCrypto.setProvider("org.apache.ws.security.components.crypto.Merlin");
>>       Properties props = new Properties();
>>  props.setProperty("org.apache.ws.security.crypto.merlin.keystore.type",
>> "JKS");
>>
>>  props.setProperty("org.apache.ws.security.crypto.merlin.file","client.jks");
>>  props.setProperty("org.apache.ws.security.crypto.merlin.keystore.password",
>> "apache");
>>       sigCrypto.setProp(props);
>>       rampartConfig.setSigCryptoConfig(sigCrypto);
>>       Policy policy = new Policy();
>>  policy.addAssertion(rampartConfig);
>>  stub._getServiceClient().getAxisService().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_SERVICE_POLICY,
>> policy);
>>
>> Thanks,
>> Shaan
>>
>>
>

Re: Problem using WSSPolicy with generated client stubs

Posted by Thilina Mahesh Buddhika <th...@gmail.com>.
Hi Shaan,

This is the widely used approach of attaching a security policy to a client.

                StAXOMBuilder builder = new
StAXOMBuilder("/path/to/policy");
        Policy policy
= PolicyEngine.getPolicy(builder.getDocumentElement());

        RampartConfig rc = new RampartConfig();
        // set the parameters to rampart config.

        policy.addAssertion(rc);

        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
loadPolicy(policy));

HTH.

Thanks.
/thilina

Thilina Mahesh Buddhika
http://blog.thilinamb.com


On Tue, Dec 8, 2009 at 4:07 PM, Shaan Jayaratna <ja...@predic8.de>wrote:

> Hi.
>
> I want to use WSSPolicy with Axis2 1.5.1 and Rampart 1.4. Deploying the
> service with an attached Policy works fine. Creating the stubs with
> WSDL2Java don't cause an error. But when I send a request there are no
> WSSHeaders generated.
>
> Rampart is engaged. Using the OutflowSecurity parameter WSS works on the
> client side.
>
> Without the OutflowSecurity parameter I use the RampartConfig class to
> configure the client:
>
>  RampartConfig rampartConfig = new RampartConfig();
>  rampartConfig.setUser("client");
>  rampartConfig.setPwCbClass("PWDCallback");
>       CryptoConfig sigCrypto = new CryptoConfig();
>  sigCrypto.setProvider("org.apache.ws.security.components.crypto.Merlin");
>       Properties props = new Properties();
>  props.setProperty("org.apache.ws.security.crypto.merlin.keystore.type",
> "JKS");
>
>  props.setProperty("org.apache.ws.security.crypto.merlin.file","client.jks");
>  props.setProperty("org.apache.ws.security.crypto.merlin.keystore.password",
> "apache");
>       sigCrypto.setProp(props);
>       rampartConfig.setSigCryptoConfig(sigCrypto);
>       Policy policy = new Policy();
>  policy.addAssertion(rampartConfig);
>  stub._getServiceClient().getAxisService().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_SERVICE_POLICY,
> policy);
>
> Thanks,
> Shaan
>
>