01: package com.technoetic.xplanner.security.module.jaas;
02:
03: import javax.security.auth.callback.Callback;
04: import javax.security.auth.callback.CallbackHandler;
05: import javax.security.auth.callback.NameCallback;
06: import javax.security.auth.callback.PasswordCallback;
07: import javax.security.auth.callback.UnsupportedCallbackException;
08:
09: public class UserIdAndPasswordCallbackHandler implements
10: CallbackHandler {
11: private String userId;
12: private String password;
13:
14: public UserIdAndPasswordCallbackHandler(String userId,
15: String password) {
16: this .userId = userId;
17: this .password = password;
18: }
19:
20: public void handle(Callback[] callbacks)
21: throws java.io.IOException, UnsupportedCallbackException {
22: for (int i = 0; i < callbacks.length; i++) {
23: if (callbacks[i] instanceof NameCallback) {
24: ((NameCallback) callbacks[i]).setName(userId);
25: }
26: if (callbacks[i] instanceof PasswordCallback) {
27: ((PasswordCallback) callbacks[i]).setPassword(password
28: .toCharArray());
29: }
30: }
31: }
32: }
|