1 22 package org.jboss.test.util; 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 39 public class AppCallbackHandler implements CallbackHandler 40 { 41 private String username; 42 private char[] password; 43 private byte[] data; 44 private String text; 45 46 public AppCallbackHandler(String username, char[] password) 47 { 48 this.username = username; 49 this.password = password; 50 } 51 public AppCallbackHandler(String username, char[] password, byte[] data) 52 { 53 this.username = username; 54 this.password = password; 55 this.data = data; 56 } 57 public AppCallbackHandler(String username, char[] password, byte[] data, String text) 58 { 59 this.username = username; 60 this.password = password; 61 this.data = data; 62 this.text = text; 63 } 64 65 public void handle(Callback [] callbacks) throws 66 IOException , UnsupportedCallbackException 67 { 68 for (int i = 0; i < callbacks.length; i++) 69 { 70 Callback c = callbacks[i]; 71 if( c instanceof NameCallback ) 72 { 73 NameCallback nc = (NameCallback ) c; 74 nc.setName(username); 75 } 76 else if( c instanceof PasswordCallback ) 77 { 78 PasswordCallback pc = (PasswordCallback ) c; 79 pc.setPassword(password); 80 } 81 else if( c instanceof TextInputCallback ) 82 { 83 TextInputCallback tc = (TextInputCallback ) c; 84 tc.setText(text); 85 } 86 else if( c instanceof ByteArrayCallback ) 87 { 88 ByteArrayCallback bac = (ByteArrayCallback) c; 89 bac.setByteArray(data); 90 } 91 else 92 { 93 throw new UnsupportedCallbackException (c, "Unrecognized Callback"); 94 } 95 } 96 } 97 } 98 99 | Popular Tags |