1 17 18 package org.apache.geronimo.security.bridge; 19 20 import java.util.Set ; 21 import javax.security.auth.Subject ; 22 import javax.security.auth.callback.Callback ; 23 import javax.security.auth.callback.CallbackHandler ; 24 import javax.security.auth.callback.NameCallback ; 25 import javax.security.auth.callback.PasswordCallback ; 26 import javax.security.auth.callback.UnsupportedCallbackException ; 27 28 import org.apache.geronimo.gbean.GBeanInfo; 29 import org.apache.geronimo.gbean.GBeanInfoBuilder; 30 import org.apache.geronimo.security.realm.providers.GeronimoPasswordCredential; 31 32 33 36 public class CallerIdentityUserPasswordRealmBridge extends AbstractRealmBridge { 37 38 private static final GBeanInfo GBEAN_INFO; 39 40 public CallerIdentityUserPasswordRealmBridge() { 41 } 42 43 public CallerIdentityUserPasswordRealmBridge(String targetRealm) { 44 super(targetRealm); 45 } 46 47 48 protected CallbackHandler getCallbackHandler(final Subject sourceSubject) { 49 return new CallbackHandler () { 50 public void handle(Callback [] callbacks) throws UnsupportedCallbackException { 51 Set credentials = sourceSubject.getPrivateCredentials(GeronimoPasswordCredential.class); 52 if (credentials == null || credentials.size() != 1) { 53 throw new UnsupportedCallbackException (null, "No GeronimoPasswordCredential to read"); 54 } 55 GeronimoPasswordCredential geronimoPasswordCredential = (GeronimoPasswordCredential) credentials.iterator().next(); 56 for (int i = 0; i < callbacks.length; i++) { 57 Callback callback = callbacks[i]; 58 if (callback instanceof NameCallback ) { 59 ((NameCallback ) callback).setName(geronimoPasswordCredential.getUserName()); 60 } else if (callback instanceof PasswordCallback ) { 61 ((PasswordCallback ) callback).setPassword(geronimoPasswordCredential.getPassword()); 62 } else { 63 throw new UnsupportedCallbackException (callback, "Only name and password callbacks supported"); 64 } 65 66 } 67 } 68 69 }; 70 } 71 72 static { 73 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(CallerIdentityUserPasswordRealmBridge.class, AbstractRealmBridge.GBEAN_INFO); 74 GBEAN_INFO = infoFactory.getBeanInfo(); 75 } 76 77 public static GBeanInfo getGBeanInfo() { 78 return GBEAN_INFO; 79 } 80 81 } 82 | Popular Tags |