简体   繁体   中英

Cannot load Rampart module within Axis2 client project

While my project is a Java web application, I use web services only as client.

I successfully created stubs with Apache Axis2 and tested them with SoapUI. Now it's time to implement security. This is one of the services I must integrate. It ships a WS-Security policy so that I must trasmit my credentials properly.

I want to integrate Apache Rampart into my project. I have found lots of difficulties downloading the required JARs and MAR file to use, but I made it.

Now I have the following project structure:

webapp
   -- WEB-INF
       -- classes
       -- conf
          -- axis2.xml
       -- modules
          -- several -mar files
          -- rampart-1.6.2.mar
          -- modules.list
       -- spring
          -- various context files
       -- web.xml

I use Spring to initialize all beans, including web service stubs. If I let Spring instantiate them normally, they work as expected. But when I use a BeanPostProcessor to engage the rampart module it will fail

Caused by: org.apache.axis2.AxisFault: Unable to engage module : rampart
at org.apache.axis2.client.ServiceClient.engageModule(ServiceClient.java:363)
at it.csttech.edwin.security.SecurityHandler.engage(SecurityHandler.java:52)

In my axis2.xml I have added <module ref="rampart" /> after addressing

I enable Rampart with the following code:

    RampartConfig rc = new RampartConfig();
    rc.setUser(user);
    Policy policy = PolicyEngine.getPolicy(new StAXOMBuilder(policyStream).getDocumentElement()); //XML policy file in classpath
    policy.addAssertion(rc);
    serviceClient.engageModule("rampart"); //this fails
    Options options = serviceClient.getOptions();
    options.setProperty(WSHandlerConstants.PW_CALLBACK_REF, callbackHandler); //This will provide password
    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy); //This will provide policy

I discovered that if I do Map<String, AxisModule> modules = serviceClient.getAxisConfiguration().getModules(); I just get an empty map!!!!

So no modules are loaded at all.

Then I tried to move the modules/ directory to another place on my hard drive, and link it via system property axis2.repo but even if Axis2 won't load if I willignly set a bad path, it just won't load the rampart-1.6.2.mar file and the map will be still empty.

I'm getting crazy. I don't know how to properly load Rampart into my setup. I don't even know if Spring IoC can be used to inject a proper configuration and/or engage Rampart in all services.

You can try creating ConfigurationContext and use it get ServiceClient.

// create configuration context
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(RESOURCES_DIR, null);

// create service client
ServiceClient serClient = new ServiceClient(ctx, null);

// engage modules
serClient.engageModule("rampart");

Where 'RESOURCES_DIR' should point to the location of your .mar files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM