1 22 package org.jboss.test.client.test; 23 24 import javax.security.auth.callback.Callback ; 25 import javax.security.auth.callback.UnsupportedCallbackException ; 26 import javax.security.auth.callback.NameCallback ; 27 import javax.security.auth.callback.PasswordCallback ; 28 import javax.security.auth.callback.CallbackHandler ; 29 30 37 public class SystemPropertyCallbackHandler implements CallbackHandler 38 { 39 public SystemPropertyCallbackHandler() 40 { 41 } 42 43 48 public void handle(Callback [] callbacks) throws 49 UnsupportedCallbackException 50 { 51 for (int i = 0; i < callbacks.length; i++) 52 { 53 Callback c = callbacks[i]; 54 if (c instanceof NameCallback ) 55 { 56 NameCallback nc = (NameCallback ) c; 57 nc.setName(System.getProperty("j_username")); 58 } 59 else if (c instanceof PasswordCallback ) 60 { 61 PasswordCallback pc = (PasswordCallback ) c; 62 String password = System.getProperty("j_password"); 63 if( password != null ) 64 pc.setPassword(password.toCharArray()); 65 } 66 else 67 { 68 throw new UnsupportedCallbackException (callbacks[i], "Unrecognized Callback"); 69 } 70 } 71 } 72 } 73 | Popular Tags |