UserPrincipalProvider implements PrincipalProvider { @Override public Principal getPrincipal(@NotNull String principalName) { Tree authorizableTree = userProvider.getAuthorizableByPrincipal(new PrincipalImpl(principalName)); Principal principal = createPrincipal(authorizableTree); if (principal == null) { return (EveryonePrincipal.NAME.equals(principalName)) ? EveryonePrincipal.getInstance() : null; } else { return principal; } } UserPrincipalProvider(@NotNull Root root,
                          @NotNull UserConfiguration userConfiguration,
                          @NotNull NamePathMapper namePathMapper); @Override Principal getPrincipal(@NotNull String principalName); @Nullable @Override ItemBasedPrincipal getItemBasedPrincipal(@NotNull String principalOakPath); @NotNull @Override Set<Principal> getMembershipPrincipals(@NotNull Principal principal); @NotNull @Override Set<? extends Principal> getPrincipals(@NotNull String userID); @NotNull @Override Iterator<? extends Principal> findPrincipals(@Nullable final String nameHint, final int searchType); @NotNull @Override Iterator<? extends Principal> findPrincipals(@Nullable final String nameHint, final boolean fullText, final int searchType, long offset,
            long limit); @NotNull @Override Iterator<? extends Principal> findPrincipals(int searchType);  }
@Test public void testTreeBasedUserPrincipal() throws Exception { User user = getTestUser(); Principal principal = principalProvider.getPrincipal(user.getPrincipal().getName()); assertTrue(principal instanceof TreeBasedPrincipal); }
@Test public void testTreeBasedSystemUserPrincipal() throws Exception { User systemUser = getUserManager(root).createSystemUser("systemUser" + UUID.randomUUID(), null); root.commit(); try { Principal principal = principalProvider.getPrincipal(systemUser.getPrincipal().getName()); assertTrue(principal instanceof SystemUserPrincipalImpl); } finally { systemUser.remove(); root.commit(); } }
@Test public void testTreeBasedGroupPrincipal() throws Exception { Principal principal = principalProvider.getPrincipal(testGroup.getPrincipal().getName()); assertTrue(principal instanceof AbstractGroupPrincipal); }
@Test public void testTreeBasedGroupPrincipalReflectsMemberChanges() throws Exception { Principal principal = principalProvider.getPrincipal(testGroup.getPrincipal().getName()); assertTrue(principal instanceof AbstractGroupPrincipal); AbstractGroupPrincipal agp = (AbstractGroupPrincipal) principal; User u = getTestUser(); assertTrue(agp.isMember(u)); testGroup.removeMember(u); assertFalse(agp.isMember(u)); }
@Test public void testTreeBasedGroupPrincipalReflectsRemoval() throws Exception { Principal principal = principalProvider.getPrincipal(testGroup.getPrincipal().getName()); assertTrue(principal instanceof AbstractGroupPrincipal); AbstractGroupPrincipal agp = (AbstractGroupPrincipal) principal; testGroup.remove(); assertFalse(agp.isMember(getTestUser())); }
@Test public void testTreeBasedGroupPrincipalReflectsChangedType() throws Exception { Principal principal = principalProvider.getPrincipal(testGroup.getPrincipal().getName()); assertTrue(principal instanceof AbstractGroupPrincipal); AbstractGroupPrincipal agp = (AbstractGroupPrincipal) principal; Tree t = root.getTree(testGroup.getPath()); t.setProperty(JCR_PRIMARYTYPE, NT_REP_USER, Type.NAME); assertFalse(agp.isMember(getTestUser())); }
@Test public void testEveryoneMembers() throws Exception { Principal everyone = principalProvider.getPrincipal(EveryonePrincipal.NAME); assertTrue(everyone instanceof EveryonePrincipal); Group everyoneGroup = null; try { UserManager userMgr = getUserManager(root); everyoneGroup = userMgr.createGroup(EveryonePrincipal.NAME); root.commit(); Principal ep = principalProvider.getPrincipal(EveryonePrincipal.NAME); assertTrue(ep instanceof GroupPrincipal); } finally { if (everyoneGroup != null) { everyoneGroup.remove(); root.commit(); } } }
@Test public void testGroupMembers() throws Exception { Principal principal = principalProvider.getPrincipal(testGroup.getPrincipal().getName()); assertTrue(principal instanceof GroupPrincipal); boolean found = false; Enumeration<? extends Principal> members = ((GroupPrincipal) principal).members(); while (members.hasMoreElements() && !found) { found = members.nextElement().equals(getTestUser().getPrincipal()); } assertTrue(found); }
@Test public void testGroupIsMember() throws Exception { Principal principal = principalProvider.getPrincipal(testGroup.getPrincipal().getName()); assertTrue(principal instanceof GroupPrincipal); assertTrue(((GroupPrincipal) principal).isMember(getTestUser().getPrincipal())); }