You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by amitru <am...@gmail.com> on 2013/05/04 21:31:14 UTC

CXF WSS4J Interceptors

My Enviromnet:
--------------------
Application Server: JBOSS-AS7.1.1.Final JAVA: 1.7

Below is the Web Service code when I am sending request from Client it
doesn't check for security parameters mentioned in proprty file and returns
success call, i want interceptors to work as I dont
know spring i want to use wss4j api only, plz help.


Prop File:- (inside WEB-INF/classes) 

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=changeit123
org.apache.ws.security.crypto.merlin.keystore.file=publicstore.jks
org.apache.ws.security.crypto.merlin.keystore.alias=amit


import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;

// Client side Logging related CXF APIs
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;

import client.DemoCXF;
import client.DemoCXFService;
import client.Employee;

public class TestCXF
  {
     public static void main(String ar[]) throws Exception
      {
        String WSDL_URL="http://localhost:8080/cxfpoc?wsdl";
        DemoCXFService service=new DemoCXFService(new URL(WSDL_URL));
        DemoCXF port=service.getDemoCXFPort();

        /* Following part of code is needed for client side Logging of Soap
request/response */
        /* We need to make sure that we place the "log4j.properties" file
inside clients classpath */
        Client client = ClientProxy.getClient(port);
        client.getInInterceptors().add(new LoggingInInterceptor());
        client.getOutInterceptors().add(new LoggingOutInterceptor());

        Map<String,Object> outProps = new HashMap<String,Object>();
        
        outProps.put(WSHandlerConstants.ACTION, 
        	    WSHandlerConstants.TIMESTAMP + " " + 
        	    WSHandlerConstants.SIGNATURE + " " + 
        	    WSHandlerConstants.ENCRYPT);

     outProps.put(WSHandlerConstants.MUST_UNDERSTAND, "0");


        outProps.put(WSHandlerConstants.ACTION, "Signature");
        outProps.put(WSHandlerConstants.USER, "amit");
        outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,
KeystorePasswordCallback.class.getName());

        outProps.put(WSHandlerConstants.SIG_PROP_FILE,
"client_sign.properties");
        WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
        
        org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
        
        cxfEndpoint.getOutInterceptors().add(wssOut);
        
          
        Employee emp=new Employee();
        emp.setEmpNo(1000L);
        emp.setEmpName("MiddlewaremagicEmployee");
        emp.setEmpSalary(6000L);

        System.out.println("\n\nBefore  EmpNo: "+emp.getEmpNo()+", 
Name:"+emp.getEmpName()+",  Sal:"+emp.getEmpSalary());
        emp=port.processEmployeeSalary(emp,1000L);
        System.out.println("\n\nAfter   EmpNo: "+emp.getEmpNo()+", 
Name:"+emp.getEmpName()+",  Sal:"+emp.getEmpSalary());
      }
  }




--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-WSS4J-Interceptors-tp5727229.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: AW: CXF WSS4J Interceptors

Posted by amitru <am...@gmail.com>.

Hello Dirk,

I am using :- 

1) Application server jboss-as-7.1.1.Final 
2) JAVA Ver: 1.7
3) Apache CXF Ver: 2.4.6


Below is my server code: -
-------------------------------

DemoCXFI.java -->

package ws;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;


@WebService(targetNamespace = "http://test.org", name = "DemoCXF")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface DemoCXFI {
	@WebMethod()
	@WebResult(targetNamespace = "http://test.org", name = "updatedEmployee")
	public Employee processEmployeeSalary(
			@WebParam(partName = "employee", name = "employee", targetNamespace =
"http://test.org") Employee emp,
			@WebParam(partName = "incrementAmount", name = "incrementAmount",
targetNamespace = "http://test.org") Long incrementAmount) ;
}

-----------

DemoCXF.java --->


package ws;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
import org.apache.ws.security.handler.WSHandlerConstants;

@WebService(name = "DemoCXF", serviceName = "DemoCXFService", portName =
"DemoCXFPort", targetNamespace = "http://test.org")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public class DemoCXF  implements DemoCXFI{
	@WebMethod()
	@WebResult(targetNamespace = "http://test.org", name = "updatedEmployee")
	public Employee processEmployeeSalary(
			@WebParam(partName = "employee", name = "employee", targetNamespace =
"http://test.org") Employee emp,
			@WebParam(partName = "incrementAmount", name = "incrementAmount",
targetNamespace = "http://test.org") Long incrementAmount) {

		Map<String, Object> inProps = new HashMap<String, Object>();

		inProps.put(WSHandlerConstants.ACTION, "Signature");
		inProps.put(WSHandlerConstants.SIG_PROP_FILE, "server.properties");
   	    inProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,
KeystorePasswordCallback.class.getName());
 	    WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
		
		
		try {
			Service cxfService = Service.create(new URL(
					"http://localhost:8080/cxfpoc?wsdl"), new QName(
							"http://test.org", "DemoCXFService"));
			DemoCXFI mySer = cxfService.getPort(DemoCXFI.class); 
	        Client client = ClientProxy.getClient(mySer); 
	        client.getInInterceptors().add(new LoggingInInterceptor());
	        client.getOutInterceptors().add(new LoggingOutInterceptor());
			Endpoint cxfEndpoint = client.getEndpoint();
			cxfEndpoint.getInInterceptors().add(wssIn);
			System.out.println("[DemoCXF] Before processing: " + emp);
			long incrementedSalary = emp.getEmpSalary() + incrementAmount;
			emp.setEmpSalary(incrementedSalary);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return emp;
	}
}




--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-WSS4J-Interceptors-not-working-tp5727229p5727499.html
Sent from the cxf-user mailing list archive at Nabble.com.

AW: CXF WSS4J Interceptors

Posted by "Lattermann, Dirk" <Di...@datagroup.de>.
Hi,

if you expect help, you should write more about the environment you are using, and how you implement the services (server side).

Right now, we are experiencing a similar effect while moving from JBoss EAP 6.0.0 to JBoss EAP 6.0.1 with CXF webservices implemented as Servlets. We're still investigating, but it seems in our case the CXF @InInterceptors annotation is ignored so that the WSS4JInInterceptor is not put into the interceptor chain.

Dirk

-----Ursprüngliche Nachricht-----
Von: amitru [mailto:amit.ruwali@gmail.com]
Gesendet: Donnerstag, 9. Mai 2013 08:33
An: users@cxf.apache.org
Betreff: Re: CXF WSS4J Interceptors


Thanks for the reply.

I am new to CXF and X509 based implementations.

When I am removing MustUnderstand to "0" i am getting errors so I have added this by checking in some forums. I would really a help if you can guide me how to solve this problem.

As per me the Clinet code is OK, there is an issue with a server code which is not able to check security using interceptors. I also have no knowledge of Spring Framework and i want to do the same in the java code itself.





--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-WSS4J-Interceptors-not-working-tp5727229p5727450.html
Sent from the cxf-user mailing list archive at Nabble.com.
--------------------------------------------------------
DATAGROUP BGS GmbH
Dirk Lattermann


Auf den Tongruben 3
D-53721 Siegburg
Fon: +49 2241 166-531
Fax: +49 2241 166-680
E-Mail: Dirk.Lattermann@datagroup.de
http://www.datagroup.de

Sie finden uns auch auf:
Facebook<https://www.facebook.com/#!/datagroupag/> | Xing<https://www.xing.com/companies/datagroupag/updates/> | Google+<https://plus.google.com/s/datagroup#112017044868465108697/posts> | LinkedIn<http://www.linkedin.com/company/datagroup-ag/> | Kununu<http://www.kununu.com/de/all/de/it/datagroup/>

Geschäftsführung: Hans-Hermann Schaber
Amtsgericht Mainz, HRB 44217

DATAGROUP ist als einer von wenigen IT-Dienstleistern zertifiziert nach ISO 20000, der höchstmöglichen Auszeichnung für professionelles IT Service Management.

Re: CXF WSS4J Interceptors

Posted by amitru <am...@gmail.com>.
Thanks for the reply.

I am new to CXF and X509 based implementations.

When I am removing MustUnderstand to "0" i am getting errors so I have added
this by checking in
some forums. I would really a help if you can guide me how to solve this
problem.

As per me the Clinet code is OK, there is an issue with a server code which
is not able to check
security using interceptors. I also have no knowledge of Spring Framework
and i want to do the 
same in the java code itself. 





--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-WSS4J-Interceptors-not-working-tp5727229p5727450.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: AW: CXF WSS4J Interceptors

Posted by amitru <am...@gmail.com>.
Hello Dirk ,

I referred to this Page:- http://cxf.apache.org/docs/ws-security.html for
this implementation, i stuck in 
the line "  EndpointImpl jaxWsEndpoint = (EndpointImpl)
EndpointImpl.publish(WSDL_URL, new DemoCXF());
" (see code below), so i tried in different direction, let me know how can i
acheive this via annotations.

The complete steps i have mentioned in below URL:-

http://stackoverflow.com/questions/15703041/issues-in-x509-implementation-using-cxf-ws-in-jboss-7


Old Server Side implementation :--
------------------------------------

@WebService(name = "DemoCXF", serviceName = "DemoCXFService", portName =
"DemoCXFPort", targetNamespace = "http://test.org")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public class DemoCXF {

    @WebMethod()
    @WebResult(targetNamespace = "http://test.org", name =
"updatedEmployee")
    public Employee processEmployeeSalary(
        @WebParam(partName = "employee", name = "employee", targetNamespace
= "http://test.org") 
        Employee emp,
        @WebParam(partName = "incrementAmount", name = "incrementAmount",
targetNamespace = "http://test.org")
        Long incrementAmount) {
        Map<String,Object> inProps= new HashMap<String,Object>();
        inProps.put(WSHandlerConstants.ACTION, "Signature");
        inProps.put(WSHandlerConstants.SIG_PROP_FILE, "server.properties");

        EndpointImpl jaxWsEndpoint = (EndpointImpl)
EndpointImpl.publish(WSDL_URL, new DemoCXF());

        Endpoint cxfEndpoint = jaxWsEndpoint.getServer().getEndpoint();

        WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
        cxfEndpoint.getInInterceptors().add(wssIn);

        System.out.println("[DemoCXF] Method
Invoked....processEmployeeSalary");

        System.out.println("[DemoCXF] Before processing: " + emp);

        long incrementedSalary = emp.getEmpSalary() + incrementAmount;

        emp.setEmpSalary(incrementedSalary);

        System.out.println("[DemoCXF] After processing: " + emp);

        return emp;
    }
}



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-WSS4J-Interceptors-not-working-tp5727229p5727501.html
Sent from the cxf-user mailing list archive at Nabble.com.

AW: AW: CXF WSS4J Interceptors

Posted by "Lattermann, Dirk" <Di...@datagroup.de>.
>I referred to this Page:- http://cxf.apache.org/docs/ws-security.html
> for this implementation, i stuck in the line
>"  EndpointImpl jaxWsEndpoint = (EndpointImpl) EndpointImpl.publish(WSDL_URL, new DemoCXF()); "
> (see code below), so i tried in different direction, let me know
>how can i acheive this via annotations.

As far as I know, in an application server, normally the server is responsible for publishing the endpoint. Normally this happens if you use the @WebService annotation together with the @Servlet annotation (publishing the web service as a servlet) or the @Stateless annotation (publishing it as an EJB) -- you could also use XML descriptors to define the servlet or EJB.

I'm not sure how manually publishing the endpoint works in the context of an application server, I never tried that.

Greetings,
Dirk

--------------------------------------------------------
DATAGROUP BGS GmbH
Dirk Lattermann


Auf den Tongruben 3
D-53721 Siegburg
Fon: +49 2241 166-531
Fax: +49 2241 166-680
E-Mail: Dirk.Lattermann@datagroup.de
http://www.datagroup.de

Sie finden uns auch auf:
Facebook<https://www.facebook.com/#!/datagroupag/> | Xing<https://www.xing.com/companies/datagroupag/updates/> | Google+<https://plus.google.com/s/datagroup#112017044868465108697/posts> | LinkedIn<http://www.linkedin.com/company/datagroup-ag/> | Kununu<http://www.kununu.com/de/all/de/it/datagroup/>

Geschäftsführung: Hans-Hermann Schaber
Amtsgericht Mainz, HRB 44217

DATAGROUP ist als einer von wenigen IT-Dienstleistern zertifiziert nach ISO 20000, der höchstmöglichen Auszeichnung für professionelles IT Service Management.

Re: CXF WSS4J Interceptors

Posted by Colm O hEigeartaigh <co...@apache.org>.
I'd suggest looking at your client configuration again. You define
WSHandlerConstants.ACTION twice, once for Signature, and once for
Signature, Encryption + Timestamp. Do you really mean to set MustUnderstand
to "0" as well?

Colm.


On Sat, May 4, 2013 at 8:31 PM, amitru <am...@gmail.com> wrote:

>
> My Enviromnet:
> --------------------
> Application Server: JBOSS-AS7.1.1.Final JAVA: 1.7
>
> Below is the Web Service code when I am sending request from Client it
> doesn't check for security parameters mentioned in proprty file and returns
> success call, i want interceptors to work as I dont
> know spring i want to use wss4j api only, plz help.
>
>
> Prop File:- (inside WEB-INF/classes)
>
>
> org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
> org.apache.ws.security.crypto.merlin.keystore.type=jks
> org.apache.ws.security.crypto.merlin.keystore.password=changeit123
> org.apache.ws.security.crypto.merlin.keystore.file=publicstore.jks
> org.apache.ws.security.crypto.merlin.keystore.alias=amit
>
>
> import java.net.URL;
> import java.util.HashMap;
> import java.util.Map;
>
> import javax.xml.namespace.QName;
> import javax.xml.ws.BindingProvider;
>
> // Client side Logging related CXF APIs
> import org.apache.cxf.endpoint.Client;
> import org.apache.cxf.frontend.ClientProxy;
> import org.apache.cxf.interceptor.LoggingInInterceptor;
> import org.apache.cxf.interceptor.LoggingOutInterceptor;
> import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
> import org.apache.ws.security.WSConstants;
> import org.apache.ws.security.handler.WSHandlerConstants;
>
> import client.DemoCXF;
> import client.DemoCXFService;
> import client.Employee;
>
> public class TestCXF
>   {
>      public static void main(String ar[]) throws Exception
>       {
>         String WSDL_URL="http://localhost:8080/cxfpoc?wsdl";
>         DemoCXFService service=new DemoCXFService(new URL(WSDL_URL));
>         DemoCXF port=service.getDemoCXFPort();
>
>         /* Following part of code is needed for client side Logging of Soap
> request/response */
>         /* We need to make sure that we place the "log4j.properties" file
> inside clients classpath */
>         Client client = ClientProxy.getClient(port);
>         client.getInInterceptors().add(new LoggingInInterceptor());
>         client.getOutInterceptors().add(new LoggingOutInterceptor());
>
>         Map<String,Object> outProps = new HashMap<String,Object>();
>
>         outProps.put(WSHandlerConstants.ACTION,
>                     WSHandlerConstants.TIMESTAMP + " " +
>                     WSHandlerConstants.SIGNATURE + " " +
>                     WSHandlerConstants.ENCRYPT);
>
>      outProps.put(WSHandlerConstants.MUST_UNDERSTAND, "0");
>
>
>         outProps.put(WSHandlerConstants.ACTION, "Signature");
>         outProps.put(WSHandlerConstants.USER, "amit");
>         outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,
> KeystorePasswordCallback.class.getName());
>
>         outProps.put(WSHandlerConstants.SIG_PROP_FILE,
> "client_sign.properties");
>         WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
>
>         org.apache.cxf.endpoint.Endpoint cxfEndpoint =
> client.getEndpoint();
>
>         cxfEndpoint.getOutInterceptors().add(wssOut);
>
>
>         Employee emp=new Employee();
>         emp.setEmpNo(1000L);
>         emp.setEmpName("MiddlewaremagicEmployee");
>         emp.setEmpSalary(6000L);
>
>         System.out.println("\n\nBefore  EmpNo: "+emp.getEmpNo()+",
> Name:"+emp.getEmpName()+",  Sal:"+emp.getEmpSalary());
>         emp=port.processEmployeeSalary(emp,1000L);
>         System.out.println("\n\nAfter   EmpNo: "+emp.getEmpNo()+",
> Name:"+emp.getEmpName()+",  Sal:"+emp.getEmpSalary());
>       }
>   }
>
>
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/CXF-WSS4J-Interceptors-tp5727229.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>



-- 
Colm O hEigeartaigh

Talend Community Coder
http://coders.talend.com