Package org.apache.ws.security.common

Examples of org.apache.ws.security.common.CustomHandler


    /**
     * Test that adds a UserNameToken via WSHandler
     */
    @org.junit.Test
    public void testUsernameTokenWSHandler() throws Exception {
        CustomHandler handler = new CustomHandler();
        Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
       
        RequestData reqData = new RequestData();
        java.util.Map<String, Object> config = new java.util.TreeMap<String, Object>();
        config.put("password", "verySecret");
        config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
        reqData.setUsername("wernerd");
        reqData.setMsgContext(config);
       
        java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(WSConstants.UT));
       
        handler.send(WSConstants.UT, doc, reqData, actions, true);
       
        if (LOG.isDebugEnabled()) {
            LOG.debug("Username Token via WSHandler");
            String outputString =
                org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
View Full Code Here


    /**
     * Test that adds a UserNameToken with an empty password via WSHandler
     */
    @org.junit.Test
    public void testUsernameTokenWSHandlerEmptyPassword() throws Exception {
        CustomHandler handler = new CustomHandler();
        Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
       
        RequestData reqData = new RequestData();
        java.util.Map<String, Object> config = new java.util.TreeMap<String, Object>();
        config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
        config.put(WSHandlerConstants.PW_CALLBACK_REF, this);
        reqData.setUsername("emptyuser");
        reqData.setMsgContext(config);
       
        java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(WSConstants.UT));
       
        handler.send(WSConstants.UT, doc, reqData, actions, true);
       
        if (LOG.isDebugEnabled()) {
            LOG.debug("Username Token with an empty password via WSHandler");
            String outputString =
                org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
View Full Code Here

        reqData.setMsgContext(config);
       
        final java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(action));
        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
        CustomHandler handler = new CustomHandler();
        handler.send(
            action,
            doc,
            reqData,
            actions,
            true
View Full Code Here

    /**
     * Test that adds a UserNameToken via WSHandler
     */
    @org.junit.Test
    public void testUsernameTokenWSHandler() throws Exception {
        CustomHandler handler = new CustomHandler();
        Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
       
        RequestData reqData = new RequestData();
        java.util.Map<String, Object> config = new java.util.TreeMap<String, Object>();
        config.put("password", "verySecret");
        config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
        reqData.setUsername("wernerd");
        reqData.setMsgContext(config);
       
        java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(WSConstants.UT));
       
        handler.send(WSConstants.UT, doc, reqData, actions, true);
       
        if (LOG.isDebugEnabled()) {
            LOG.debug("Username Token via WSHandler");
            String outputString =
                org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
            LOG.debug(outputString);
        }
       
        //
        // It should pass even on a different password type, as we haven't set the
        // processing to be strict
        //
        config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
        reqData.setMsgContext(config);
        handler.receive(WSConstants.UT, reqData);
        WSSecurityEngine secEngine = new WSSecurityEngine();
        secEngine.setWssConfig(reqData.getWssConfig());
        secEngine.processSecurityHeader(doc, null, callbackHandler, null);
       
        //
        // It should fail on strict password type processing
        //
        config.put(WSHandlerConstants.PASSWORD_TYPE_STRICT, "true");
        reqData.setMsgContext(config);
        handler.receive(WSConstants.UT, reqData);
        try {
            secEngine.processSecurityHeader(doc, null, callbackHandler, null);
            fail("Expected failure on the wrong password type");
        } catch (WSSecurityException ex) {
            // expected
View Full Code Here

     * Test that uses a 32 byte key length for the secret key, instead of the default 16 bytes.
     * This test configures the key length via WSHandler.
     */
    @org.junit.Test
    public void testWSS226Handler() throws Exception {
        CustomHandler handler = new CustomHandler();
        Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
       
        RequestData reqData = new RequestData();
        reqData.setWssConfig(WSSConfig.getNewInstance());
        java.util.Map<String, Object> config = new java.util.TreeMap<String, Object>();
        config.put("password", "verySecret");
        config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
        config.put(WSHandlerConstants.WSE_SECRET_KEY_LENGTH, "32");
        config.put(WSHandlerConstants.USE_DERIVED_KEY, "false");
        reqData.setUsername("wernerd");
        reqData.setMsgContext(config);
       
        java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(WSConstants.UT_SIGN));
       
        handler.send(WSConstants.UT_SIGN, doc, reqData, actions, true);
       
        if (LOG.isDebugEnabled()) {
            LOG.debug("Username Token Signature via WSHandler");
            String outputString =
                org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
            LOG.debug(outputString);
        }
       
        //
        // It should fail on the default key length of 16...
        //
        try {
            secEngine.processSecurityHeader(doc, null, callbackHandler, null);
            fail("An error was expected on verifying the signature");
        } catch (Exception ex) {
            // expected
        }
       
        handler.receive(WSConstants.UT_SIGN, reqData);
       
        WSSecurityEngine wss226SecurityEngine = new WSSecurityEngine();
        wss226SecurityEngine.setWssConfig(reqData.getWssConfig());
        wss226SecurityEngine.processSecurityHeader(doc, null, callbackHandler, null);
    }
View Full Code Here

        reqData.setMsgContext(config);
       
        final java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(action));
        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
        CustomHandler handler = new CustomHandler();
        handler.send(
            action,
            doc,
            reqData,
            actions,
            true
View Full Code Here

        reqData.setUsername("");
       
        final java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(WSConstants.SIGN));
        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
        CustomHandler handler = new CustomHandler();
        handler.send(
            WSConstants.SIGN,
            doc,
            reqData,
            actions,
            true
        );
       
        String outputString =
            org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
        if (LOG.isDebugEnabled()) {
            LOG.debug(outputString);
        }
       
        reqData = new RequestData();
        reqData.setWssConfig(WSSConfig.getNewInstance());
        messageContext = new java.util.TreeMap<String, Object>();
        messageContext.put(WSHandlerConstants.PW_CALLBACK_REF, this);
        reqData.setMsgContext(messageContext);
        reqData.setUsername("");
       
        handler.receive(WSConstants.SIGN, reqData);
       
        secEngine.processSecurityHeader(doc, null, this, null, crypto);
    }
View Full Code Here

        reqData.setMsgContext(config);
       
        final java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(action));
        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
        CustomHandler handler = new CustomHandler();
        handler.send(
            action,
            doc,
            reqData,
            actions,
            true
View Full Code Here

    /**
     */
    @org.junit.Test
    public void
    testOrder() throws Exception {
        CustomHandler handler = new CustomHandler();
       
        java.util.List<WSSecurityEngineResult> results = new java.util.ArrayList<WSSecurityEngineResult>();
        results.add(
            new WSSecurityEngineResult(WSConstants.UT, (Timestamp)null)
        );
        results.add(
            new WSSecurityEngineResult(WSConstants.TS, (Timestamp)null)
        );
        results.add(
            new WSSecurityEngineResult(WSConstants.SC, (Timestamp)null)
        );
        results.add(
            new WSSecurityEngineResult(WSConstants.SIGN, (Timestamp)null)
        );
       
        java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(WSConstants.UT));
        actions.add(new Integer(WSConstants.TS));
        actions.add(new Integer(WSConstants.SIGN));
       
        assertTrue (handler.checkResults(results, actions));
        assertTrue (handler.checkResultsAnyOrder(results, actions));
    }
View Full Code Here

    /**
     */
    @org.junit.Test
    public void
    testReverseOrder() throws Exception {
        CustomHandler handler = new CustomHandler();
       
        java.util.List<WSSecurityEngineResult> results = new java.util.ArrayList<WSSecurityEngineResult>();
        results.add(
            new WSSecurityEngineResult(WSConstants.SIGN, (Timestamp)null)
        );
        results.add(
            new WSSecurityEngineResult(WSConstants.SC, (Timestamp)null)
        );
        results.add(
            new WSSecurityEngineResult(WSConstants.TS, (Timestamp)null)
        );
        results.add(
            new WSSecurityEngineResult(WSConstants.UT, (Timestamp)null)
        );
       
        java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
        actions.add(new Integer(WSConstants.UT));
        actions.add(new Integer(WSConstants.TS));
        actions.add(new Integer(WSConstants.SIGN));
       
        assertFalse (handler.checkResults(results, actions));
        assertTrue (handler.checkResultsAnyOrder(results, actions));
        assertTrue (results.size() == 4 && actions.size() == 3);
    }
View Full Code Here

TOP

Related Classes of org.apache.ws.security.common.CustomHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.