use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class UserAccessControlProviderTest method testNodeRemovedForPrincipal.
public void testNodeRemovedForPrincipal() throws RepositoryException, NotExecutableException {
Principal testPrincipal = getTestPrincipal();
final User u = getUserManager(superuser).createUser(testPrincipal.getName(), "pw");
save(superuser);
Path rootPath = ((SessionImpl) s).getQPath("/");
CompiledPermissions cp = null;
try {
Set<Principal> principals = Collections.singleton(u.getPrincipal());
cp = provider.compilePermissions(principals);
assertTrue(cp.canReadAll());
assertTrue(cp.grants(rootPath, Permission.READ));
assertNotSame(CompiledPermissions.NO_PERMISSION, cp);
} finally {
// remove the user to assert that the path doesn't point to an
// existing node any more -> userNode cannot be resolved any more -> permissions denied.
u.remove();
save(superuser);
if (cp != null) {
assertFalse(cp.canReadAll());
assertFalse(cp.grants(rootPath, Permission.READ));
assertTrue(cp.getPrivilegeSet(rootPath).isEmpty());
}
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class UserManagerImplTest method testEnforceAuthorizableFolderHierarchy.
/**
* Implementation specific test: user(/groups) cannot be nested.
* @throws RepositoryException
*/
public void testEnforceAuthorizableFolderHierarchy() throws RepositoryException {
AuthorizableImpl authImpl = (AuthorizableImpl) userMgr.getAuthorizable(superuser.getUserID());
Node userNode = authImpl.getNode();
SessionImpl sImpl = (SessionImpl) userNode.getSession();
Node folder = userNode.addNode("folder", sImpl.getJCRName(UserConstants.NT_REP_AUTHORIZABLE_FOLDER));
String path = folder.getPath();
try {
// authNode - authFolder -> create User
Authorizable a = null;
try {
Principal p = getTestPrincipal();
a = userMgr.createUser(p.getName(), p.getName(), p, path);
fail("Users may not be nested.");
} catch (RepositoryException e) {
// success
} finally {
if (a != null) {
a.remove();
}
}
} finally {
if (sImpl.nodeExists(path)) {
folder.remove();
sImpl.save();
}
}
Node someContent = userNode.addNode("mystuff", "nt:unstructured");
path = someContent.getPath();
try {
// authNode - anyNode -> create User
Authorizable a = null;
try {
Principal p = getTestPrincipal();
a = userMgr.createUser(p.getName(), p.getName(), p, someContent.getPath());
fail("Users may not be nested.");
} catch (RepositoryException e) {
// success
} finally {
if (a != null) {
a.remove();
a = null;
}
}
// authNode - anyNode - authFolder -> create User
if (!sImpl.nodeExists(path)) {
someContent = userNode.addNode("mystuff", "nt:unstructured");
}
folder = someContent.addNode("folder", sImpl.getJCRName(UserConstants.NT_REP_AUTHORIZABLE_FOLDER));
// this time save node structure
sImpl.save();
try {
Principal p = getTestPrincipal();
a = userMgr.createUser(p.getName(), p.getName(), p, folder.getPath());
fail("Users may not be nested.");
} catch (RepositoryException e) {
// success
} finally {
if (a != null) {
a.remove();
}
}
} finally {
if (sImpl.nodeExists(path)) {
someContent.remove();
sImpl.save();
}
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class UserImporterTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
if (!(superuser instanceof SessionImpl)) {
throw new NotExecutableException("SessionImpl expected.");
}
sImpl = (SessionImpl) superuser;
UserManager umgr = sImpl.getUserManager();
if (umgr.isAutoSave()) {
try {
umgr.autoSave(false);
} catch (RepositoryException e) {
// -> test not executable
throw new NotExecutableException("Expected user manager that can have its autosave behavior changed to false.");
}
}
this.umgr = (UserManagerImpl) umgr;
// avoid collision with testing a-folders that may have been created
// with another test (but not removed as user/groups got removed)
String path = this.umgr.getUsersPath() + "/t";
if (sImpl.nodeExists(path)) {
sImpl.getNode(path).remove();
}
path = this.umgr.getGroupsPath() + "/g";
if (sImpl.nodeExists(path)) {
sImpl.getNode(path).remove();
}
sImpl.save();
// make sure the target node for group-import exists
Authorizable administrators = umgr.getAuthorizable(SecurityConstants.ADMINISTRATORS_NAME);
if (administrators == null) {
groupIdToRemove = umgr.createGroup(new PrincipalImpl(SecurityConstants.ADMINISTRATORS_NAME)).getID();
sImpl.save();
} else if (!administrators.isGroup()) {
throw new NotExecutableException("Expected " + administrators.getID() + " to be a group.");
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class UserManagerImplTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
if (!(userMgr instanceof UserManagerImpl)) {
throw new NotExecutableException("UserManagerImpl expected -> cannot perform test.");
}
NameResolver resolver = (SessionImpl) superuser;
pPrincipalName = resolver.getJCRName(UserConstants.P_PRINCIPAL_NAME);
}
use of org.apache.jackrabbit.core.SessionImpl in project pentaho-platform by pentaho.
the class PentahoEntry method readEntries.
static List<PentahoEntry> readEntries(NodeImpl aclNode, String path) throws RepositoryException {
if (aclNode == null || !NT_REP_ACL.equals(aclNode.getPrimaryNodeTypeName())) {
throw new IllegalArgumentException("Node must be of type 'rep:ACL'");
}
SessionImpl sImpl = (SessionImpl) aclNode.getSession();
PrincipalManager principalMgr = sImpl.getPrincipalManager();
PrivilegeManagerImpl privilegeMgr = (PrivilegeManagerImpl) ((JackrabbitWorkspace) sImpl.getWorkspace()).getPrivilegeManager();
NodeId nodeId = aclNode.getParentId();
List<PentahoEntry> entries = new ArrayList<PentahoEntry>();
// load the entries:
NodeIterator itr = aclNode.getNodes();
while (itr.hasNext()) {
NodeImpl aceNode = (NodeImpl) itr.nextNode();
try {
String principalName = aceNode.getProperty(P_PRINCIPAL_NAME).getString();
boolean isGroupEntry = false;
Principal princ = principalMgr.getPrincipal(principalName);
if (princ != null) {
isGroupEntry = (princ instanceof Group);
}
InternalValue[] privValues = aceNode.getProperty(P_PRIVILEGES).internalGetValues();
Name[] privNames = new Name[privValues.length];
for (int i = 0; i < privValues.length; i++) {
privNames[i] = privValues[i].getName();
}
Value globValue = null;
if (aceNode.hasProperty(P_GLOB)) {
globValue = aceNode.getProperty(P_GLOB).getValue();
}
boolean isAllow = NT_REP_GRANT_ACE.equals(aceNode.getPrimaryNodeTypeName());
PentahoEntry ace = new PentahoEntry(nodeId, principalName, isGroupEntry, privilegeMgr.getBits(privNames), isAllow, path, globValue);
entries.add(ace);
} catch (RepositoryException e) {
log.debug("Failed to build ACE from content. {}", e.getMessage());
}
}
return entries;
}
Aggregations