use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class AccessControlImporter method init.
//----------------------------------------------< ProtectedItemImporter >---
@Override
public boolean init(@Nonnull Session session, @Nonnull Root root, @Nonnull NamePathMapper namePathMapper, boolean isWorkspaceImport, int uuidBehavior, @Nonnull ReferenceChangeTracker referenceTracker, @Nonnull SecurityProvider securityProvider) {
if (initialized) {
throw new IllegalStateException("Already initialized");
}
if (!(session instanceof JackrabbitSession)) {
return false;
}
try {
AuthorizationConfiguration config = securityProvider.getConfiguration(AuthorizationConfiguration.class);
importBehavior = Util.getImportBehavior(config);
if (isWorkspaceImport) {
acMgr = config.getAccessControlManager(root, namePathMapper);
PrincipalConfiguration pConfig = securityProvider.getConfiguration(PrincipalConfiguration.class);
principalManager = pConfig.getPrincipalManager(root, namePathMapper);
} else {
acMgr = session.getAccessControlManager();
principalManager = ((JackrabbitSession) session).getPrincipalManager();
}
ntMgr = ReadOnlyNodeTypeManager.getInstance(root, namePathMapper);
initialized = true;
} catch (RepositoryException e) {
log.warn("Error while initializing access control importer", e);
}
return initialized;
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testUsersArePerWorkspace.
public void testUsersArePerWorkspace() throws Exception {
String altWsp = getAlternativeWorkspaceName();
if (altWsp == null) {
throw new NotExecutableException();
}
Session s = getHelper().getSuperuserSession(altWsp);
User u = null;
try {
// other users created in the default workspace...
u = ((JackrabbitSession) superuser).getUserManager().createUser("testUser", "testUser");
superuser.save();
// ... must not be present in the alternate-workspace
UserManager umgr = ((JackrabbitSession) s).getUserManager();
assertNull(umgr.getAuthorizable("testUser"));
try {
Session us = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()), altWsp);
us.logout();
fail("testUser must not be able to login to a workspace without this user.");
} catch (LoginException e) {
// success
}
} finally {
s.logout();
if (u != null) {
u.remove();
superuser.save();
}
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testUpdateUser.
public void testUpdateUser() throws NotExecutableException, RepositoryException {
// create the same use in 2 different workspace must make the 'corresponding'
// and updating must succeed
String altWsp = getAlternativeWorkspaceName();
if (altWsp == null) {
throw new NotExecutableException();
}
UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
Session s = getHelper().getSuperuserSession(altWsp);
User u = null;
try {
// other users created in the default workspace...
u = uMgr.createUser("testUser", "testUser");
superuser.save();
String userPath = null;
if (u.getPrincipal() instanceof ItemBasedPrincipal) {
userPath = ((ItemBasedPrincipal) u.getPrincipal()).getPath();
assertTrue(superuser.nodeExists(userPath));
} else {
throw new NotExecutableException();
}
// ... must not be present in the alternate-workspace
UserManager umgr = ((JackrabbitSession) s).getUserManager();
assertNull(umgr.getAuthorizable("testUser"));
assertFalse(s.nodeExists(userPath));
User u2 = umgr.createUser("testUser", "testUser");
s.save();
assertTrue(s.nodeExists(userPath));
Value value = superuser.getValueFactory().createValue("anyValue");
u.setProperty(propertyName1, value);
superuser.save();
// no automatic sync.
assertFalse(u2.hasProperty(propertyName1));
// update nodes
Node n2 = s.getNode(userPath);
n2.update(superuser.getWorkspace().getName());
// now the value must be visible
assertTrue(u2.hasProperty(propertyName1));
assertEquals(value.getString(), u2.getProperty(propertyName1)[0].getString());
} finally {
// remove the test user in the destination workspace
Authorizable dest = ((JackrabbitSession) s).getUserManager().getAuthorizable("testUser");
if (dest != null) {
dest.remove();
s.save();
}
// logout the session to the destination workspace
s.logout();
if (u != null) {
// and remove it in the default workspace as well
u.remove();
superuser.save();
}
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testSystemUsersAreSaved.
public void testSystemUsersAreSaved() throws Exception {
String adminId = ((UserPerWorkspaceSecurityManager) secMgr).adminId;
UserManager umgr = ((JackrabbitSession) superuser).getUserManager();
Principal p = umgr.getAuthorizable(adminId).getPrincipal();
if (p instanceof ItemBasedPrincipal) {
Item item = superuser.getItem(((ItemBasedPrincipal) p).getPath());
assertFalse(item.isNew());
assertFalse(item.isModified());
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testCloneUser.
public void testCloneUser() throws Exception {
String altWsp = getAlternativeWorkspaceName();
if (altWsp == null) {
throw new NotExecutableException();
}
UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
Session s = getHelper().getSuperuserSession(altWsp);
User u = null;
try {
// other users created in the default workspace...
u = uMgr.createUser("testUser", "testUser");
superuser.save();
String userPath = null;
if (u.getPrincipal() instanceof ItemBasedPrincipal) {
userPath = ((ItemBasedPrincipal) u.getPrincipal()).getPath();
assertTrue(superuser.nodeExists(userPath));
} else {
throw new NotExecutableException();
}
// ... must not be present in the alternate-workspace
UserManager umgr = ((JackrabbitSession) s).getUserManager();
assertNull(umgr.getAuthorizable("testUser"));
assertFalse(s.nodeExists(userPath));
String clonePath = userPath;
String parentPath = Text.getRelativeParent(clonePath, 1);
while (!s.nodeExists(parentPath)) {
clonePath = parentPath;
parentPath = Text.getRelativeParent(parentPath, 1);
}
// clone the user into the second workspace
s.getWorkspace().clone(superuser.getWorkspace().getName(), clonePath, clonePath, true);
// ... now the user must be visible
assertNotNull(umgr.getAuthorizable("testUser"));
if (userPath != null) {
assertTrue(s.nodeExists(userPath));
}
// ... and able to login to that workspace
Session us = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()), altWsp);
us.logout();
} finally {
// remove the test user in the second workspace
Authorizable dest = ((JackrabbitSession) s).getUserManager().getAuthorizable("testUser");
if (dest != null) {
dest.remove();
s.save();
}
// logout the session
s.logout();
if (u != null) {
// remove as well in the first workspace
u.remove();
superuser.save();
}
}
}
Aggregations