Search in sources :

Example 1 with WSPasswordCallback

use of org.apache.wss4j.common.ext.WSPasswordCallback in project tdi-studio-se by Talend.

the class HardcodedPassword method handle.

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback c : callbacks) {
        if (c instanceof WSPasswordCallback) {
            WSPasswordCallback passwordCallback = (WSPasswordCallback) c;
            passwordCallback.setPassword(password);
            continue;
        }
        throw new UnsupportedCallbackException(c);
    }
}
Also used : WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Callback(javax.security.auth.callback.Callback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback)

Example 2 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)

Example 3 with WSPasswordCallback

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

the class ClientPasswordHandler method handle.

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
    // set the password for our message.
    pc.setPassword(password != null ? password : Main.ADM_PASSWORD);
}
Also used : WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback)

Example 4 with WSPasswordCallback

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

the class PasswordCallback 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++) {
        WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
            return;
        }
    }
}
Also used : WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback)

Example 5 with WSPasswordCallback

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

the class UsernameTokenProvider method createToken.

public TokenProviderResponse createToken(TokenProviderParameters tokenParameters) {
    try {
        Document doc = DOMUtils.createDocument();
        Principal principal = tokenParameters.getPrincipal();
        String user = principal.getName();
        // Get the password
        WSPasswordCallback[] cb = { new WSPasswordCallback(user, WSPasswordCallback.USERNAME_TOKEN) };
        STSPropertiesMBean stsProperties = tokenParameters.getStsProperties();
        stsProperties.getCallbackHandler().handle(cb);
        String password = cb[0].getPassword();
        if (password == null || "".equals(password)) {
            throw new STSException("No password available", STSException.REQUEST_FAILED);
        }
        UsernameToken ut = new UsernameToken(true, doc, WSConstants.PASSWORD_TEXT);
        ut.setName(user);
        ut.setPassword(password);
        WSSConfig config = WSSConfig.getNewInstance();
        ut.setID(config.getIdAllocator().createId("UsernameToken-", ut));
        TokenProviderResponse response = new TokenProviderResponse();
        response.setToken(ut.getElement());
        response.setTokenId(ut.getID());
        return response;
    } catch (Exception e) {
        e.printStackTrace();
        throw new STSException("Error creating UsernameToken", e, STSException.REQUEST_FAILED);
    }
}
Also used : STSPropertiesMBean(org.apache.cxf.sts.STSPropertiesMBean) WSSConfig(org.apache.wss4j.dom.engine.WSSConfig) UsernameToken(org.apache.wss4j.dom.message.token.UsernameToken) STSException(org.apache.cxf.ws.security.sts.provider.STSException) TokenProviderResponse(org.apache.cxf.sts.token.provider.TokenProviderResponse) Document(org.w3c.dom.Document) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Principal(java.security.Principal) STSException(org.apache.cxf.ws.security.sts.provider.STSException)

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