1 17 18 package org.apache.geronimo.security.bridge; 19 20 import javax.security.auth.Subject ; 21 22 import org.apache.geronimo.security.AbstractTest; 23 import org.apache.geronimo.security.realm.providers.GeronimoPasswordCredential; 24 25 26 29 public abstract class AbstractUserPasswordBridgeTest extends AbstractTest { 30 protected final static String USER = "testuser"; 31 protected final static String PASSWORD = "testpassword"; 32 33 protected void checkValidSubject(Subject targetSubject) { 34 assertEquals("Expected one TestPrincipal", 1, targetSubject.getPrincipals(TestPrincipal.class).size()); 35 Object p = targetSubject.getPrincipals(TestPrincipal.class).iterator().next(); 36 assertSame("Expected ResourcePrincipal", TestPrincipal.class, p.getClass()); 37 assertEquals("Expected name of TestPrincipal to be " + USER, USER, ((TestPrincipal) p).getName()); 38 assertEquals("Expected no public credential", 0, targetSubject.getPublicCredentials().size()); 39 assertEquals("Expected one private credential", 1, targetSubject.getPrivateCredentials().size()); 40 Object cred = targetSubject.getPrivateCredentials().iterator().next(); 41 assertSame("Expected GeronimoPasswordCredential", GeronimoPasswordCredential.class, cred.getClass()); 42 assertEquals("Expected user", USER, ((GeronimoPasswordCredential) cred).getUserName()); 43 assertEquals("Expected password", PASSWORD, new String (((GeronimoPasswordCredential) cred).getPassword())); 44 } 45 } 46 | Popular Tags |