1 26 27 package org.objectweb.jonas.security.auth.callback; 28 29 import java.io.IOException ; 30 import javax.security.auth.callback.CallbackHandler ; 31 import javax.security.auth.callback.UnsupportedCallbackException ; 32 import javax.security.auth.callback.NameCallback ; 33 import javax.security.auth.callback.PasswordCallback ; 34 import javax.security.auth.callback.Callback ; 35 import java.security.cert.Certificate ; 36 37 44 public class NoInputCallbackHandler implements CallbackHandler { 45 46 49 private String username = null; 50 51 54 private String password = null; 55 56 59 private Certificate cert = null; 60 61 65 public NoInputCallbackHandler() throws Exception { 66 throw new Exception ( 67 "This class could only be used with the constructor NoInputCallbackHandler(String username, String password)"); 68 } 69 70 75 public NoInputCallbackHandler(String username, String password) { 76 this.username = username; 77 this.password = password; 78 } 79 80 86 public NoInputCallbackHandler(String username, String password, Certificate cert) { 87 this(username, password); 88 this.cert = cert; 89 } 90 91 101 public void handle(Callback [] callbacks) throws IOException , UnsupportedCallbackException { 102 103 for (int i = 0; i < callbacks.length; i++) { 104 if (callbacks[i] instanceof NameCallback ) { 105 NameCallback nc = (NameCallback ) callbacks[i]; 107 nc.setName(username); 108 } else if (callbacks[i] instanceof PasswordCallback ) { 109 PasswordCallback pc = (PasswordCallback ) callbacks[i]; 111 pc.setPassword(password.toCharArray()); 112 } else if (callbacks[i] instanceof CertificateCallback) { 113 CertificateCallback cc = (CertificateCallback) callbacks[i]; 114 cc.setUserCertificate(cert); 115 } else { 116 throw new UnsupportedCallbackException (callbacks[i], "Unrecognized Callback"); 117 } 118 } 119 } 120 } | Popular Tags |