Search in sources :

Example 31 with AuthorizationPolicy

use of org.apache.cxf.configuration.security.AuthorizationPolicy in project tbd-studio-se by Talend.

the class HCatalogServiceUtil method addKerberos2Client.

private static void addKerberos2Client(WebClient client, HCatalogConnection connection) throws Exception {
    HadoopClusterConnection hcConnection = HCRepositoryUtil.getRelativeHadoopClusterConnection(connection);
    if (hcConnection != null) {
        if (hcConnection.isEnableMaprT()) {
            setMaprTicketPropertiesConfig(hcConnection);
        }
        if (hcConnection.isEnableKerberos()) {
            KerberosAuthOutInterceptor kbInterceptor = new KerberosAuthOutInterceptor();
            AuthorizationPolicy policy = new AuthorizationPolicy();
            policy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_NEGOTIATE);
            kbInterceptor.setPolicy(policy);
            java.util.Map<String, String> properties = new HashMap<String, String>();
            String krbPrincipal = ConnectionContextHelper.getParamValueOffContext(connection, StringUtils.trimToEmpty(connection.getKrbPrincipal()));
            kbInterceptor.setServicePrincipalName(StringUtils.trimToEmpty(krbPrincipal));
            String krbRealm = ConnectionContextHelper.getParamValueOffContext(connection, StringUtils.trimToEmpty(connection.getKrbRealm()));
            kbInterceptor.setRealm(StringUtils.trimToEmpty(krbRealm));
            // $NON-NLS-1$ //$NON-NLS-2$
            properties.put("useTicketCache", "true");
            // $NON-NLS-1$ //$NON-NLS-2$
            properties.put("refreshKrb5Config", "true");
            // $NON-NLS-1$ //$NON-NLS-2$
            properties.put("renewTGT", "true");
            if (hcConnection.isUseKeytab()) {
                // $NON-NLS-1$//$NON-NLS-2$
                properties.put("useKeyTab", "true");
                // $NON-NLS-1$
                properties.put(// $NON-NLS-1$
                "principal", ConnectionContextHelper.getParamValueOffContext(hcConnection, hcConnection.getKeytabPrincipal()));
                properties.put("keyTab", // $NON-NLS-1$
                ConnectionContextHelper.getParamValueOffContext(hcConnection, hcConnection.getKeytab()));
            }
            kbInterceptor.setLoginConfig(new KerberosPolicyConfig(properties));
            WebClient.getConfig(client).getOutInterceptors().add(kbInterceptor);
        }
        if (hcConnection.isEnableMaprT()) {
            setMaprTicketConfig(hcConnection, getClassLoader(hcConnection, connection), hcConnection.isEnableKerberos());
        }
    }
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) KerberosPolicyConfig(org.talend.repository.hcatalog.util.KerberosPolicyConfig) HashMap(java.util.HashMap) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) KerberosAuthOutInterceptor(org.apache.cxf.jaxrs.security.KerberosAuthOutInterceptor)

Example 32 with AuthorizationPolicy

use of org.apache.cxf.configuration.security.AuthorizationPolicy in project testcases by coheigea.

the class WSS4JBasicAuthFilter method filter.

public void filter(ContainerRequestContext requestContext) throws IOException {
    Message message = JAXRSUtils.getCurrentMessage();
    AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
    if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
        requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic realm=\"STS\"").build());
        return;
    }
    try {
        super.validate(message);
    } catch (Exception ex) {
        throw ExceptionUtils.toInternalServerErrorException(ex, null);
    }
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Message(org.apache.cxf.message.Message) IOException(java.io.IOException)

Example 33 with AuthorizationPolicy

use of org.apache.cxf.configuration.security.AuthorizationPolicy in project testcases by coheigea.

the class WSS4JBasicAuthFilter method filter.

public void filter(ContainerRequestContext requestContext) throws IOException {
    Message message = JAXRSUtils.getCurrentMessage();
    AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
    if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
        requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build());
        return;
    }
    try {
        super.validate(message);
    } catch (Exception ex) {
        throw ExceptionUtils.toInternalServerErrorException(ex, null);
    }
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Message(org.apache.cxf.message.Message) IOException(java.io.IOException)

Example 34 with AuthorizationPolicy

use of org.apache.cxf.configuration.security.AuthorizationPolicy in project testcases by coheigea.

the class WSS4JBasicAuthFilter method filter.

public void filter(ContainerRequestContext requestContext) throws IOException {
    Message message = JAXRSUtils.getCurrentMessage();
    AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
    if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
        requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build());
        return;
    }
    try {
        super.validate(message);
    } catch (Exception ex) {
        throw ExceptionUtils.toInternalServerErrorException(ex, null);
    }
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Message(org.apache.cxf.message.Message) IOException(java.io.IOException)

Example 35 with AuthorizationPolicy

use of org.apache.cxf.configuration.security.AuthorizationPolicy in project testcases by coheigea.

the class SyncopeBasicAuthInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
    if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
        String name = null;
        if (policy != null) {
            name = policy.getUserName();
        }
        String error = "No user credentials are available";
        LOG.warning(error + " " + "for name: " + name);
        throw new SecurityException(error);
    }
    try {
        UsernameToken token = convertPolicyToToken(policy);
        Credential credential = new Credential();
        credential.setUsernametoken(token);
        RequestData data = new RequestData();
        data.setMsgContext(message);
        credential = validator.validate(credential, data);
        // Create a Principal/SecurityContext
        Principal p = null;
        if (credential != null && credential.getPrincipal() != null) {
            p = credential.getPrincipal();
        } else {
            p = new WSUsernameTokenPrincipalImpl(policy.getUserName(), false);
            ((WSUsernameTokenPrincipalImpl) p).setPassword(policy.getPassword());
        }
        message.put(SecurityContext.class, createSecurityContext(p));
    } catch (Exception ex) {
        throw new Fault(ex);
    }
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Credential(org.apache.wss4j.dom.validate.Credential) RequestData(org.apache.wss4j.dom.handler.RequestData) UsernameToken(org.apache.wss4j.dom.message.token.UsernameToken) Fault(org.apache.cxf.interceptor.Fault) Principal(java.security.Principal) WSUsernameTokenPrincipalImpl(org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl)

Aggregations

AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)86 Message (org.apache.cxf.message.Message)25 Test (org.junit.Test)22 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)16 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)11 Client (org.apache.cxf.endpoint.Client)11 List (java.util.List)9 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)9 URL (java.net.URL)7 HashMap (java.util.HashMap)7 ProxyAuthorizationPolicy (org.apache.cxf.configuration.security.ProxyAuthorizationPolicy)7 Map (java.util.Map)6 SecurityContext (org.apache.cxf.security.SecurityContext)6 Bus (org.apache.cxf.Bus)5 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)5 WebClient (org.apache.cxf.jaxrs.client.WebClient)5 MessageImpl (org.apache.cxf.message.MessageImpl)5 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)5 Principal (java.security.Principal)4