Search in sources :

Example 1 with WSPasswordCallbackHandler

use of org.talend.esb.security.saml.WSPasswordCallbackHandler in project tesb-rt-se by Talend.

the class WSPasswordCallbackHandlerTest method handleNotEncryptedPasswordTest.

@Test
public void handleNotEncryptedPasswordTest() throws Exception {
    String username = "username";
    String password = "password";
    WSPasswordCallbackHandler h = new WSPasswordCallbackHandler(username, password);
    Callback c = new WSPasswordCallback(username, 0);
    List<Callback> cs = new ArrayList<Callback>();
    cs.add(c);
    h.handle(cs.toArray(new Callback[0]));
}
Also used : WSPasswordCallbackHandler(org.talend.esb.security.saml.WSPasswordCallbackHandler) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Callback(javax.security.auth.callback.Callback) ArrayList(java.util.ArrayList) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Test(org.junit.Test)

Example 2 with WSPasswordCallbackHandler

use of org.talend.esb.security.saml.WSPasswordCallbackHandler in project tesb-rt-se by Talend.

the class WSPasswordCallbackHandlerTest method handleEncryptedPasswordTest.

@Ignore
public void handleEncryptedPasswordTest() throws Exception {
    String username = "username";
    String password = PropertyValueEncryptionUtils.encrypt("password", getEncryptor());
    WSPasswordCallbackHandler h = new WSPasswordCallbackHandler(username, password);
    Callback c = new WSPasswordCallback(username, 0);
    List<Callback> cs = new ArrayList<Callback>();
    cs.add(c);
    h.handle(cs.toArray(new Callback[0]));
}
Also used : WSPasswordCallbackHandler(org.talend.esb.security.saml.WSPasswordCallbackHandler) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Callback(javax.security.auth.callback.Callback) ArrayList(java.util.ArrayList) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Ignore(org.junit.Ignore)

Example 3 with WSPasswordCallbackHandler

use of org.talend.esb.security.saml.WSPasswordCallbackHandler in project tesb-rt-se by Talend.

the class WSPasswordCallbackHandlerTest method handleNoUserTest.

@Test
public void handleNoUserTest() throws Exception {
    String username = null;
    String password = "password";
    WSPasswordCallbackHandler h = new WSPasswordCallbackHandler(username, password);
    Callback c = new WSPasswordCallback(username, 0);
    List<Callback> cs = new ArrayList<Callback>();
    cs.add(c);
    h.handle(cs.toArray(new Callback[0]));
}
Also used : WSPasswordCallbackHandler(org.talend.esb.security.saml.WSPasswordCallbackHandler) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Callback(javax.security.auth.callback.Callback) ArrayList(java.util.ArrayList) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Test(org.junit.Test)

Example 4 with WSPasswordCallbackHandler

use of org.talend.esb.security.saml.WSPasswordCallbackHandler in project tesb-rt-se by Talend.

the class SecurityArguments method buildClientConfig.

public Map<String, Object> buildClientConfig(final Bus bus, boolean useServiceRegistry, String encryptionUsername) {
    Map<String, Object> clientConfig = new HashMap<String, Object>();
    if (EsbSecurity.TOKEN == esbSecurity || useServiceRegistry) {
        clientConfig.put(SecurityConstants.USERNAME, username);
        clientConfig.put(SecurityConstants.PASSWORD, password);
    }
    if (EsbSecurity.SAML == esbSecurity || useServiceRegistry) {
        final STSClient stsClient = configureSTSClient(bus);
        clientConfig.put(SecurityConstants.STS_CLIENT, stsClient);
        for (Map.Entry<String, String> entry : clientProperties.entrySet()) {
            if (SecurityConstants.ALL_PROPERTIES.contains(entry.getKey())) {
                clientConfig.put(entry.getKey(), processFileURI(entry.getValue()));
            }
        }
        if (null == alias) {
            String sigUser = clientProperties.get(SecurityConstants.SIGNATURE_USERNAME);
            if (sigUser == null) {
                sigUser = clientProperties.get("ws-" + SecurityConstants.SIGNATURE_USERNAME);
            }
            clientConfig.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(sigUser, clientProperties.get(SAMLRESTUtils.SIGNATURE_PASSWORD)));
        } else {
            clientConfig.put(SecurityConstants.SIGNATURE_USERNAME, alias);
            clientConfig.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(alias, password));
        }
        if (null != cryptoProvider) {
            clientConfig.put(SecurityConstants.ENCRYPT_CRYPTO, cryptoProvider);
            Object encryptUsername = clientConfig.get(SecurityConstants.ENCRYPT_USERNAME);
            if (encryptUsername == null) {
                encryptUsername = clientProperties.get("ws-" + SecurityConstants.ENCRYPT_USERNAME);
            }
            if (encryptUsername == null || encryptUsername.toString().isEmpty()) {
                clientConfig.put(SecurityConstants.ENCRYPT_USERNAME, encryptionUsername);
            }
        }
    }
    return clientConfig;
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) WSPasswordCallbackHandler(org.talend.esb.security.saml.WSPasswordCallbackHandler) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

WSPasswordCallbackHandler (org.talend.esb.security.saml.WSPasswordCallbackHandler)4 ArrayList (java.util.ArrayList)3 Callback (javax.security.auth.callback.Callback)3 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)3 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 STSClient (org.apache.cxf.ws.security.trust.STSClient)1 Ignore (org.junit.Ignore)1