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.login.LoginException ; 23 24 import org.apache.geronimo.security.ContextManager; 25 import org.apache.geronimo.security.IdentificationPrincipal; 26 import org.apache.geronimo.security.realm.providers.GeronimoPasswordCredential; 27 28 29 32 public class CallerIdentityUserPasswordBridgeTest extends AbstractBridgeTest { 33 34 private CallerIdentityUserPasswordRealmBridge bridge; 35 36 protected void setUp() throws Exception { 37 super.setUp(); 38 bridge = new CallerIdentityUserPasswordRealmBridge(); 39 bridge.setTargetRealm(TestLoginModule.JAAS_NAME); 40 } 41 42 public void testCallerIdentityBridge() throws Exception { 43 Subject sourceSubject = new Subject (); 44 sourceSubject.getPrivateCredentials().add(new GeronimoPasswordCredential(AbstractBridgeTest.USER, AbstractBridgeTest.PASSWORD.toCharArray())); 45 Subject targetSubject = bridge.mapSubject(sourceSubject); 46 assertTrue("expected non-null client subject", targetSubject != null); 47 Set set = targetSubject.getPrincipals(IdentificationPrincipal.class); 48 assertEquals("client subject should have one ID principal", set.size(), 1); 49 IdentificationPrincipal idp = (IdentificationPrincipal)set.iterator().next(); 50 targetSubject = ContextManager.getRegisteredSubject(idp.getId()); 51 checkValidSubject(targetSubject); 52 } 53 54 public void testNoCredentials() throws Exception { 55 Subject sourceSubject = new Subject (); 56 try { 57 bridge.mapSubject(sourceSubject); 58 fail(); 59 } catch (LoginException e) { 60 } 61 62 } 63 } 64 | Popular Tags |