Java Code Examples for org.apache.cxf.service.Service#put()

The following examples show how to use org.apache.cxf.service.Service#put() . 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: StaxRoundTripTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsernameTokenTextUnknownUser() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setCallbackHandler(new TestPwdCallback());
    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.USERNAMETOKEN);
    properties.setActions(actions);
    properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
    properties.setTokenUser("Alice");
    properties.setCallbackHandler(new UnknownUserPasswordCallbackHandler());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on an unknown user");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 2
Source File: StaxRoundTripTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsernameTokenTextUnknownPassword() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setCallbackHandler(new TestPwdCallback());
    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.USERNAMETOKEN);
    properties.setActions(actions);
    properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
    properties.setTokenUser("username");
    properties.setCallbackHandler(new UnknownUserPasswordCallbackHandler());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on an unknown password");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 3
Source File: StaxToDOMSamlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaml2Config() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    validator.setRequireSAML1Assertion(false);
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
    inProperties.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);
    service.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    outConfig.put(ConfigurationConstants.SAML_CALLBACK_REF, new SAML2CallbackHandler());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);

    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 4
Source File: StaxRoundTripTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsernameTokenDigestUnknownUser() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setCallbackHandler(new TestPwdCallback());
    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.USERNAMETOKEN);
    properties.setActions(actions);
    properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
    properties.setTokenUser("Alice");
    properties.setCallbackHandler(new UnknownUserPasswordCallbackHandler());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on an unknown user");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 5
Source File: StaxRoundTripTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsernameTokenDigestUnknownPassword() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setCallbackHandler(new TestPwdCallback());
    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.USERNAMETOKEN);
    properties.setActions(actions);
    properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
    properties.setTokenUser("username");
    properties.setCallbackHandler(new UnknownUserPasswordCallbackHandler());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on an unknown password");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 6
Source File: StaxToDOMSamlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaml1() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
    inProperties.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);
    service.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.SAML_TOKEN_UNSIGNED);
    properties.setActions(actions);
    properties.setSamlCallbackHandler(new SAML1CallbackHandler());

    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 7
Source File: StaxToDOMSamlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaml1Config() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
    inProperties.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);
    service.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    outConfig.put(ConfigurationConstants.SAML_CALLBACK_REF, new SAML1CallbackHandler());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);

    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 8
Source File: StaxToDOMSamlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaml2() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    validator.setRequireSAML1Assertion(false);
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
    inProperties.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);
    service.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.SAML_TOKEN_UNSIGNED);
    properties.setActions(actions);
    properties.setSamlCallbackHandler(new SAML2CallbackHandler());

    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 9
Source File: StaxToDOMRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testTimestamp() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP);
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.TIMESTAMP);
    properties.setActions(actions);

    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for no Timestamp
    service.getInInterceptors().remove(inInterceptor);
    inProperties.put(ConfigurationConstants.ACTION, "");
    inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on no Timestamp");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "An error was discovered";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 10
Source File: JaxWsEndpointImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public JaxWsEndpointImpl(Bus bus, Service s, EndpointInfo ei, JaxWsImplementorInfo implementorInfo,
                         List<WebServiceFeature> wf, List<? extends Feature> af, boolean isFromWsdl)
    throws EndpointException {
    super(bus, s, ei);
    this.implInfo = implementorInfo;
    this.wsFeatures = new ArrayList<>();
    if (af != null) {
        features = CastUtils.cast(af);
    } else {
        features = new ArrayList<>();
    }
    if (wf != null) {
        for (WebServiceFeature f : wf) {
            if (f instanceof Feature) {
                features.add((Feature)f);
            } else {
                wsFeatures.add(f);
            }
        }
    }
    createJaxwsBinding();

    List<Interceptor<? extends Message>> in = super.getInInterceptors();
    List<Interceptor<? extends Message>> out = super.getOutInterceptors();

    boolean isProvider = implInfo != null && implInfo.isWebServiceProvider();
    Class<?> clazz = implInfo != null && isProvider ? implInfo.getProviderParameterType() : null;
    Mode mode = implInfo != null && isProvider ? implInfo.getServiceMode() : null;

    if (isProvider) {
        s.put(AbstractInDatabindingInterceptor.NO_VALIDATE_PARTS, Boolean.TRUE);
    }

    // Inbound chain
    logicalInInterceptor = new LogicalHandlerInInterceptor(jaxwsBinding);
    if (!isProvider) {
        in.add(new WrapperClassInInterceptor());
        in.add(new HolderInInterceptor());
    }
    if (getBinding() instanceof SoapBinding) {
        soapHandlerInterceptor = new SOAPHandlerInterceptor(jaxwsBinding);
        in.add(new SwAInInterceptor());
        getOutInterceptors().add(new SwAOutInterceptor());
        if (isProvider && mode == Mode.MESSAGE) {
            in.add(new SAAJInInterceptor());
        }
    }
    if (isProvider && mode == Mode.MESSAGE) {
        in.add(new MessageModeInInterceptor(clazz, getBinding().getBindingInfo().getName()));
    }

    // Outbound chain
    logicalOutInterceptor = new LogicalHandlerOutInterceptor(jaxwsBinding);
    if (!isProvider) {
        out.add(new WrapperClassOutInterceptor());
        out.add(new HolderOutInterceptor());
    }
    if (getBinding() instanceof SoapBinding && mode == Mode.MESSAGE) {
        SAAJOutInterceptor saajOut = new SAAJOutInterceptor();
        out.add(saajOut);
        out.add(new MessageModeOutInterceptor(saajOut,
                                              getBinding().getBindingInfo().getName()));
    } else if (isProvider) {
        out.add(new MessageModeOutInterceptor(clazz, getBinding().getBindingInfo().getName()));
    }

    logicalFaultOutInterceptor = new LogicalHandlerFaultOutInterceptor(jaxwsBinding);
    logicalFaultInInterceptor = new LogicalHandlerFaultInInterceptor(jaxwsBinding);

    if (getBinding() instanceof SoapBinding) {
        soapFaultOutInterceptor = new SOAPHandlerFaultOutInterceptor(jaxwsBinding);
        soapFaultInInterceptor = new SOAPHandlerFaultInInterceptor(jaxwsBinding);
    }

    if (ei != null) {
        if (!isFromWsdl) {
            buildWsdlExtensibilities(ei.getBinding());
        }
        extractWsdlExtensibilities(ei);
    }
    resolveFeatures();
}
 
Example 11
Source File: StaxToDOMRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsernameTokenDigestConfig() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_DIGEST);
    inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    outConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordDigest");
    outConfig.put(ConfigurationConstants.USER, "username");
    outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);

    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for wrong password type
    service.getInInterceptors().remove(inInterceptor);
    inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
    inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on the wrong password type");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 12
Source File: StaxToDOMRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsernameTokenDigest() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_DIGEST);
    inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.USERNAMETOKEN);
    properties.setActions(actions);
    properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
    properties.setTokenUser("username");
    properties.setCallbackHandler(new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for wrong password type
    service.getInInterceptors().remove(inInterceptor);
    inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
    inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on the wrong password type");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 13
Source File: StaxToDOMRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsernameTokenTextConfig() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
    inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    outConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordText");
    outConfig.put(ConfigurationConstants.USER, "username");
    outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);

    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for wrong password type
    service.getInInterceptors().remove(inInterceptor);
    inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_DIGEST);
    inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on the wrong password type");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 14
Source File: StaxToDOMRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsernameTokenText() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
    inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.USERNAMETOKEN);
    properties.setActions(actions);
    properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
    properties.setTokenUser("username");
    properties.setCallbackHandler(new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for wrong password type
    service.getInInterceptors().remove(inInterceptor);
    inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_DIGEST);
    inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on the wrong password type");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 15
Source File: StaxRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsernameTokenDigestConfig() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inConfig = new HashMap<>();
    inConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    inConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordDigest");
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig);
    WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor();
    principalInterceptor.setPrincipalName("username");
    service.getInInterceptors().add(inhandler);
    service.getInInterceptors().add(principalInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    outConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordDigest");
    outConfig.put(ConfigurationConstants.USER, "username");
    outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);

    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for wrong password type
    service.getInInterceptors().remove(inhandler);
    inConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordText");
    inhandler = new WSS4JStaxInInterceptor(inConfig);
    service.getInInterceptors().add(inhandler);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on the wrong password type");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 16
Source File: StaxRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsernameTokenDigest() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setCallbackHandler(new TestPwdCallback());
    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor();
    principalInterceptor.setPrincipalName("username");
    service.getInInterceptors().add(inhandler);
    service.getInInterceptors().add(principalInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.USERNAMETOKEN);
    properties.setActions(actions);
    properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
    properties.setTokenUser("username");
    properties.setCallbackHandler(new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for wrong password type
    service.getInInterceptors().remove(inhandler);
    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
    inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on the wrong password type");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 17
Source File: StaxRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsernameTokenTextConfig() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inConfig = new HashMap<>();
    inConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    inConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordText");
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig);
    WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor();
    principalInterceptor.setPrincipalName("username");
    service.getInInterceptors().add(inhandler);
    service.getInInterceptors().add(principalInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    outConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordText");
    outConfig.put(ConfigurationConstants.USER, "username");
    outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);

    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for wrong password type
    service.getInInterceptors().remove(inhandler);
    inConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordDigest");
    inhandler = new WSS4JStaxInInterceptor(inConfig);
    service.getInInterceptors().add(inhandler);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on the wrong password type");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 18
Source File: StaxToDOMRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testTimestampConfig() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP);
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP);
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);

    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for no Timestamp
    service.getInInterceptors().remove(inInterceptor);
    inProperties.put(ConfigurationConstants.ACTION, "");
    inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on no Timestamp");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "An error was discovered";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 19
Source File: DOMToStaxRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsernameTokenDigest() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
    inProperties.setCallbackHandler(new TestPwdCallback());
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> properties = new HashMap<>();
    properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    properties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_DIGEST);
    properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    properties.put(ConfigurationConstants.USER, "username");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for wrong password type
    service.getInInterceptors().remove(inhandler);

    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
    inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);
    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on the wrong password type");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}
 
Example 20
Source File: DOMToStaxRoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsernameTokenText() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
    inProperties.setCallbackHandler(new TestPwdCallback());
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> properties = new HashMap<>();
    properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
    properties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
    properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    properties.put(ConfigurationConstants.USER, "username");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));

    // Negative test for wrong password type
    service.getInInterceptors().remove(inhandler);

    inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
    inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);

    try {
        echo.echo("test");
        fail("Failure expected on the wrong password type");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
        String error = "The security token could not be authenticated or authorized";
        assertTrue(ex.getMessage().contains(error));
    }
}