Search in sources :

Example 66 with WSPasswordCallback

use of org.apache.wss4j.common.ext.WSPasswordCallback in project tesb-rt-se by Talend.

the class SAMClientSecurityProvider method init.

@PostConstruct
public void init() {
    final EsbSecurityConstants esbSecurity = EsbSecurityConstants.fromString(authenticationType);
    if (EsbSecurityConstants.NO == esbSecurity) {
        return;
    }
    Bus bus = client.getBus();
    List<Policy> policies = new ArrayList<Policy>();
    WSPolicyFeature policyFeature = new WSPolicyFeature();
    policyFeature.setPolicies(policies);
    Map<String, Object> properties = client.getRequestContext();
    if (null == properties) {
        properties = new HashMap<String, Object>();
    }
    if (EsbSecurityConstants.BASIC == esbSecurity) {
        AuthorizationPolicy authzPolicy = new AuthorizationPolicy();
        authzPolicy.setUserName(username);
        authzPolicy.setPassword(password);
        authzPolicy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_BASIC);
        HTTPConduit conduit = (HTTPConduit) client.getConduit();
        conduit.setAuthorization(authzPolicy);
    } else if (EsbSecurityConstants.USERNAMETOKEN == esbSecurity) {
        policies.add(loadPolicy(policyUsernameToken, bus));
        java.util.Map<String, Object> wssProps = new java.util.HashMap<String, Object>();
        wssProps.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
        wssProps.put(ConfigurationConstants.USER, username);
        wssProps.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
        wssProps.put(ConfigurationConstants.PW_CALLBACK_REF, new CallbackHandler() {

            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                ((WSPasswordCallback) callbacks[0]).setPassword(password);
            }
        });
        client.getEndpoint().getOutInterceptors().add(new WSS4JOutInterceptor(wssProps));
        client.getRequestContext().put("security.username", username);
        client.getRequestContext().put("security.password", password);
    } else if (EsbSecurityConstants.SAML == esbSecurity) {
        policies.add(loadPolicy(policySaml, bus));
        properties.put(SecurityConstants.SIGNATURE_PROPERTIES, processFileURI(getSignatureProperties()));
        properties.put(SecurityConstants.SIGNATURE_USERNAME, getSignatureUsername());
        properties.put(ENDPOINT_SIGNATURE_PASSWORD, getSignaturePassword());
        properties.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(getSignatureUsername(), getSignaturePassword()));
        // STS client
        STSClient stsClient = new STSClient(bus);
        stsClient.setWsdlLocation(stsWsdlLocation);
        stsClient.setServiceQName(new QName(stsNamespace, stsServiceName));
        stsClient.setEndpointQName(new QName(stsNamespace, stsEndpointName));
        Map<String, Object> stsProperties = new HashMap<String, Object>();
        stsProperties.put(SecurityConstants.USERNAME, username);
        stsProperties.put(SecurityConstants.PASSWORD, password);
        stsProperties.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(username, password));
        stsProperties.put(SecurityConstants.STS_TOKEN_PROPERTIES, processFileURI(getSignatureProperties()));
        stsProperties.put(SecurityConstants.STS_TOKEN_USERNAME, signatureUsername);
        stsProperties.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, stsTokenUsecert);
        stsProperties.put(SecurityConstants.ENCRYPT_PROPERTIES, processFileURI(getSignatureProperties()));
        stsProperties.put(SecurityConstants.ENCRYPT_USERNAME, encryptionUsername);
        stsProperties.put(SecurityConstants.IS_BSP_COMPLIANT, isBspCompliant);
        stsClient.setProperties(stsProperties);
        properties.put(SecurityConstants.STS_CLIENT, stsClient);
    }
    client.getEndpoint().getActiveFeatures().add(policyFeature);
    policyFeature.initialize(client, bus);
}
Also used : Policy(org.apache.neethi.Policy) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Bus(org.apache.cxf.Bus) CallbackHandler(javax.security.auth.callback.CallbackHandler) WSPolicyFeature(org.apache.cxf.ws.policy.WSPolicyFeature) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) STSClient(org.apache.cxf.ws.security.trust.STSClient) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) HashMap(java.util.HashMap) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

Example 67 with WSPasswordCallback

use of org.apache.wss4j.common.ext.WSPasswordCallback in project jbossws-cxf by jbossws.

the class PasswordCallbackHandler method handle.

/**
 * It attempts to get the password from the private
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        final Callback c = callbacks[i];
        if (c != null && c instanceof WSPasswordCallback) {
            final WSPasswordCallback pc = (WSPasswordCallback) c;
            String pass = passwords.get(pc.getIdentifier());
            if (pass != null) {
                pc.setPassword(pass);
                return;
            }
        }
    }
}
Also used : WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Callback(javax.security.auth.callback.Callback) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback)

Example 68 with WSPasswordCallback

use of org.apache.wss4j.common.ext.WSPasswordCallback in project jbossws-cxf by jbossws.

the class UsernamePasswordCallback method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
    final String id = pc.getIdentifier();
    if ("kermit".equals(id))
        pc.setPassword("thefrog");
    else if ("alice".equals(id) || "bob".equals(id))
        pc.setPassword("password");
    else
        pc.setPassword("wrong password");
}
Also used : WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback)

Example 69 with WSPasswordCallback

use of org.apache.wss4j.common.ext.WSPasswordCallback in project midpoint by Evolveum.

the class PasswordCallback method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    LOGGER.trace("Invoked PasswordCallback with {} callbacks: {}", callbacks.length, callbacks);
    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
    String username = pc.getIdentifier();
    String wssPasswordType = pc.getType();
    LOGGER.trace("Username: '{}', Password type: {}", username, wssPasswordType);
    try {
        ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
        pc.setPassword(passwordAuthenticationEvaluatorImpl.getAndCheckUserPassword(connEnv, username));
    } catch (Exception e) {
        LOGGER.trace("Exception in password callback: {}: {}", e.getClass().getSimpleName(), e.getMessage(), e);
        throw new PasswordCallbackException("Authentication failed");
    }
}
Also used : WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment)

Aggregations

WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)69 Callback (javax.security.auth.callback.Callback)22 CallbackHandler (javax.security.auth.callback.CallbackHandler)20 IOException (java.io.IOException)17 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)14 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)11 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)8 QName (javax.xml.namespace.QName)7 Endpoint (org.apache.cxf.endpoint.Endpoint)7 Test (org.junit.Test)7 URL (java.net.URL)6 Service (javax.xml.ws.Service)6 SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)6 Client (org.apache.cxf.endpoint.Client)6 Crypto (org.apache.wss4j.common.crypto.Crypto)6 PrivateKey (java.security.PrivateKey)3 X509Certificate (java.security.cert.X509Certificate)3 DestroyFailedException (javax.security.auth.DestroyFailedException)3