Search in sources :

Example 1 with SimpleAuthorizingInterceptor

use of org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor in project cxf by apache.

the class UserNameTokenAuthorizationTest method setUpService.

public void setUpService(String expectedRoles, boolean digest, boolean encryptUsernameTokenOnly) throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());
    wsIn = new SimpleSubjectCreatingInterceptor();
    wsIn.setSupportDigestPasswords(digest);
    wsIn.setProperty(ConfigurationConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getInInterceptors().add(wsIn);
    SimpleAuthorizingInterceptor sai = new SimpleAuthorizingInterceptor();
    sai.setMethodRolesMap(Collections.singletonMap("echo", expectedRoles));
    service.getInInterceptors().add(sai);
    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(ConfigurationConstants.USER, "myalias");
    if (digest) {
        wsOut.setProperty("password", "myAliasPassword");
    } else {
        wsOut.setProperty(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
    }
    if (encryptUsernameTokenOnly) {
        wsOut.setProperty(ConfigurationConstants.ENCRYPTION_USER, "myalias");
        wsOut.setProperty(ConfigurationConstants.ENCRYPTION_PARTS, "{Content}{" + WSS4JConstants.WSSE_NS + "}UsernameToken");
    }
    wsOut.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);
    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    echo = (Echo) proxyFac.create();
    ((BindingProvider) echo).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) SimpleAuthorizingInterceptor(org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor) Server(org.apache.cxf.endpoint.Server) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Service(org.apache.cxf.service.Service) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Aggregations

SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)1 SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)1 Server (org.apache.cxf.endpoint.Server)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)1 SimpleAuthorizingInterceptor (org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor)1 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)1 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)1 Service (org.apache.cxf.service.Service)1