org.apache.cxf.phase.PhaseInterceptor Java Examples

The following examples show how to use org.apache.cxf.phase.PhaseInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimestamp() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    ohandler.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    ohandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/wsu:Timestamp", doc);
}
 
Example #2
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncrypt() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//s:Body/xenc:EncryptedData", doc);
}
 
Example #3
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignature() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myAlias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/ds:Signature", doc);
}
 
Example #4
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignature() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myAlias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/ds:Signature", doc);
}
 
Example #5
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncrypt() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//s:Body/xenc:EncryptedData", doc);
}
 
Example #6
Source File: CryptoCoverageCheckerTest.java    From steady with Apache License 2.0 6 votes vote down vote up
private void runInterceptorAndValidate(
        String document,
        Map<String, String> prefixes, 
        List<XPathExpression> xpaths,
        boolean pass) throws Exception {
    
    final Document doc = this.readDocument(document);
    final SoapMessage msg = this.getSoapMessageForDom(doc);
    final CryptoCoverageChecker checker = new CryptoCoverageChecker(prefixes, xpaths);
    final PhaseInterceptor<SoapMessage> wss4jInInterceptor = this.getWss4jInInterceptor();
    
    wss4jInInterceptor.handleMessage(msg);
    
    try {
        checker.handleMessage(msg);
        if (!pass) {
            fail("Passed interceptor erroneously.");
        }
    } catch (Fault e) {
        if (pass) {
            fail("Failed interceptor erroneously.");
        }
        
        assertTrue(e.getMessage().contains("element found matching XPath"));
    }
}
 
Example #7
Source File: CryptoCoverageCheckerTest.java    From steady with Apache License 2.0 6 votes vote down vote up
private void runInterceptorAndValidate(
        String document,
        Map<String, String> prefixes, 
        List<XPathExpression> xpaths,
        boolean pass) throws Exception {
    
    final Document doc = this.readDocument(document);
    final SoapMessage msg = this.getSoapMessageForDom(doc);
    final CryptoCoverageChecker checker = new CryptoCoverageChecker(prefixes, xpaths);
    final PhaseInterceptor<SoapMessage> wss4jInInterceptor = this.getWss4jInInterceptor();
    
    wss4jInInterceptor.handleMessage(msg);
    
    try {
        checker.handleMessage(msg);
        if (!pass) {
            fail("Passed interceptor erroneously.");
        }
    } catch (Fault e) {
        if (pass) {
            fail("Failed interceptor erroneously.");
        }
        
        assertTrue(e.getMessage().contains("element found matching XPath"));
    }
}
 
Example #8
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncrypt() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//s:Body/xenc:EncryptedData", doc);
}
 
Example #9
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignature() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myAlias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/ds:Signature", doc);
}
 
Example #10
Source File: CryptoCoverageCheckerTest.java    From steady with Apache License 2.0 6 votes vote down vote up
private void runInterceptorAndValidate(
        String document,
        Map<String, String> prefixes, 
        List<XPathExpression> xpaths,
        boolean pass) throws Exception {
    
    final Document doc = this.readDocument(document);
    final SoapMessage msg = this.getSoapMessageForDom(doc);
    final CryptoCoverageChecker checker = new CryptoCoverageChecker(prefixes, xpaths);
    final PhaseInterceptor<SoapMessage> wss4jInInterceptor = this.getWss4jInInterceptor();
    
    wss4jInInterceptor.handleMessage(msg);
    
    try {
        checker.handleMessage(msg);
        if (!pass) {
            fail("Passed interceptor erroneously.");
        }
    } catch (Fault e) {
        if (pass) {
            fail("Failed interceptor erroneously.");
        }
        
        assertTrue(e.getMessage().contains("element found matching XPath"));
    }
}
 
Example #11
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncrypt() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//s:Body/xenc:EncryptedData", doc);
}
 
Example #12
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignature() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myAlias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/ds:Signature", doc);
}
 
Example #13
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimestamp() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    ohandler.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    ohandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/wsu:Timestamp", doc);
}
 
Example #14
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimestamp() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    ohandler.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    ohandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/wsu:Timestamp", doc);
}
 
Example #15
Source File: CryptoCoverageCheckerTest.java    From steady with Apache License 2.0 6 votes vote down vote up
private void runInterceptorAndValidate(
        String document,
        Map<String, String> prefixes, 
        List<XPathExpression> xpaths,
        boolean pass) throws Exception {
    
    final Document doc = this.readDocument(document);
    final SoapMessage msg = this.getSoapMessageForDom(doc);
    final CryptoCoverageChecker checker = new CryptoCoverageChecker(prefixes, xpaths);
    final PhaseInterceptor<SoapMessage> wss4jInInterceptor = this.getWss4jInInterceptor();
    
    wss4jInInterceptor.handleMessage(msg);
    
    try {
        checker.handleMessage(msg);
        if (!pass) {
            fail("Passed interceptor erroneously.");
        }
    } catch (Fault e) {
        if (pass) {
            fail("Failed interceptor erroneously.");
        }
        
        assertTrue(e.getMessage().contains("element found matching XPath"));
    }
}
 
Example #16
Source File: CryptoCoverageCheckerTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private PhaseInterceptor<SoapMessage> getWss4jInInterceptor() {
    final WSS4JInInterceptor inHandler = new WSS4JInInterceptor(true);
    final String action = WSHandlerConstants.SIGNATURE + " " + WSHandlerConstants.ENCRYPT;
    
    inHandler.setProperty(WSHandlerConstants.ACTION, action);
    inHandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, 
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.DEC_PROP_FILE,
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, 
            TestPwdCallback.class.getName());
    inHandler.setProperty(WSHandlerConstants.IS_BSP_COMPLIANT, "false");
    
    return inHandler;
}
 
Example #17
Source File: WSS4JInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<PhaseInterceptor<? extends org.apache.cxf.message.Message>>
getAdditionalInterceptors() {
    List<PhaseInterceptor<? extends org.apache.cxf.message.Message>> extras 
        = new ArrayList<PhaseInterceptor<? extends org.apache.cxf.message.Message>>(1);
    extras.add(SAAJInInterceptor.SAAJPreInInterceptor.INSTANCE);
    return extras;
}
 
Example #18
Source File: DefaultCryptoCoverageCheckerTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private PhaseInterceptor<SoapMessage> getWss4jInInterceptor() {
    final WSS4JInInterceptor inHandler = new WSS4JInInterceptor(true);
    final String action = WSHandlerConstants.SIGNATURE + " " + WSHandlerConstants.ENCRYPT;
    
    inHandler.setProperty(WSHandlerConstants.ACTION, action);
    inHandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, 
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.DEC_PROP_FILE,
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, 
            TestPwdCallback.class.getName());
    inHandler.setProperty(WSHandlerConstants.IS_BSP_COMPLIANT, "false");
    
    return inHandler;
}
 
Example #19
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddCustomAction() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    CountingUsernameTokenAction action = new CountingUsernameTokenAction();
    Map<Object, Object> customActions = new HashMap<Object, Object>(1);
    customActions.put(12345, action);
            
    msg.put(WSHandlerConstants.ACTION, "12345");
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "username");
    msg.put("password", "myAliasPassword");
    msg.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    msg.put(WSS4JOutInterceptor.WSS4J_ACTION_MAP, customActions);
    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/wsse:UsernameToken", doc);
    assertValid("//wsse:Security/wsse:UsernameToken/wsse:Username[text()='username']", doc);
    // Test to see that the plaintext password is used in the header
    assertValid("//wsse:Security/wsse:UsernameToken/wsse:Password[text()='myAliasPassword']", doc);
    assertEquals(1, action.getExecutions());
}
 
Example #20
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddCustomAction() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    CountingUsernameTokenAction action = new CountingUsernameTokenAction();
    Map<Object, Object> customActions = new HashMap<Object, Object>(1);
    customActions.put(12345, action);
            
    msg.put(WSHandlerConstants.ACTION, "12345");
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "username");
    msg.put("password", "myAliasPassword");
    msg.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    msg.put(WSS4JOutInterceptor.WSS4J_ACTION_MAP, customActions);
    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/wsse:UsernameToken", doc);
    assertValid("//wsse:Security/wsse:UsernameToken/wsse:Username[text()='username']", doc);
    // Test to see that the plaintext password is used in the header
    assertValid("//wsse:Security/wsse:UsernameToken/wsse:Password[text()='myAliasPassword']", doc);
    assertEquals(1, action.getExecutions());
}
 
Example #21
Source File: WSS4JInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<PhaseInterceptor<? extends org.apache.cxf.message.Message>>
getAdditionalInterceptors() {
    List<PhaseInterceptor<? extends org.apache.cxf.message.Message>> extras 
        = new ArrayList<PhaseInterceptor<? extends org.apache.cxf.message.Message>>(1);
    extras.add(SAAJInInterceptor.SAAJPreInInterceptor.INSTANCE);
    return extras;
}
 
Example #22
Source File: WSS4JInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<PhaseInterceptor<? extends org.apache.cxf.message.Message>>
getAdditionalInterceptors() {
    List<PhaseInterceptor<? extends org.apache.cxf.message.Message>> extras 
        = new ArrayList<PhaseInterceptor<? extends org.apache.cxf.message.Message>>(1);
    extras.add(SAAJInInterceptor.SAAJPreInInterceptor.INSTANCE);
    return extras;
}
 
Example #23
Source File: DefaultCryptoCoverageCheckerTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private PhaseInterceptor<SoapMessage> getWss4jInInterceptor() {
    final WSS4JInInterceptor inHandler = new WSS4JInInterceptor(true);
    final String action = WSHandlerConstants.SIGNATURE + " " + WSHandlerConstants.ENCRYPT;
    
    inHandler.setProperty(WSHandlerConstants.ACTION, action);
    inHandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, 
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.DEC_PROP_FILE,
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, 
            TestPwdCallback.class.getName());
    inHandler.setProperty(WSHandlerConstants.IS_BSP_COMPLIANT, "false");
    
    return inHandler;
}
 
Example #24
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsernameTokenText() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "username");
    msg.put("password", "myAliasPassword");
    msg.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/wsse:UsernameToken", doc);
    assertValid("//wsse:Security/wsse:UsernameToken/wsse:Username[text()='username']", doc);
    // Test to see that the plaintext password is used in the header
    assertValid("//wsse:Security/wsse:UsernameToken/wsse:Password[text()='myAliasPassword']", doc);
}
 
Example #25
Source File: DefaultCryptoCoverageCheckerTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private void runInterceptorAndValidate(
        String document,
        Map<String, String> prefixes, 
        List<XPathExpression> xpaths,
        boolean pass) throws Exception {
    
    final Document doc = this.readDocument(document);
    final SoapMessage msg = this.getSoapMessageForDom(doc);
    final CryptoCoverageChecker checker = new DefaultCryptoCoverageChecker();
    checker.addPrefixes(prefixes);
    checker.addXPaths(xpaths);
    final PhaseInterceptor<SoapMessage> wss4jInInterceptor = this.getWss4jInInterceptor();
    
    wss4jInInterceptor.handleMessage(msg);
    
    try {
        checker.handleMessage(msg);
        if (!pass) {
            fail("Passed interceptor erroneously.");
        }
    } catch (Fault e) {
        if (pass) {
            fail("Failed interceptor erroneously.");
        }
        
        assertTrue(e.getMessage().contains("element found matching XPath"));
    }
}
 
Example #26
Source File: DefaultCryptoCoverageCheckerTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private void runInterceptorAndValidate(
        String document,
        Map<String, String> prefixes, 
        List<XPathExpression> xpaths,
        boolean pass) throws Exception {
    
    final Document doc = this.readDocument(document);
    final SoapMessage msg = this.getSoapMessageForDom(doc);
    final CryptoCoverageChecker checker = new DefaultCryptoCoverageChecker();
    checker.addPrefixes(prefixes);
    checker.addXPaths(xpaths);
    final PhaseInterceptor<SoapMessage> wss4jInInterceptor = this.getWss4jInInterceptor();
    
    wss4jInInterceptor.handleMessage(msg);
    
    try {
        checker.handleMessage(msg);
        if (!pass) {
            fail("Passed interceptor erroneously.");
        }
    } catch (Fault e) {
        if (pass) {
            fail("Failed interceptor erroneously.");
        }
        
        assertTrue(e.getMessage().contains("element found matching XPath"));
    }
}
 
Example #27
Source File: DefaultCryptoCoverageCheckerTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private PhaseInterceptor<SoapMessage> getWss4jInInterceptor() {
    final WSS4JInInterceptor inHandler = new WSS4JInInterceptor(true);
    final String action = WSHandlerConstants.SIGNATURE + " " + WSHandlerConstants.ENCRYPT;
    
    inHandler.setProperty(WSHandlerConstants.ACTION, action);
    inHandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, 
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.DEC_PROP_FILE,
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, 
            TestPwdCallback.class.getName());
    inHandler.setProperty(WSHandlerConstants.IS_BSP_COMPLIANT, "false");
    
    return inHandler;
}
 
Example #28
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsernameTokenText() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "username");
    msg.put("password", "myAliasPassword");
    msg.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/wsse:UsernameToken", doc);
    assertValid("//wsse:Security/wsse:UsernameToken/wsse:Username[text()='username']", doc);
    // Test to see that the plaintext password is used in the header
    assertValid("//wsse:Security/wsse:UsernameToken/wsse:Password[text()='myAliasPassword']", doc);
}
 
Example #29
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsernameTokenDigest() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "username");
    msg.put("password", "myAliasPassword");
    msg.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/wsse:UsernameToken", doc);
    assertValid("//wsse:Security/wsse:UsernameToken/wsse:Username[text()='username']", doc);
    // Test to see that the password digest is used in the header
    assertInvalid("//wsse:Security/wsse:UsernameToken/wsse:Password[text()='myAliasPassword']", doc);
}
 
Example #30
Source File: CryptoCoverageCheckerTest.java    From steady with Apache License 2.0 5 votes vote down vote up
private PhaseInterceptor<SoapMessage> getWss4jInInterceptor() {
    final WSS4JInInterceptor inHandler = new WSS4JInInterceptor(true);
    final String action = WSHandlerConstants.SIGNATURE + " " + WSHandlerConstants.ENCRYPT;
    
    inHandler.setProperty(WSHandlerConstants.ACTION, action);
    inHandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, 
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.DEC_PROP_FILE,
            "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, 
            TestPwdCallback.class.getName());
    inHandler.setProperty(WSHandlerConstants.IS_BSP_COMPLIANT, "false");
    
    return inHandler;
}