public void testGetAuthorizableByPrincipal() throws RepositoryException, NotExecutableException { Authorizable auth = null; Set<Principal> principals = getPrincipalSetFromSession(superuser); for (Iterator<Principal> it = principals.iterator(); it.hasNext() && auth == null;) { Principal p = it.next(); auth = userMgr.getAuthorizable(p); } assertNotNull("At least one of the Sessions principal must be a known authorizable to the UserManager", auth); }
public void testGetNonExistingAuthorizableByIdAndType() throws NotExecutableException, RepositoryException { Authorizable auth = userMgr.getAuthorizable("nonExistingAuthorizable", User.class); assertNull(auth); auth = userMgr.getAuthorizable("nonExistingAuthorizable", Authorizable.class); assertNull(auth); }
public void testGetAuthorizableById() throws RepositoryException, NotExecutableException { Authorizable auth = null; for (Principal principal : getPrincipalSetFromSession(superuser)) { Principal p = principal; auth = userMgr.getAuthorizable(p); if (auth != null) { Authorizable authByID = userMgr.getAuthorizable(auth.getID()); assertEquals("Equal ID expected", auth.getID(), authByID.getID()); } } }
public void testGetAuthorizableByIdAndWrongType() throws NotExecutableException, RepositoryException { for (Principal principal : getPrincipalSetFromSession(superuser)) { Principal p = principal; Authorizable auth = userMgr.getAuthorizable(p); if (auth != null) { Class<? extends Authorizable> otherType = auth.isGroup() ? User.class : Group.class; try { userMgr.getAuthorizable(auth.getID(), otherType); fail("Wrong Authorizable type is not detected."); } catch (AuthorizableTypeException e) { // success } } } }
public void testGetAuthorizableByPath() throws RepositoryException, NotExecutableException { String uid = superuser.getUserID(); Authorizable a = userMgr.getAuthorizable(uid); if (a == null) { throw new NotExecutableException(); } try { String path = a.getPath(); Authorizable a2 = userMgr.getAuthorizableByPath(path); assertNotNull(a2); assertEquals(a.getID(), a2.getID()); } catch (UnsupportedRepositoryOperationException e) { throw new NotExecutableException(); } }
@Test public void testFindUserWithSpecialCharIdByPrincipalName2() throws RepositoryException { List<String> ids = Arrays.asList("]"); for (String id : ids) { User user = null; try { user = userMgr.createUser(id, "pw"); superuser.save(); boolean found = false; Iterator<Authorizable> it = userMgr.findAuthorizables("rep:principalName", id, UserManager.SEARCH_TYPE_USER); while (it.hasNext() && !found) { Authorizable a = it.next(); found = id.equals(a.getID()); } assertTrue(found); } finally { if (user != null) { user.remove(); superuser.save(); } } } }
public void testGetAuthorizableByNullType() throws Exception { String uid = superuser.getUserID(); Authorizable auth = userMgr.getAuthorizable(uid); if (auth != null) { try { userMgr.getAuthorizable(uid, null); fail("Null Authorizable type is not detected."); } catch (AuthorizableTypeException e) { // success } } }
public void testGetAuthorizableByIdAndType() throws NotExecutableException, RepositoryException { for (Principal principal : getPrincipalSetFromSession(superuser)) { Principal p = principal; Authorizable a = userMgr.getAuthorizable(p); if (a != null) { Authorizable authorizable = userMgr.getAuthorizable(a.getID(), a.getClass()); assertEquals("Equal ID expected", a.getID(), authorizable.getID()); authorizable = userMgr.getAuthorizable(a.getID(), Authorizable.class); assertEquals("Equal ID expected", a.getID(), authorizable.getID()); } } }
@Test public void testFindUserWithSpecialCharIdByPrincipalName() throws RepositoryException { List<String> ids = Arrays.asList("'", Text.escapeIllegalJcrChars("']"), Text.escape("']")); for (String id : ids) { User user = null; try { user = userMgr.createUser(id, "pw"); superuser.save(); boolean found = false; Iterator<Authorizable> it = userMgr.findAuthorizables("rep:principalName", id, UserManager.SEARCH_TYPE_USER); while (it.hasNext() && !found) { Authorizable a = it.next(); found = id.equals(a.getID()); } assertTrue(found); } finally { if (user != null) { user.remove(); superuser.save(); } } } }
@Test public void testQueryUserWithSpecialCharId() throws Exception { List<String> ids = Arrays.asList("'", "]"); for (String id : ids) { User user = null; try { user = userMgr.createUser(id, "pw"); superuser.save(); boolean found = false; String query = "{\"condition\":[{\"named\":\"" + id + "\"}]}"; AuthorizableQueryManager queryManager = new AuthorizableQueryManager(userMgr, superuser.getValueFactory()); Iterator<Authorizable> it = queryManager.execute(query); while (it.hasNext() && !found) { Authorizable a = it.next(); found = id.equals(a.getID()); } assertTrue(found); } finally { if (user != null) { user.remove(); superuser.save(); } } } }
public void testGetNonExistingAuthorizableByNullType() throws Exception { assertNull(userMgr.getAuthorizable("nonExistingAuthorizable", null)); }