Created
September 21, 2014 04:20
-
-
Save hasithaa/ad4daa18fe0993bbfc0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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