use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.
the class GroupImportTest method testImportGroupMembersFromNodes.
@Test
public void testImportGroupMembersFromNodes() throws Exception {
List<String> createdUsers = new LinkedList<String>();
Session s = getImportSession();
UserManager uMgr = getUserManager();
try {
String[] users = { "angi", "adi", "hansi", "lisi", "luzi", "susi", "pipi", "hari", "gabi", "eddi", "debbi", "cati", "admin", "anonymous" };
for (String user : users) {
if (uMgr.getAuthorizable(user) == null) {
uMgr.createUser(user, user);
createdUsers.add(user);
}
}
if (!uMgr.isAutoSave()) {
s.save();
}
doImport(getTargetPath(), "GroupImportTest-testImportGroupMembersFromNodes.xml");
if (!uMgr.isAutoSave()) {
s.save();
}
Authorizable aShrimps = uMgr.getAuthorizable("shrimps");
assertNotNull("Shrimps authorizable must exist", aShrimps);
assertTrue("Shrimps authorizable must be a group", aShrimps.isGroup());
Group gShrimps = (Group) aShrimps;
for (String user : users) {
assertTrue(user + " should be member of " + gShrimps, gShrimps.isMember(uMgr.getAuthorizable(user)));
}
} finally {
for (String user : createdUsers) {
Authorizable a = uMgr.getAuthorizable(user);
if (a != null && !a.isGroup()) {
a.remove();
}
}
for (NodeIterator it = s.getNode(getTargetPath()).getNodes(); it.hasNext(); ) {
Node n = it.nextNode();
if (!n.getDefinition().isProtected()) {
n.remove();
}
}
s.save();
}
}
use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.
the class UserInitializerTest method testAnonymousConfiguration.
/**
* @since OAK 1.0 The anonymous user is optional.
*/
@Test
public void testAnonymousConfiguration() throws Exception {
Map<String, Object> userParams = new HashMap();
userParams.put(UserConstants.PARAM_ANONYMOUS_ID, "");
ConfigurationParameters params = ConfigurationParameters.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams));
SecurityProvider sp = new SecurityProviderImpl(params);
final ContentRepository repo = new Oak().with(new InitialContent()).with(new PropertyIndexEditorProvider()).with(new PropertyIndexProvider()).with(new TypeEditorProvider()).with(sp).createContentRepository();
ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {
@Override
public ContentSession run() throws Exception {
return repo.login(null, null);
}
});
try {
Root root = cs.getLatestRoot();
UserConfiguration uc = sp.getConfiguration(UserConfiguration.class);
UserManager umgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
Authorizable anonymous = umgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
assertNull(anonymous);
} finally {
cs.close();
}
// login as admin should fail
ContentSession anonymousSession = null;
try {
anonymousSession = repo.login(new GuestCredentials(), null);
fail();
} catch (LoginException e) {
//success
} finally {
if (anonymousSession != null) {
anonymousSession.close();
}
}
}
use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.
the class UserValidatorTest method testRemoveAdminUser.
@Test
public void testRemoveAdminUser() throws Exception {
try {
String adminId = getConfig().getConfigValue(PARAM_ADMIN_ID, DEFAULT_ADMIN_ID);
UserManager userMgr = getUserManager(root);
Authorizable admin = userMgr.getAuthorizable(adminId);
if (admin == null) {
admin = userMgr.createUser(adminId, adminId);
root.commit();
}
root.getTree(admin.getPath()).remove();
root.commit();
fail("Admin user cannot be removed");
} catch (CommitFailedException e) {
// success
} finally {
root.refresh();
}
}
use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.
the class AccessControlActionTest method testAccessControlAction.
@Test
public void testAccessControlAction() throws Exception {
UserManager userMgr = getUserManager(root);
Group gr = null;
try {
gr = userMgr.createGroup("actionTestGroup");
root.commit();
assertAcAction(gr, PrivilegeConstants.JCR_READ);
} finally {
root.refresh();
if (gr != null) {
gr.remove();
}
root.commit();
}
}
use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.
the class UserValidatorTest method testRemoveAdminUserFolder.
@Test
public void testRemoveAdminUserFolder() throws Exception {
try {
String adminId = getConfig().getConfigValue(PARAM_ADMIN_ID, DEFAULT_ADMIN_ID);
UserManager userMgr = getUserManager(root);
Authorizable admin = userMgr.getAuthorizable(adminId);
if (admin == null) {
admin = userMgr.createUser(adminId, adminId);
root.commit();
}
root.getTree(admin.getPath()).getParent().remove();
root.commit();
fail("Admin user cannot be removed");
} catch (CommitFailedException e) {
// success
} finally {
root.refresh();
}
}
Aggregations