use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit by apache.
the class AdministratorTest method testAdminNodeCollidingWithAuthorizableFolder.
/**
* Test for collisions that would prevent from recreate the admin user.
* - an intermediate rep:AuthorizableFolder node with the same name
*/
public void testAdminNodeCollidingWithAuthorizableFolder() throws RepositoryException, NotExecutableException {
Authorizable admin = userMgr.getAuthorizable(adminId);
if (admin == null || !(admin instanceof AuthorizableImpl)) {
throw new NotExecutableException();
}
// access the node corresponding to the admin user and remove it
NodeImpl adminNode = ((AuthorizableImpl) admin).getNode();
String adminPath = adminNode.getPath();
String adminNodeName = adminNode.getName();
Node parentNode = adminNode.getParent();
Session s = adminNode.getSession();
adminNode.remove();
// use session obtained from the node as usermgr may point to a dedicated
// system workspace different from the superusers workspace.
s.save();
Session s2 = null;
String collidingPath = null;
try {
// now create a colliding node:
Node n = parentNode.addNode(adminNodeName, "rep:AuthorizableFolder");
collidingPath = n.getPath();
s.save();
// force recreation of admin user.
s2 = getHelper().getSuperuserSession();
admin = userMgr.getAuthorizable(adminId);
assertNotNull(admin);
assertEquals(adminNodeName, ((AuthorizableImpl) admin).getNode().getName());
assertFalse(adminPath.equals(((AuthorizableImpl) admin).getNode().getPath()));
} finally {
if (s2 != null) {
s2.logout();
}
// remove the extra folder and the admin user (created underneath) again.
if (collidingPath != null) {
s.getNode(collidingPath).remove();
s.save();
}
}
}
use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit by apache.
the class DefaultPrincipalProviderTest method testPrincipalCache.
/**
* Test if cache is properly updated.
*
* @throws Exception
*/
public void testPrincipalCache() throws Exception {
Principal testPrincipal = getTestPrincipal();
String testName = testPrincipal.getName();
assertNull(principalProvider.getPrincipal(testName));
// create a user with the given principal name -> cache must be updated.
Authorizable a = userMgr.createUser(testName, "pw");
save(superuser);
try {
assertNotNull(principalProvider.getPrincipal(testName));
} finally {
a.remove();
save(superuser);
}
// after removal -> entry must be removed from the cache.
assertNull(principalProvider.getPrincipal(testName));
// create a group with that name
a = userMgr.createGroup(testPrincipal);
save(superuser);
try {
Principal p = principalProvider.getPrincipal(testName);
assertNotNull(p);
assertTrue(p instanceof java.security.acl.Group);
} finally {
a.remove();
save(superuser);
}
// recreate user again without filling cache with 'null' value
a = userMgr.createUser(testName, "pw");
save(superuser);
try {
Principal p = principalProvider.getPrincipal(testName);
assertNotNull(p);
assertFalse(p instanceof java.security.acl.Group);
} finally {
a.remove();
save(superuser);
}
}
use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit by apache.
the class GroupAdministratorTest method testRemoveMembershipForOwnAuthorizable.
public void testRemoveMembershipForOwnAuthorizable() throws RepositoryException, NotExecutableException {
UserManager umgr = getUserManager(uSession);
Authorizable user = umgr.getAuthorizable(uID);
Group gr = (Group) umgr.getAuthorizable(groupAdmin.getID());
// removing himself from group. should succeed.
assertTrue(gr.removeMember(user));
}
use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit by apache.
the class GroupAdministratorTest method tearDown.
protected void tearDown() throws Exception {
try {
if (uSession != null) {
uSession.logout();
}
} finally {
// remove group member ship
groupAdmin.removeMember(userMgr.getAuthorizable(uID));
// remove all users that have been created
Authorizable a = userMgr.getAuthorizable(otherUID);
if (a != null) {
a.remove();
}
save(superuser);
}
super.tearDown();
}
use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.
the class DefaultSyncContextTest method testSyncProperties.
@Test
public void testSyncProperties() throws Exception {
ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER);
Authorizable a = syncCtx.createUser(externalUser);
// create exact mapping
Map<String, String> mapping = new HashMap();
Map<String, ?> extProps = externalUser.getProperties();
for (String propName : extProps.keySet()) {
mapping.put(propName, propName);
}
syncCtx.syncProperties(externalUser, a, mapping);
for (String propName : extProps.keySet()) {
assertTrue(a.hasProperty(propName));
Object obj = extProps.get(propName);
Value[] vs = a.getProperty(propName);
if (vs.length == 1) {
assertEquals(syncCtx.createValue(obj), a.getProperty(propName)[0]);
} else {
Value[] expected = (obj instanceof Collection) ? syncCtx.createValues((Collection) obj) : syncCtx.createValues(Arrays.asList((Object[]) obj));
assertArrayEquals(expected, a.getProperty(propName));
}
}
}
Aggregations