@NotNull @Override public Principal perform() throws RepositoryException { return delegate.getPrincipal(); } });
@Override public Principal apply(@Nullable Authorizable authorizable) { if (authorizable != null) { try { return authorizable.getPrincipal(); } catch (RepositoryException e) { log.debug(e.getMessage()); } } return null; } }
@Override public Principal apply(@Nullable Authorizable authorizable) { if (authorizable != null) { try { return authorizable.getPrincipal(); } catch (RepositoryException e) { log.debug(e.getMessage()); } } return null; } }
private Set<Principal> getAuthorizablesToCheck(Authorizable authorizable, Context context) throws RepositoryException { Set<Principal> principals = new HashSet<>(); Principal principal = authorizable.getPrincipal(); principals.add(principal); for (PrincipalIterator it = (context.getSession()).getPrincipalManager() .getGroupMembership(principal); it.hasNext(); ) { principals.add(it.nextPrincipal()); } return principals; }
@Override protected void createDeepTree() throws Exception { UserManager uMgr = ((JackrabbitSession) adminSession).getUserManager(); for (int i = 0; i < 100; i++) { Authorizable a = uMgr.getAuthorizable("group" + i); if (a == null) { a = uMgr.createGroup("group" + i); principals.add(a.getPrincipal()); } } super.createDeepTree(); }
@Override protected void createDeepTree() throws Exception { UserManager uMgr = ((JackrabbitSession) adminSession).getUserManager(); for (int i = 0; i < 100; i++) { Authorizable a = uMgr.getAuthorizable("group" + i); if (a == null) { a = uMgr.createGroup("group" + i); principals.add(a.getPrincipal()); } } super.createDeepTree(); }
public boolean evaluate(Authorizable authorizable) { try { String name = authorizable.getID(); Principal principal = authorizable.getPrincipal(); return name.startsWith("a") || principal != null && principal.getName().startsWith("a"); } catch (RepositoryException e) { fail(e.getMessage()); } return false; } });
@Test public void testGetGroupMembershipExternalGroup() throws Exception { Authorizable group = getUserManager(root).getAuthorizable("secondGroup"); assertNotNull(group); Set<? extends Principal> principals = principalProvider.getMembershipPrincipals(group.getPrincipal()); assertTrue(principals.isEmpty()); // same if the principal is not marked as 'GroupPrincipal' and not tree-based-principal principals = principalProvider.getMembershipPrincipals(new PrincipalImpl(group.getPrincipal().getName())); assertTrue(principals.isEmpty()); }
@Test public void testGetGroupMembershipDefaultSync2() throws Exception { // synchronized by default sync-context => no 'dynamic' group principals Authorizable user = getUserManager(root).getAuthorizable(TestIdentityProvider.ID_SECOND_USER); assertNotNull(user); // same as in test before even if the principal is not a tree-based-principal Set<? extends Principal> principals = principalProvider.getMembershipPrincipals(new PrincipalImpl(user.getPrincipal().getName())); assertTrue(principals.isEmpty()); }
@Test public void testAdminImpersonation() throws Exception { final String adminPrincipalName = userMgr.getAuthorizable(superuser.getUserID()).getPrincipal().getName(); Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() { public <T> void build(QueryBuilder<T> builder) { builder.setCondition(builder.impersonates(adminPrincipalName)); } }); Iterator<Authorizable> expected = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, null, UserManager.SEARCH_TYPE_USER); assertTrue(result.hasNext()); assertSameElements(expected, result); }
@Test public void testVisitImpersonationAdmin() throws Exception { String adminPrincipalName = getUserManager(root).getAuthorizable(getUserConfiguration().getParameters().getConfigValue(UserConstants.PARAM_ADMIN_ID, UserConstants.DEFAULT_ADMIN_ID)).getPrincipal().getName(); Condition.Impersonation c = new Condition.Impersonation(adminPrincipalName); visitor.visit(c); String s = statement.toString(); assertFalse(s.contains(UserConstants.REP_IMPERSONATORS)); assertTrue(s.contains("@rcj:primaryType='" + UserConstants.NT_REP_USER + "'")); }
@Test public void testGetGroupMembershipDefaultSync() throws Exception { // synchronized by default sync-context => no 'dynamic' group principals Authorizable user = getUserManager(root).getAuthorizable(TestIdentityProvider.ID_SECOND_USER); assertNotNull(user); Set<? extends Principal> principals = principalProvider.getMembershipPrincipals(user.getPrincipal()); assertTrue(principals.isEmpty()); }
public void testGetPrincipal() throws RepositoryException { Authorizable admin = userMgr.getAuthorizable(adminId); assertNotNull(admin); assertFalse(admin.isGroup()); assertTrue(admin.getPrincipal() instanceof AdminPrincipal); }
@Test public void testGetGroupPrincipals() throws Exception { Set<Principal> expected = getExpectedGroupPrincipals(USER_ID); Authorizable user = getUserManager(root).getAuthorizable(USER_ID); Set<Principal> result = principalProvider.getMembershipPrincipals(user.getPrincipal()); assertTrue(result.contains(userAutoMembershipGroup.getPrincipal())); assertTrue(result.contains(groupAutoMembershipGroup.getPrincipal())); assertEquals(expected, result); }
@Test public void testGetGroupMembershipExternalUser2() throws Exception { Authorizable user = getUserManager(root).getAuthorizable(USER_ID); assertNotNull(user); Set<Principal> expected = getExpectedGroupPrincipals(USER_ID); // same as in test before even if the principal is not a tree-based-principal Set<? extends Principal> principals = principalProvider.getMembershipPrincipals(new PrincipalImpl(user.getPrincipal().getName())); assertEquals(expected, principals); }
@Test public void testGetPrincipal() throws RepositoryException, NotExecutableException { assertNotNull(group.getPrincipal()); assertNotNull(userMgr.getAuthorizable(group.getID()).getPrincipal()); }
@Test public void testGetPrincipal() throws RepositoryException, NotExecutableException { assertNotNull(user.getPrincipal()); assertNotNull(userMgr.getAuthorizable(user.getID()).getPrincipal()); }
@Test public void testIsMember() throws Exception { ExternalUser externalUser = idp.getUser(USER_ID); GroupPrincipal principal = getGroupPrincipal(externalUser.getDeclaredGroups().iterator().next()); assertTrue(principal.isMember(new PrincipalImpl(externalUser.getPrincipalName()))); assertTrue(principal.isMember(getUserManager(root).getAuthorizable(USER_ID).getPrincipal())); }
@Test public void testGetGroupMembershipExternalUser() throws Exception { Authorizable user = getUserManager(root).getAuthorizable(USER_ID); assertNotNull(user); Set<Principal> expected = getExpectedGroupPrincipals(USER_ID); Set<? extends Principal> principals = principalProvider.getMembershipPrincipals(user.getPrincipal()); assertEquals(expected, principals); }
@Test public void testImpersonation() throws Exception { User u = mgr.createUser("u", "u"); Impersonation imp = u.getImpersonation(); Principal p = mgr.getAuthorizable("anonymous").getPrincipal(); assertTrue(imp.grantImpersonation(p)); assertFalse(root.hasPendingChanges()); assertTrue(imp.revokeImpersonation(p)); assertFalse(root.hasPendingChanges()); }