1 17 package org.acme; 18 19 import java.io.IOException ; 20 import javax.security.auth.callback.CallbackHandler ; 21 import javax.security.auth.callback.Callback ; 22 import javax.security.auth.callback.UnsupportedCallbackException ; 23 import javax.security.auth.callback.NameCallback ; 24 import javax.security.auth.callback.PasswordCallback ; 25 26 29 public class MagicGBallCallbackHandler implements CallbackHandler { 30 31 public void handle(Callback [] callbacks) throws IOException , UnsupportedCallbackException { 32 for (int i = 0; i < callbacks.length; i++) { 33 Callback callback = callbacks[i]; 34 if (callback instanceof NameCallback ) { 35 ((NameCallback )callback).setName("system"); 36 } else if (callback instanceof PasswordCallback ) { 37 ((PasswordCallback )callback).setPassword("manager".toCharArray()); 38 } else { 39 throw new UnsupportedCallbackException (callback); 40 } 41 System.out.println("CallbackHandler set user=system, password=manager"); 42 } 43 } 44 } 45 | Popular Tags |