axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Kempf" <petek...@gmail.com>
Subject can't get axis2 security working for client code
Date Tue, 16 Sep 2008 13:41:46 GMT
Using Axis2 1.4.1, Rampart 1.4, eclipse 3.4, jdk 1.5
I am unable to get the security to work.
I am basing it on this article
https://wso2.org/library/3415
only I'm running in eclipse.

This is the exception I get when I execute.  Any ideas what I'm doing wrong?
Obviously I'm missing something, probably related to the rampartconfig.


java.lang.NullPointerException
        at
org.apache.rampart.util.RampartUtil.setKeyIdentifierType(RampartUtil.java:1141)
        at
org.apache.rampart.builder.BindingBuilder.getSignatureBuider(BindingBuilder.java:243)
        at
org.apache.rampart.builder.AsymmetricBindingBuilder.doSignature(AsymmetricBindingBuilder.java:626)
        at
org.apache.rampart.builder.AsymmetricBindingBuilder.doSignBeforeEncrypt(AsymmetricBindingBuilder.java:413)
        at
org.apache.rampart.builder.AsymmetricBindingBuilder.build(AsymmetricBindingBuilder.java:93)
        at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:147)
        at
org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:64)
        at org.apache.axis2.engine.Phase.invoke(Phase.java:317)
        at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:429)
        at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401)
        at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
        at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
        at
com.myco.ws.test.JmeterserviceSecStub.addition(JmeterserviceSecStub.java:240)
        at com.myco.ws.test.TestClient.main(TestClient.java:57)




package com.myco.ws.test;


import java.util.Properties;

import com.myco.ws.test.PWCBHandler;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.PolicyInclude;
import org.apache.neethi.Policy;
import org.apache.rampart.policy.model.CryptoConfig;
import org.apache.rampart.policy.model.RampartConfig;

import com.myco.ws.test.JmeterserviceSecStub.Addition;
import com.myco.ws.test.JmeterserviceSecStub.AdditionResponse;

public class TestClient {

        /**
         * @param args
         */
        public static void main(String[] args) {


                try {

//                        System.setProperty("javax.net.ssl.trustStore",
"WebContent/WEB-INF/.keystore");
//
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");




                        ConfigurationContext ctx =
ConfigurationContextFactory.createConfigurationContextFromFileSystem("WebContent/WEB-INF",
null);

                JmeterserviceSecStub stub = new JmeterserviceSecStub(ctx,"
https://localhost:58443/WSTestService/services/JmeterserviceSec?wsdl");

                ServiceClient sc = stub._getServiceClient();
                sc.engageModule("rampart");

                Policy rampartPolicy = getRampartConfig();

//sc.getAxisService().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_SERVICE_POLICY,
rampartPolicy);
                //AxisService.getPolicyInclude()     Deprecated. As of
release 1.4, replaced by getPolicySubject()

sc.getAxisService().getPolicySubject().attachPolicy(rampartPolicy);


                /*
                Options options = sc.getOptions();
                options.setUserName("apache");
                options.setPassword("password");
                */

                        //JmeterserviceStub stub = new JmeterserviceStub("
http://localhost:58080/WSTestService/services/Jmeterservice?wsdl");
                        Addition add = new Addition();
                        add.setX(1);
                        add.setY(2);
                        AdditionResponse addresp = stub.addition(add);
                        System.out.println("Response=" +
addresp.get_return());


                } catch (Exception e) {
                        System.out.println("Exception:"+e);
                        e.printStackTrace();
                }

        }

        private static Policy getRampartConfig () {

                RampartConfig rampartConfig = new RampartConfig();
                  rampartConfig.setUser("client");

rampartConfig.setPwCbClass("com.myco.ws.test.PWCBHandler");


                  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","WebContent/WEB-INF/keystore");

props.setProperty("org.apache.ws.security.crypto.merlin.keystore.password",
"changeit");

                  sigCrypto.setProp(props);

                  rampartConfig.setSigCryptoConfig(sigCrypto);

                  Policy policy = new Policy();
                  policy.addAssertion(rampartConfig);

                  return policy;
        }

}

Mime
View raw message