use of org.apache.jackrabbit.api.security.user.User in project camel by apache.
the class JcrAuthTestBase method createJndiContext.
@Override
protected Context createJndiContext() throws Exception {
Context context = super.createJndiContext();
repository = new TransientRepository(new File(REPO_PATH));
// set up a user to authenticate
SessionImpl session = (SessionImpl) repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
UserManager userManager = session.getUserManager();
User user = (User) userManager.getAuthorizable("test");
if (user == null) {
user = userManager.createUser("test", "quatloos");
}
// set up permissions
String path = session.getRootNode().getPath();
AccessControlManager accessControlManager = session.getAccessControlManager();
AccessControlPolicyIterator acls = accessControlManager.getApplicablePolicies(path);
AccessControlList acl = null;
if (acls.hasNext()) {
acl = (AccessControlList) acls.nextAccessControlPolicy();
} else {
acl = (AccessControlList) accessControlManager.getPolicies(path)[0];
}
acl.addAccessControlEntry(user.getPrincipal(), accessControlManager.getSupportedPrivileges(path));
accessControlManager.setPolicy(path, acl);
session.save();
session.logout();
context.bind("repository", repository);
return context;
}
use of org.apache.jackrabbit.api.security.user.User in project jackrabbit by apache.
the class WriteTest method testEditor2.
public void testEditor2() throws NotExecutableException, RepositoryException {
UserManager uMgr = getUserManager(superuser);
User u = null;
User u2 = null;
try {
u = uMgr.createUser("t", "t");
u2 = uMgr.createUser("tt", "tt", new TestPrincipal("tt"), "t/tt");
if (!uMgr.isAutoSave()) {
superuser.save();
}
Principal p = u.getPrincipal();
Principal p2 = u2.getPrincipal();
if (p instanceof ItemBasedPrincipal && p2 instanceof ItemBasedPrincipal && Text.isDescendant(((ItemBasedPrincipal) p).getPath(), ((ItemBasedPrincipal) p2).getPath())) {
JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) getAccessControlManager(superuser);
JackrabbitAccessControlPolicy[] acls = acMgr.getApplicablePolicies(p2);
acMgr.setPolicy(acls[0].getPath(), acls[0]);
acls = acMgr.getApplicablePolicies(p);
String path = acls[0].getPath();
Node n = superuser.getNode(path);
assertEquals("rep:PrincipalAccessControl", n.getPrimaryNodeType().getName());
} else {
throw new NotExecutableException();
}
} finally {
superuser.refresh(false);
if (u2 != null)
u2.remove();
if (u != null)
u.remove();
if (!uMgr.isAutoSave()) {
superuser.save();
}
}
}
use of org.apache.jackrabbit.api.security.user.User in project jackrabbit by apache.
the class WriteTest method testEditor.
public void testEditor() throws NotExecutableException, RepositoryException {
UserManager uMgr = getUserManager(superuser);
User u = null;
try {
u = uMgr.createUser("t", "t");
if (!uMgr.isAutoSave()) {
superuser.save();
}
Principal p = u.getPrincipal();
JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) getAccessControlManager(superuser);
JackrabbitAccessControlPolicy[] acls = acMgr.getApplicablePolicies(p);
assertEquals(1, acls.length);
assertTrue(acls[0] instanceof ACLTemplate);
// access again
acls = acMgr.getApplicablePolicies(p);
assertEquals(1, acls.length);
assertEquals(1, acMgr.getApplicablePolicies(acls[0].getPath()).getSize());
assertEquals(0, acMgr.getPolicies(p).length);
assertEquals(0, acMgr.getPolicies(acls[0].getPath()).length);
acMgr.setPolicy(acls[0].getPath(), acls[0]);
assertEquals(0, acMgr.getApplicablePolicies(p).length);
assertEquals(1, acMgr.getPolicies(p).length);
assertEquals(1, acMgr.getPolicies(acls[0].getPath()).length);
} finally {
superuser.refresh(false);
if (u != null) {
u.remove();
if (!uMgr.isAutoSave()) {
superuser.save();
}
}
}
}
use of org.apache.jackrabbit.api.security.user.User in project jackrabbit by apache.
the class AuthorizableActionTest method testPasswordAction.
public void testPasswordAction() throws Exception {
User u = null;
try {
TestAction action = new TestAction();
setActions(action);
String uid = getTestPrincipal().getName();
u = impl.createUser(uid, buildPassword(uid));
u.changePassword("pw1");
assertEquals(1, action.called);
u.changePassword("pw2", "pw1");
assertEquals(2, action.called);
} finally {
if (u != null) {
u.remove();
}
save(superuser);
}
}
use of org.apache.jackrabbit.api.security.user.User in project jackrabbit by apache.
the class AuthorizableActionTest method testPasswordValidationActionOnChange.
public void testPasswordValidationActionOnChange() throws Exception {
User u = null;
try {
String uid = getTestPrincipal().getName();
u = impl.createUser(uid, buildPassword(uid));
PasswordValidationAction pwAction = new PasswordValidationAction();
pwAction.setConstraint("abc");
setActions(pwAction);
String hashed = PasswordUtility.buildPasswordHash("abc");
u.changePassword(hashed);
fail("Password change must always enforce password validation.");
} catch (ConstraintViolationException e) {
// success
} finally {
if (u != null) {
u.remove();
}
save(superuser);
}
}
Aggregations