1 13 package info.magnolia.cms.security.auth; 14 15 import java.io.IOException ; 16 17 import javax.security.auth.callback.Callback ; 18 import javax.security.auth.callback.CallbackHandler ; 19 import javax.security.auth.callback.NameCallback ; 20 import javax.security.auth.callback.PasswordCallback ; 21 import javax.security.auth.callback.TextOutputCallback ; 22 import javax.security.auth.callback.UnsupportedCallbackException ; 23 24 import org.slf4j.Logger; 25 import org.slf4j.LoggerFactory; 26 27 28 33 public class CredentialsCallbackHandler implements CallbackHandler { 34 35 38 protected static Logger log = LoggerFactory.getLogger(CredentialsCallbackHandler.class); 39 40 43 protected String name; 44 45 48 protected char[] pswd; 49 50 53 public CredentialsCallbackHandler() { 54 } 56 57 61 public CredentialsCallbackHandler(String name, char[] pswd) { 62 this.name = name; 63 this.pswd = pswd; 64 } 65 66 69 public void handle(Callback [] callbacks) throws IOException , UnsupportedCallbackException { 70 for (int i = 0; i < callbacks.length; i++) { 71 if (callbacks[i] instanceof NameCallback ) { 72 ((NameCallback ) callbacks[i]).setName(this.name); 73 } 74 else if (callbacks[i] instanceof PasswordCallback ) { 75 ((PasswordCallback ) callbacks[i]).setPassword(this.pswd); 76 } 77 else if (callbacks[i] instanceof TextOutputCallback ) { 78 TextOutputCallback outputCallback = (TextOutputCallback ) callbacks[i]; 79 switch (outputCallback.getMessageType()) { 80 case TextOutputCallback.INFORMATION: 81 log.info(outputCallback.getMessage()); 82 break; 83 case TextOutputCallback.ERROR: 84 log.error(outputCallback.getMessage()); 85 break; 86 case TextOutputCallback.WARNING: 87 log.warn(outputCallback.getMessage()); 88 break; 89 default: 90 if (log.isDebugEnabled()) { 91 log.debug("Unsupported message type : {}", Integer 92 .toString(outputCallback.getMessageType())); 93 log.debug("Message : {}", outputCallback.getMessage()); 94 } 95 } 96 } 97 } 98 } 99 } 100 | Popular Tags |