ExternalGroupPrincipalProvider implements PrincipalProvider, ExternalIdentityConstants { @Override public Principal getPrincipal(@NotNull String principalName) { Result result = findPrincipals(principalName, true); if (result != null && result.getRows().iterator().hasNext()) { return new ExternalGroupPrincipal(principalName); } else { return null; } } 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 testGetPrincipalLocalUser() throws Exception { assertNull(principalProvider.getPrincipal(getTestUser().getPrincipal().getName())); }
@Test public void testGetPrincipalLocalGroup() throws Exception { Group gr = createTestGroup(); assertNull(principalProvider.getPrincipal(gr.getPrincipal().getName())); }
@Test public void testGetPrincipalExternalUser() throws Exception { UserManager userManager = getUserManager(root); User syncedUser = userManager.getAuthorizable(USER_ID, User.class); assertNull(principalProvider.getPrincipal(syncedUser.getPrincipal().getName())); syncedUser = userManager.getAuthorizable(TestIdentityProvider.ID_SECOND_USER, User.class); assertNull(principalProvider.getPrincipal(syncedUser.getPrincipal().getName())); }
@Test public void testGetPrincipalExternalGroup() throws Exception { Group gr = getUserManager(root).getAuthorizable("secondGroup", Group.class); assertNotNull(gr); assertNull(principalProvider.getPrincipal(gr.getPrincipal().getName())); }
@Test public void testGetPrincipalDynamicGroup() throws Exception { for (ExternalIdentityRef ref : idp.getUser(USER_ID).getDeclaredGroups()) { String princName = idp.getIdentity(ref).getPrincipalName(); Principal principal = principalProvider.getPrincipal(princName); assertNotNull(principal); assertTrue(principal instanceof GroupPrincipal); } }
@Test public void testGetPrincipalInheritedGroups() throws Exception { ImmutableSet<ExternalIdentityRef> declared = ImmutableSet.<ExternalIdentityRef>copyOf(idp.getUser(USER_ID).getDeclaredGroups()); for (ExternalIdentityRef ref : declared) { for (ExternalIdentityRef inheritedGroupRef : idp.getIdentity(ref).getDeclaredGroups()) { if (declared.contains(inheritedGroupRef)) { continue; } String inheritedPrincName = idp.getIdentity(inheritedGroupRef).getPrincipalName(); assertNull(principalProvider.getPrincipal(inheritedPrincName)); } } }
@Test public void testGetPrincipalUnderscoreSign() throws Exception { ExternalUser externalUser = idp.getUser(USER_ID); for (ExternalIdentityRef ref : externalUser.getDeclaredGroups()) { String pName = idp.getIdentity(ref).getPrincipalName(); for (String n : new String[]{"_", "_" + pName.substring(1), pName.substring(0, pName.length() - 1) + "_"}) { assertNull(principalProvider.getPrincipal(n)); } } }
@Test public void testGetPrincipalPercentSign() throws Exception { ExternalUser externalUser = idp.getUser(USER_ID); for (ExternalIdentityRef ref : externalUser.getDeclaredGroups()) { String pName = idp.getIdentity(ref).getPrincipalName(); for (String n : new String[] {"%", "%" + pName, pName + "%", pName.charAt(0) + "%"}) { assertNull(principalProvider.getPrincipal(n)); } } }
@Test public void testGetPrincipalGroupsWithQueryWildCard() throws Exception { ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_WILDCARD_USER); sync(externalUser); for (ExternalIdentityRef ref : externalUser.getDeclaredGroups()) { String pName = idp.getIdentity(ref).getPrincipalName(); Principal p = principalProvider.getPrincipal(pName); assertNotNull(p); assertEquals(pName, p.getName()); } }