ExternalGroupPrincipalProvider implements PrincipalProvider, ExternalIdentityConstants { @NotNull @Override public Set<? extends Principal> getPrincipals(@NotNull String userID) { try { return getGroupPrincipals(userManager.getAuthorizable(userID)); } catch (RepositoryException e) { log.debug(e.getMessage()); return ImmutableSet.of(); } } ExternalGroupPrincipalProvider(@NotNull Root root, @NotNull UserConfiguration uc,
                                   @NotNull NamePathMapper namePathMapper,
                                   @NotNull Map<String, String[]> autoMembershipMapping); @Override Principal getPrincipal(@NotNull String principalName); @NotNull @Override Set<Principal> getMembershipPrincipals(@NotNull Principal principal); @NotNull @Override Set<? extends Principal> getPrincipals(@NotNull String userID); @NotNull @Override Iterator<? extends Principal> findPrincipals(@Nullable String nameHint, int searchType); @NotNull @Override Iterator<? extends Principal> findPrincipals(int searchType); @NotNull @Override Iterator<? extends Principal> findPrincipals(@Nullable String nameHint, boolean fullText, int searchType,
            long offset, long limit);  }
@Test public void testGetPrincipalsLocalUser() throws Exception { Set<? extends Principal> principals = principalProvider.getPrincipals(getTestUser().getID()); assertTrue(principals.isEmpty()); }
@Test public void testGetPrincipalsLocalGroup() throws Exception { Set<? extends Principal> principals = principalProvider.getPrincipals(createTestGroup().getID()); assertTrue(principals.isEmpty()); }
@Test public void testGetPrincipalsExternalUser() throws Exception { Set<? extends Principal> principals = principalProvider.getPrincipals(USER_ID); assertEquals(getExpectedGroupPrincipals(USER_ID), principals); }
@Test public void testGetPrincipalsExternalUser2() { Set<? extends Principal> principals = principalProvider.getPrincipals(TestIdentityProvider.ID_SECOND_USER); assertTrue(principals.isEmpty()); }
@Test public void testGetPrincipalsExternalGroup() throws Exception { Authorizable authorizable = getUserManager(root).getAuthorizable("secondGroup"); assertNotNull(authorizable); Set<? extends Principal> principals = principalProvider.getPrincipals(authorizable.getID()); assertTrue(principals.isEmpty()); }
@Test public void testGetPrincipalsNonExistingUser() throws Exception { assertNull(getUserManager(root).getAuthorizable("nonExistingUser")); Set<? extends Principal> principals = principalProvider.getPrincipals("nonExistingUser"); assertTrue(principals.isEmpty()); }
@Test public void testGetPrincipalsNonExistingUserTree() throws Exception { Authorizable a = spy(getUserManager(root).getAuthorizable(USER_ID)); when(a.getPath()).thenReturn("/path/to/non/existing/item"); UserManager um = when(mock(UserManager.class).getAuthorizable(USER_ID)).thenReturn(a).getMock(); UserConfiguration uc = when(mock(UserConfiguration.class).getUserManager(root, getNamePathMapper())).thenReturn(um).getMock(); ExternalGroupPrincipalProvider pp = new ExternalGroupPrincipalProvider(root, uc, getNamePathMapper(), ImmutableMap.of(idp.getName(), getAutoMembership())); assertTrue(pp.getPrincipals(USER_ID).isEmpty()); }
@Test public void testGetPrincipalsForGroupTree() throws Exception { Authorizable group = getUserManager(root).createGroup("testGroup"); Authorizable a = spy(getUserManager(root).getAuthorizable(USER_ID)); when(a.getPath()).thenReturn(group.getPath()); UserManager um = when(mock(UserManager.class).getAuthorizable(USER_ID)).thenReturn(a).getMock(); UserConfiguration uc = when(mock(UserConfiguration.class).getUserManager(root, getNamePathMapper())).thenReturn(um).getMock(); ExternalGroupPrincipalProvider pp = new ExternalGroupPrincipalProvider(root, uc, getNamePathMapper(), ImmutableMap.of(idp.getName(), getAutoMembership())); assertTrue(pp.getPrincipals(USER_ID).isEmpty()); }
@Test public void testGetPrincipalsMissingIdpName() throws Exception { String userPath = getUserManager(root).getAuthorizable(USER_ID).getPath(); Tree t = root.getTree(userPath); t.removeProperty(REP_EXTERNAL_ID); String[] automembership = getAutoMembership(); ExternalGroupPrincipalProvider pp = new ExternalGroupPrincipalProvider(root, getUserConfiguration(), getNamePathMapper(), ImmutableMap.of(idp.getName(), automembership)); Set<? extends Principal> principals = pp.getPrincipals(USER_ID); assertFalse(principals.isEmpty()); assertFalse(principals.removeAll(ImmutableSet.copyOf(automembership))); }