You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Steven Thein <st...@oracle.com> on 2009/12/08 16:57:57 UTC

Exception during encrypting UsernameToken element...

Hi all,

                I was testing encrypting just the UsenameToken element using the example under "sign_enc"(CXF2.2.4)  folder by removing all the signing codes. I got the following exception during my test.  Is "UsernameToken"  the correct element name for   "encryptionParts" ?

 

 

javax.xml.ws.WebServiceException: Security processing failed.

     at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)

     at $Proxy40.greetMe(Unknown Source)

     at demo.wssec.client.Client.main(Client.java:101)

 Caused by: org.apache.ws.security.WSSecurityException: Error during encryption: ; nested exception is:

     org.apache.ws.security.WSSecurityException: General security error (WSEncryptBody/WSSignEnvelope: Element to encrypt/sign not found: {http://docs.oasis-open.org/wss/2004/01/oasis-20040

urity-utility-1.0.xsd}UsernameToken)

     at org.apache.ws.security.action.EncryptionAction.execute(EncryptionAction.java:64)

     at org.apache.ws.security.handler.WSHandler.doSenderAction(WSHandler.java:202)

     at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor.access$200(WSS4JOutInterceptor.java:47)

     at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:236)

     at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:122)

     at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)

     at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:478)

     at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:308)

     at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:260)

     at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)

     at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)

     ... 2 more

 Caused by: org.apache.ws.security.WSSecurityException: General security error (WSEncryptBody/WSSignEnvelope: Element to encrypt/sign not found: {http://docs.oasis-open.org/wss/2004/01/oasi

s-wssecurity-utility-1.0.xsd}UsernameToken)

     at org.apache.ws.security.message.WSSecEncrypt.doEncryption(WSSecEncrypt.java:505)

     at org.apache.ws.security.message.WSSecEncrypt.doEncryption(WSSecEncrypt.java:459)

     at org.apache.ws.security.message.WSSecEncrypt.encryptForInternalRef(WSSecEncrypt.java:348)

     at org.apache.ws.security.message.WSSecEncrypt.build(WSSecEncrypt.java:309)

     at org.apache.ws.security.action.EncryptionAction.execute(EncryptionAction.java:62)

     ... 12 more

 

 

 

 

The following is the client side code that I modified:

 

public final class Client {

 

    private static final String USER_NAME = System.getProperty("user.name");

    private static final String WSU_NS

        = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";

 

    private Client() {

    }

 

    public static void main(String args[]) throws Exception {

        try {

 

            SpringBusFactory bf = new SpringBusFactory();

            URL busFile = Client.class.getResource("wssec.xml");

            Bus bus = bf.createBus(busFile.toString());

            bf.setDefaultBus(bus);

 

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

            outProps.put("action", "UsernameToken Encrypt");

 

            outProps.put("passwordType", "PasswordText");

            outProps.put("user", "clientx509v1");

 

            //If you are using the patch WSS-194, then uncomment below two lines and

            //comment the above "user" prop line.

            //outProps.put("user", "abcd");

            //outProps.put("signatureUser", "clientx509v1");

 

            outProps.put("passwordCallbackClass", "demo.wssec.client.UTPasswordCallback");

 

            outProps.put("encryptionUser", "serverx509v1");

            outProps.put("encryptionPropFile", "etc/Client_Encrypt.properties");

            outProps.put("encryptionKeyIdentifier", "IssuerSerial");

            outProps.put("encryptionParts",

                         "{Element}{" + WSU_NS + "}UsernameToken;" );

/*

            outProps.put("signaturePropFile", "etc/Client_Sign.properties");

            outProps.put("signatureKeyIdentifier", "DirectReference");

            outProps.put("signatureParts",

                         "{Element}{" + WSU_NS + "}Timestamp;"

                         + "{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body");

*/

            bus.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));

 

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

 

            inProps.put("action", "UsernameToken Encrypt");

            inProps.put("passwordType", "PasswordText");

            inProps.put("passwordCallbackClass", "demo.wssec.client.UTPasswordCallback");

 

            inProps.put("decryptionPropFile", "etc/Client_Sign.properties");

            inProps.put("encryptionKeyIdentifier", "IssuerSerial");

/*

            inProps.put("signaturePropFile", "etc/Client_Encrypt.properties");

            inProps.put("signatureKeyIdentifier", "DirectReference");

*/

            bus.getInInterceptors().add(new WSS4JInInterceptor(inProps));

 

            GreeterService service = new GreeterService();

            Greeter port = service.getGreeterPort();

 

            String[] names = new String[] {"Anne", "Bill", "Chris", "Sachin Tendulkar"};

            // make a sequence of 4 invocations

            for (int i = 0; i < 1; i++) {

                System.out.println("Invoking greetMe...");

                String response = port.greetMe(names[i]);

                System.out.println("response: " + response + "\n");

            }

 

            // allow aynchronous resends to occur

            Thread.sleep(30 * 1000);

 

            bus.shutdown(true);

 

        } catch (UndeclaredThrowableException ex) {

            ex.getUndeclaredThrowable().printStackTrace();

        } catch (Exception ex) {

            ex.printStackTrace();

        } finally {

            System.exit(0);

        }

    }

}