1 17 18 package org.apache.geronimo.security.bridge; 19 20 import javax.security.auth.Subject ; 21 import javax.security.auth.callback.CallbackHandler ; 22 import javax.security.auth.login.LoginContext ; 23 import javax.security.auth.login.LoginException ; 24 25 import org.apache.geronimo.gbean.GBeanInfo; 26 import org.apache.geronimo.gbean.GBeanInfoBuilder; 27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 28 29 30 33 public abstract class AbstractRealmBridge implements RealmBridge { 34 private String targetRealm; 35 36 public AbstractRealmBridge() { 37 } 38 39 public AbstractRealmBridge(String targetRealm) { 40 this.targetRealm = targetRealm; 41 } 42 43 public Subject mapSubject(Subject sourceSubject) throws LoginException { 44 Subject targetSubject = new Subject (); 45 LoginContext loginContext = new LoginContext (targetRealm, targetSubject, getCallbackHandler(sourceSubject)); 46 loginContext.login(); 47 return targetSubject; 48 } 49 50 protected abstract CallbackHandler getCallbackHandler(Subject sourceSubject); 51 52 public String getTargetRealm() { 53 return targetRealm; 54 } 55 56 public void setTargetRealm(String targetRealm) { 57 this.targetRealm = targetRealm; 58 } 59 60 public static final GBeanInfo GBEAN_INFO; 61 62 static { 63 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(AbstractRealmBridge.class, NameFactory.REALM_BRIDGE); 64 infoFactory.addAttribute("targetRealm", String .class, true); 65 infoFactory.setConstructor(new String []{"targetRealm"}); 66 infoFactory.addOperation("mapSubject", new Class [] {Subject .class}); 67 GBEAN_INFO = infoFactory.getBeanInfo(); 68 } 69 70 public static GBeanInfo getGBeanInfo() { 71 return GBEAN_INFO; 72 } 73 74 } 75 | Popular Tags |