Java Code Examples for org.apache.wss4j.common.ext.WSPasswordCallback#getUsage()

The following examples show how to use org.apache.wss4j.common.ext.WSPasswordCallback#getUsage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: STSCallbackHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof WSPasswordCallback) {
            WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
            if (pc.getUsage() == WSPasswordCallback.DECRYPT
                || pc.getUsage() == WSPasswordCallback.SIGNATURE) {
                if ("mystskey".equals(pc.getIdentifier())) {
                    pc.setPassword("stskpass");
                }
            } else if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
                if ("alice".equals(pc.getIdentifier())) {
                    pc.setPassword("clarinet");
                }
            }
        }
    }
}
 
Example 2
Source File: ClientCallbackHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof WSPasswordCallback) {
            WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
            if (pc.getUsage() == WSPasswordCallback.DECRYPT
                || pc.getUsage() == WSPasswordCallback.SIGNATURE) {
                if ("myclientkey".equals(pc.getIdentifier())) {
                    pc.setPassword("ckpass");
                }
            } else if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
                if ("alice".equals(pc.getIdentifier())) {
                    pc.setPassword("clarinet");
                    break;
                } else if ("bob".equals(pc.getIdentifier())) {
                    pc.setPassword("trombone");
                    break;
                }
            }
        }
    }
}
 
Example 3
Source File: KeystorePasswordCallback.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * 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];
        if (pc.getUsage() == WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD) {
            pc.setPassword("this-is-a-secret");
        } else {
            String pass = passwords.get(pc.getIdentifier());
            if (pass != null) {
                pc.setPassword(pass);
                return;
            }
            pc.setPassword("password");
        }
    }
}
 
Example 4
Source File: KeystorePasswordCallback.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * 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];
        if (pc.getUsage() == WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD) {
            pc.setPassword("this-is-a-secret");
        } else {
            String pass = passwords.get(pc.getIdentifier());
            if (pass != null) {
                pc.setPassword(pass);
                return;
            }
            pc.setPassword("password");
        }
    }
}
 
Example 5
Source File: KeystorePasswordCallback.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * 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];
        if (pc.getUsage() == WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD) {
            pc.setPassword("this-is-a-secret");
        } else {
            String pass = passwords.get(pc.getIdentifier());
            if (pass != null) {
                pc.setPassword(pass);
                return;
            }
            pc.setPassword("password");
        }
    }
}
 
Example 6
Source File: KeystorePasswordCallback.java    From cxf-fediz with Apache License 2.0 6 votes vote down vote up
/**
 * 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];
        if (pc.getUsage() == WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD) {
            pc.setPassword("this-is-a-secret");
        } else {
            String pass = passwords.get(pc.getIdentifier());
            if (pass != null) {
                pc.setPassword(pass);
                return;
            } else {
                pc.setPassword("password");
            }
        }
    }
}
 
Example 7
Source File: CustomPasswordHandler.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

    if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
        // TODO get the password from the users.properties if possible
        pc.setPassword("waterfall");

    } else if (pc.getUsage() == WSPasswordCallback.DECRYPT) {
        pc.setPassword("serverPassword");

    } else if (pc.getUsage() == WSPasswordCallback.SIGNATURE) {
        pc.setPassword("serverPassword");

    }
}
 
Example 8
Source File: ClientPasswordCallback.java    From eet-client with MIT License 5 votes vote down vote up
@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {

    for (final Callback thisCallback : callbacks) {
        final WSPasswordCallback pwcb = (WSPasswordCallback) thisCallback;
        final String user = pwcb.getIdentifier();
        final int usage = pwcb.getUsage();
        if (usage == WSPasswordCallback.SIGNATURE && alias.equals(user)) {
            pwcb.setPassword(password);
        }
    }

}
 
Example 9
Source File: SecretKeyPasswordCallback.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];
        if (pc.getUsage() == WSPasswordCallback.SECRET_KEY) {
            pc.setKey(KEY);
        }
    }
}
 
Example 10
Source File: KerberosClientPasswordCallback.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback)callbacks[i];
            nameCallback.setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback)callbacks[i];
            passwordCallback.setPassword(password.toCharArray());
        } else if (callbacks[i] instanceof WSPasswordCallback) {
            WSPasswordCallback wsPasswordCallback = (WSPasswordCallback)callbacks[i];
            // Get a custom (Kerberos) token directly using the WSS4J APIs
            if (wsPasswordCallback.getUsage() == WSPasswordCallback.CUSTOM_TOKEN) {
                KerberosSecurity kerberosSecurity = new KerberosSecurity(DOMUtils.getEmptyDocument());

                try {
                    kerberosSecurity.retrieveServiceTicket(username, this, servicePrincipal,
                                              false, false, null);
                    kerberosSecurity.addWSUNamespace();
                    WSSConfig wssConfig = WSSConfig.getNewInstance();
                    kerberosSecurity.setID(wssConfig.getIdAllocator().createSecureId("BST-", kerberosSecurity));

                    wsPasswordCallback.setCustomToken(kerberosSecurity.getElement());
                } catch (WSSecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}