/** * Get the participant id of the given subject. * * The subject is searched for compatible principals. When other * authentication types are added, this method will need to be updated to * support their principal types. * * @throws InvalidParticipantAddress The subject's address is invalid */ private ParticipantId getLoggedInUser(Subject subject) throws InvalidParticipantAddress { String address = null; for (Principal p : subject.getPrincipals()) { // TODO(josephg): When we support other authentication types (LDAP, etc), // this method will need to read the address portion out of the other principal types. if (p instanceof ParticipantPrincipal) { address = ((ParticipantPrincipal) p).getName(); break; } else if (p instanceof X500Principal) { return attemptClientCertificateLogin((X500Principal)p); } } return address == null ? null : ParticipantId.of(address); }
principal = new ParticipantPrincipal(id); status = Status.OK; return true;
public void testMissingDomainIsAddedAutomatically() throws Exception { LoginContext context = makeLoginContext("haspwd", "pwd"); context.login(); Subject subject = context.getSubject(); ParticipantPrincipal p = subject.getPrincipals(ParticipantPrincipal.class).iterator().next(); assertEquals("haspwd@example.com", p.getName()); }
public void testMissingDomainIsAddedAutomatically() throws Exception { LoginContext context = makeLoginContext("haspwd", "pwd"); context.login(); Subject subject = context.getSubject(); ParticipantPrincipal p = subject.getPrincipals(ParticipantPrincipal.class).iterator().next(); assertEquals("haspwd@example.com", p.getName()); }
public void testCorrectPasswordConfiguresSubject() throws Exception { LoginContext context = makeLoginContext("haspwd@example.com", "pwd"); context.login(); Subject subject = context.getSubject(); ParticipantPrincipal p = subject.getPrincipals(ParticipantPrincipal.class).iterator().next(); assertEquals("haspwd@example.com", p.getName()); context.logout(); assertEquals(0, subject.getPrincipals(ParticipantPrincipal.class).size()); }
public void testCorrectPasswordConfiguresSubject() throws Exception { LoginContext context = makeLoginContext("haspwd@example.com", "pwd"); context.login(); Subject subject = context.getSubject(); ParticipantPrincipal p = subject.getPrincipals(ParticipantPrincipal.class).iterator().next(); assertEquals("haspwd@example.com", p.getName()); context.logout(); assertEquals(0, subject.getPrincipals(ParticipantPrincipal.class).size()); }