AbstractLoginModule implements LoginModule { @NotNull protected Set<? extends Principal> getPrincipals(@NotNull String userId) { PrincipalProvider principalProvider = getPrincipalProvider(); if (principalProvider == null) { log.debug("Cannot retrieve principals. No principal provider configured."); return Collections.emptySet(); } else { return principalProvider.getPrincipals(userId); } }  @Override void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options); @Override boolean logout(); @Override boolean abort(); static final String SHARED_KEY_CREDENTIALS; static final String SHARED_KEY_LOGIN_NAME; static final String SHARED_KEY_ATTRIBUTES; static final String SHARED_KEY_PRE_AUTH_LOGIN; }
@Test public void testGetPrincipals() { PrincipalProvider principalProvider = new TestPrincipalProvider(); AbstractLoginModule loginModule = initLoginModule(new TestCallbackHandler(principalProvider)); Principal principal = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP).next(); String userId = TestPrincipalProvider.getIDFromPrincipal(principal); Set<? extends Principal> principals = loginModule.getPrincipals(userId); assertFalse(principals.isEmpty()); assertEquals(principalProvider.getPrincipals(userId), principals); }
@Test public void testGetPrincipalsMissingProvider() { AbstractLoginModule loginModule = initLoginModule(new TestCallbackHandler()); Set<? extends Principal> principals = loginModule.getPrincipals("userId"); assertTrue(principals.isEmpty()); }
@Test public void testGetPrincipalsFromPrincipal() { PrincipalProvider principalProvider = new TestPrincipalProvider(); AbstractLoginModule loginModule = initLoginModule(new TestCallbackHandler(principalProvider)); Principal principal = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP).next(); Set<Principal> expected = new HashSet<>(); expected.add(principal); expected.addAll(principalProvider.getMembershipPrincipals(principal)); Set<? extends Principal> principals = loginModule.getPrincipals(principal); assertFalse(principals.isEmpty()); assertEquals(expected, principals); }
@Test public void testGetPrincipalsFromPrincipalMissingProvider() { AbstractLoginModule loginModule = initLoginModule(new TestCallbackHandler()); Set<? extends Principal> principals = loginModule.getPrincipals(new PrincipalImpl("principalName")); assertTrue(principals.isEmpty()); }