1 10 11 package org.mule.extras.jaas; 12 13 import java.io.IOException ; 14 import javax.security.auth.callback.Callback ; 15 import javax.security.auth.callback.CallbackHandler ; 16 import javax.security.auth.callback.NameCallback ; 17 import javax.security.auth.callback.PasswordCallback ; 18 import javax.security.auth.callback.UnsupportedCallbackException ; 19 import org.mule.umo.security.UMOAuthentication; 20 21 24 public class MuleCallbackHandler implements CallbackHandler 25 { 26 private UMOAuthentication authentication; 27 private String username; 28 private String password; 29 30 33 public MuleCallbackHandler(UMOAuthentication authentication) 34 { 35 this.authentication = authentication; 36 this.username = (String )this.authentication.getPrincipal(); 37 this.password = (String )this.authentication.getCredentials(); 38 } 39 40 49 public final void handle(Callback [] callbacks) throws IOException , UnsupportedCallbackException 50 { 51 for (int i = 0; i < callbacks.length; i++) 52 { 53 if (callbacks[i] instanceof NameCallback ) 54 { 55 NameCallback nameCb = (NameCallback )callbacks[i]; 56 nameCb.setName(username); 57 } 58 else if (callbacks[i] instanceof PasswordCallback ) 59 { 60 PasswordCallback passCb = (PasswordCallback )callbacks[i]; 61 passCb.setPassword(password.toCharArray()); 62 } 63 else 64 { 65 throw (new UnsupportedCallbackException (callbacks[i], "Callback class not supported")); 66 } 67 } 68 } 69 } 70 | Popular Tags |