Skip to content

Instantly share code, notes, and snippets.

@hasithaa
Created September 21, 2014 04:20
Show Gist options
  • Save hasithaa/ad4daa18fe0993bbfc0c to your computer and use it in GitHub Desktop.
Save hasithaa/ad4daa18fe0993bbfc0c to your computer and use it in GitHub Desktop.
package org.example.rampart;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;
import java.io.IOException;
public class PWCBHandler implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[i];
int usage = pwcb.getUsage();
String id = pwcb.getIdentifier();
if (usage == WSPasswordCallback.USERNAME_TOKEN) {
System.out.println("Resolving password for user " + id);
// Getting password
if ("tom".equals(id)) {
pwcb.setPassword("tompass");
}else if ("bob".equals(id)){
pwcb.setPassword("bobpass");
} else {
pwcb.setPassword("");
}
} else if (usage == WSPasswordCallback.SIGNATURE
|| usage == WSPasswordCallback.DECRYPT) {
// Logic to get the private key password for signature or
// decryption
// TODO : Implement me
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment