1 18 package org.apache.activemq.jaas; 19 20 import javax.security.auth.callback.Callback ; 21 import javax.security.auth.callback.CallbackHandler ; 22 import javax.security.auth.callback.NameCallback ; 23 import javax.security.auth.callback.PasswordCallback ; 24 import javax.security.auth.callback.UnsupportedCallbackException ; 25 import java.io.IOException ; 26 27 28 31 public class JassCredentialCallbackHandler implements CallbackHandler { 32 33 private final String username; 34 private final String password; 35 36 public JassCredentialCallbackHandler(String username, String password) { 37 this.username = username; 38 this.password = password; 39 } 40 41 public void handle(Callback [] callbacks) throws IOException , UnsupportedCallbackException { 42 for (int i = 0; i < callbacks.length; i++) { 43 Callback callback = callbacks[i]; 44 if (callback instanceof PasswordCallback ) { 45 PasswordCallback passwordCallback = (PasswordCallback ) callback; 46 if (password == null) { 47 passwordCallback.setPassword(null); 48 } 49 else { 50 passwordCallback.setPassword(password.toCharArray()); 51 } 52 } else if (callback instanceof NameCallback ) { 53 NameCallback nameCallback = (NameCallback ) callback; 54 if (username == null) { 55 nameCallback.setName(null); 56 } 57 else { 58 nameCallback.setName(username); 59 } 60 } 61 } 62 } 63 } 64 | Popular Tags |