1 22 package org.jboss.ejb3.test.security; 23 24 import java.io.IOException ; 25 import javax.security.auth.callback.Callback ; 26 import javax.security.auth.callback.CallbackHandler ; 27 import javax.security.auth.callback.NameCallback ; 28 import javax.security.auth.callback.PasswordCallback ; 29 import javax.security.auth.callback.TextInputCallback ; 30 import javax.security.auth.callback.UnsupportedCallbackException ; 31 32 import org.jboss.logging.Logger; 33 34 41 public class AppCallbackHandler implements CallbackHandler 42 { 43 private static final Logger log = Logger.getLogger(AppCallbackHandler.class); 44 45 private String username; 46 private char[] password; 47 private byte[] data; 48 private String text; 49 50 public AppCallbackHandler(String username, char[] password) 51 { 52 this.username = username; 53 this.password = password; 54 } 55 public AppCallbackHandler(String username, char[] password, byte[] data) 56 { 57 this.username = username; 58 this.password = password; 59 this.data = data; 60 } 61 public AppCallbackHandler(String username, char[] password, byte[] data, String text) 62 { 63 this.username = username; 64 this.password = password; 65 this.data = data; 66 this.text = text; 67 } 68 69 public void handle(Callback [] callbacks) throws 70 IOException , UnsupportedCallbackException 71 { 72 for (int i = 0; i < callbacks.length; i++) 73 { 74 Callback c = callbacks[i]; 75 76 if( c instanceof NameCallback ) 77 { 78 NameCallback nc = (NameCallback ) c; 79 nc.setName(username); 80 } 81 else if( c instanceof PasswordCallback ) 82 { 83 PasswordCallback pc = (PasswordCallback ) c; 84 pc.setPassword(password); 85 } 86 else if( c instanceof TextInputCallback ) 87 { 88 TextInputCallback tc = (TextInputCallback ) c; 89 tc.setText(text); 90 } 91 else if( c instanceof ByteArrayCallback ) 92 { 93 ByteArrayCallback bac = (ByteArrayCallback) c; 94 bac.setByteArray(data); 95 } 96 else 97 { 98 throw new UnsupportedCallbackException (c, "Unrecognized Callback"); 99 } 100 } 101 } 102 } 103 104 | Popular Tags |