Search in sources :

Example 1 with JaspiClientInInterceptor

use of org.jboss.wsf.stack.cxf.jaspi.client.JaspiClientInInterceptor in project jbossws-cxf by jbossws.

the class DefaultJASPIAuthenticationProvider method enableClientAuthentication.

public boolean enableClientAuthentication(Object target, Map<String, String> properties) {
    if (!(target instanceof Client)) {
        Loggers.ROOT_LOGGER.cannotEnableJASPIAuthentication(target.getClass().getSimpleName());
        return false;
    }
    Client client = (Client) target;
    String securityDomain = properties.get(JaspiClientAuthenticator.JASPI_SECURITY_DOMAIN);
    if (securityDomain == null) {
        return false;
    }
    ApplicationPolicy appPolicy = SecurityConfiguration.getApplicationPolicy(securityDomain);
    if (appPolicy == null) {
        Loggers.ROOT_LOGGER.noApplicationPolicy(securityDomain);
        return false;
    }
    BaseAuthenticationInfo bai = appPolicy.getAuthenticationInfo();
    if (bai == null || bai instanceof AuthenticationInfo) {
        Loggers.ROOT_LOGGER.noJaspiApplicationPolicy(securityDomain);
        return false;
    }
    JASPIAuthenticationInfo jai = (JASPIAuthenticationInfo) bai;
    String contextRoot = client.getEndpoint().getEndpointInfo().getName().toString();
    String appId = "localhost " + contextRoot;
    AuthConfigFactory factory = AuthConfigFactory.getFactory();
    Properties props = new Properties();
    AuthConfigProvider provider = new JBossWSAuthConfigProvider(props, factory);
    provider = factory.getConfigProvider(JBossWSAuthConstants.SOAP_LAYER, appId, null);
    JBossCallbackHandler callbackHandler = new JBossCallbackHandler();
    try {
        ClientAuthConfig clientConfig = provider.getClientAuthConfig("soap", appId, callbackHandler);
        JaspiClientAuthenticator clientAuthenticator = new JaspiClientAuthenticator(clientConfig, securityDomain, jai);
        client.getInInterceptors().add(new JaspiClientInInterceptor(clientAuthenticator));
        client.getOutInterceptors().add(new JaspiClientOutInterceptor(clientAuthenticator));
    } catch (Exception e) {
        Loggers.DEPLOYMENT_LOGGER.cannotCreateServerAuthContext(securityDomain, e);
    }
    return false;
}
Also used : JBossWSAuthConfigProvider(org.jboss.wsf.stack.cxf.jaspi.config.JBossWSAuthConfigProvider) AuthConfigProvider(javax.security.auth.message.config.AuthConfigProvider) JASPIAuthenticationInfo(org.jboss.security.auth.login.JASPIAuthenticationInfo) JBossWSAuthConfigProvider(org.jboss.wsf.stack.cxf.jaspi.config.JBossWSAuthConfigProvider) JaspiClientInInterceptor(org.jboss.wsf.stack.cxf.jaspi.client.JaspiClientInInterceptor) ClientAuthConfig(javax.security.auth.message.config.ClientAuthConfig) Properties(java.util.Properties) BaseAuthenticationInfo(org.jboss.security.auth.login.BaseAuthenticationInfo) JASPIAuthenticationInfo(org.jboss.security.auth.login.JASPIAuthenticationInfo) AuthenticationInfo(org.jboss.security.auth.login.AuthenticationInfo) BaseAuthenticationInfo(org.jboss.security.auth.login.BaseAuthenticationInfo) ApplicationPolicy(org.jboss.security.config.ApplicationPolicy) AuthConfigFactory(javax.security.auth.message.config.AuthConfigFactory) JaspiClientOutInterceptor(org.jboss.wsf.stack.cxf.jaspi.client.JaspiClientOutInterceptor) Client(org.apache.cxf.endpoint.Client) JBossCallbackHandler(org.jboss.security.auth.callback.JBossCallbackHandler) JaspiClientAuthenticator(org.jboss.wsf.stack.cxf.jaspi.client.JaspiClientAuthenticator)

Aggregations

Properties (java.util.Properties)1 AuthConfigFactory (javax.security.auth.message.config.AuthConfigFactory)1 AuthConfigProvider (javax.security.auth.message.config.AuthConfigProvider)1 ClientAuthConfig (javax.security.auth.message.config.ClientAuthConfig)1 Client (org.apache.cxf.endpoint.Client)1 JBossCallbackHandler (org.jboss.security.auth.callback.JBossCallbackHandler)1 AuthenticationInfo (org.jboss.security.auth.login.AuthenticationInfo)1 BaseAuthenticationInfo (org.jboss.security.auth.login.BaseAuthenticationInfo)1 JASPIAuthenticationInfo (org.jboss.security.auth.login.JASPIAuthenticationInfo)1 ApplicationPolicy (org.jboss.security.config.ApplicationPolicy)1 JaspiClientAuthenticator (org.jboss.wsf.stack.cxf.jaspi.client.JaspiClientAuthenticator)1 JaspiClientInInterceptor (org.jboss.wsf.stack.cxf.jaspi.client.JaspiClientInInterceptor)1 JaspiClientOutInterceptor (org.jboss.wsf.stack.cxf.jaspi.client.JaspiClientOutInterceptor)1 JBossWSAuthConfigProvider (org.jboss.wsf.stack.cxf.jaspi.config.JBossWSAuthConfigProvider)1