@Test public void testLoginAfterChangePassword2() throws RepositoryException, NotExecutableException { try { user.changePassword("changed", testPw); superuser.save(); // make sure the user can login with the new pw Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(), "changed".toCharArray())); s.logout(); } finally { user.changePassword(testPw); superuser.save(); } }
private boolean isAdmin(SessionContext sessionContext, String user) { try { Authorizable a = sessionContext.getUserManager().getAuthorizable( user); if (a != null && !a.isGroup()) { return ((User) a).isAdmin(); } } catch (RepositoryException e) { // ? } return false; } }
@Test public void testEnableUser() throws Exception { user.disable("readonly user is disabled!"); superuser.save(); // enable user again user.disable(null); superuser.save(); assertFalse(user.isDisabled()); assertNull(user.getDisabledReason()); // -> login must succeed again getHelper().getRepository().login(new SimpleCredentials(user.getID(), "pw".toCharArray())).logout(); }
public List<IPentahoRole> getUserRoles( Session session, final ITenant theTenant, final String userName ) throws RepositoryException { ArrayList<IPentahoRole> roles = new ArrayList<IPentahoRole>(); User jackrabbitUser = getJackrabbitUser( theTenant, userName, session ); if ( ( jackrabbitUser != null ) && TenantUtils.isAccessibleTenant( theTenant == null ? tenantedUserNameUtils.getTenant( jackrabbitUser.getID() ) : theTenant ) ) { Iterator<Group> groups = jackrabbitUser.memberOf(); while ( groups.hasNext() ) { IPentahoRole role = convertToPentahoRole( groups.next() ); // Exclude the extra role from the list of roles to be returned back if ( !extraRoles.contains( role.getName() ) ) { roles.add( role ); } } } return roles; }
public void testImpersonateTestUser() throws RepositoryException { Principal principal = null; // EXERCISE: fill in the correct principal such that the test passes. Impersonation impersonation = anotherUser.getImpersonation(); impersonation.grantImpersonation(principal); superuser.save(); Session testSession = superuser.getRepository().login(ExerciseUtility.getTestCredentials(testUser.getID())); sessionList.add(testSession); Session impersonated = testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0])); sessionList.add(impersonated); assertEquals(anotherUser.getID(), impersonated.getUserID()); }
assertTrue(target.isModified()); assertTrue(s.hasPendingChanges()); Authorizable newUser = getUserManager().getAuthorizable("t"); assertNotNull(newUser); assertFalse(newUser.isGroup()); assertTrue(((User) newUser).isSystemUser()); assertEquals("t", newUser.getPrincipal().getName()); assertEquals("t", newUser.getID()); assertTrue(((User) newUser).isDisabled()); assertEquals("disabledUser", ((User) newUser).getDisabledReason()); Node n = s.getNode(newUser.getPath()); assertTrue(n.isNew()); assertTrue(n.getParent().isSame(target)); assertEquals("t", n.getName()); s.save();
@Test public void testAdminUser() throws Exception { Authorizable a = userMgr.getAuthorizable(UserUtil.getAdminId(config)); assertFalse(a.isGroup()); User admin = (User) a; assertTrue(admin.isAdmin()); assertTrue(admin.getPrincipal() instanceof AdminPrincipal); assertTrue(admin.getPrincipal() instanceof TreeBasedPrincipal); assertEquals(admin.getID(), admin.getPrincipal().getName()); }
public void testGetUserAfterCreation() throws RepositoryException, NotExecutableException { Principal p = getTestPrincipal(); String uid = p.getName(); User user = createUser(uid, buildPassword(uid)); createdUsers.add(user); assertNotNull(userMgr.getAuthorizable(user.getID())); assertNotNull(userMgr.getAuthorizable(p)); }
@Test public void testAccessDisabledUser() throws Exception { user.disable("readonly user is disabled!"); superuser.save(); // user must still be retrievable from user manager assertNotNull(getUserManager(superuser).getAuthorizable(user.getID())); // ... and from principal manager as well assertTrue(((JackrabbitSession) superuser).getPrincipalManager().hasPrincipal(user.getPrincipal().getName())); }
@Override protected void setUp() throws Exception { super.setUp(); Principal p = getTestPrincipal(); String pw = buildPassword(p); creds = new SimpleCredentials(p.getName(), pw.toCharArray()); User u = userMgr.createUser(p.getName(), pw); save(superuser); uID = u.getID(); uSession = getHelper().getRepository().login(creds); uMgr = getUserManager(uSession); }
@Test public void testAccessPrincipalOfDisabledUser() throws Exception { user.disable("readonly user is disabled!"); superuser.save(); Principal principal = user.getPrincipal(); assertTrue(((JackrabbitSession) superuser).getPrincipalManager().hasPrincipal(principal.getName())); assertEquals(principal, ((JackrabbitSession) superuser).getPrincipalManager().getPrincipal(principal.getName())); }
@Test public void testFindAuthorizable() throws Exception { user = createUser(uid); Iterator<Authorizable> iterator = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, user.getPrincipal().getName()); assertTrue(iterator.hasNext()); Authorizable authorizable = iterator.next(); assertNotNull(authorizable); assertFalse(authorizable.isGroup()); assertTrue(((User) authorizable).isSystemUser()); assertFalse(iterator.hasNext()); }
@Test public void testGetPrincipalExternalUser() throws Exception { UserManager userManager = getUserManager(root); // synced by principal-sync-ctx User syncedUser = userManager.getAuthorizable(USER_ID, User.class); assertNull(principalProvider.getPrincipal(syncedUser.getPrincipal().getName())); // synced by default-sync-ctx syncedUser = userManager.getAuthorizable(TestIdentityProvider.ID_SECOND_USER, User.class); assertNull(principalProvider.getPrincipal(syncedUser.getPrincipal().getName())); }
private String getYetAnotherID() throws RepositoryException, NotExecutableException { if (otherUID2 == null) { // create a third user Principal p = getTestPrincipal(); otherUID2 = userMgr.createUser(p.getName(), buildPassword(p)).getID(); save(superuser); } return otherUID2; }
@Test public void testCreateUser() throws RepositoryException, NotExecutableException { Principal p = getTestPrincipal(); String uid = p.getName(); User user = createUser(uid, "pw"); createdUsers.add(user); assertNotNull(user.getID()); assertEquals(p.getName(), user.getPrincipal().getName()); }
@Test public void testCreateUserWithRelativePath() throws RepositoryException, NotExecutableException { Principal p = getTestPrincipal(); String uid = p.getName(); User user = createUser(uid, "pw", p, "any/path"); createdUsers.add(user); assertNotNull(user.getID()); assertTrue(user.getPath().contains("any/path")); }
@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 testUserMemberOfContainsEveryone() throws Exception { User testUser = getTestUser(superuser); boolean memberOfEveryone = false; Iterator<Group> groups = testUser.memberOf(); while (groups.hasNext() && !memberOfEveryone) { Group g = groups.next(); memberOfEveryone = (EveryonePrincipal.NAME.equals(g.getPrincipal().getName())); } assertTrue(memberOfEveryone); } }
@Test public void testWriteOnParentWithNoReadePriv() throws Exception { Node a = superuser.getNode(path).addNode("a"); allow(path, testUser.getPrincipal(), readWritePrivileges); deny(a.getPath(), testUser.getPrincipal(), readPrivileges); superuser.save(); testSession.getNode(path).addNode("a"); }