Refine search
private void run(Repository repository) throws RepositoryException { Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray())); AtomicInteger count = new AtomicInteger(); long startTime = System.currentTimeMillis(); Node testRoot = session.getRootNode().addNode("r" + AbstractTest.TEST_ID); createNodes(testRoot, 20, 6, count, startTime); long duration = System.currentTimeMillis() - startTime; System.out.format( "Created %d nodes in %d seconds (%.2fms/node)%n", count.get(), duration / 1000, (double) duration / count.get()); }
private boolean credentialsEqual(final Credentials cred, final Credentials compare) { if (cred instanceof SimpleCredentials && compare instanceof SimpleCredentials) { // SimpleCredentials does *not* override hashcode or equals! SimpleCredentials sc = (SimpleCredentials)cred; if (!sc.getUserID().equals(((SimpleCredentials)compare).getUserID())) { return false; } return Arrays.equals(sc.getPassword(), ((SimpleCredentials)compare).getPassword()); } // we can only check on object equality now return cred == compare; }
public WorkflowManagerImpl(Session session) throws RepositoryException { this.userSession = session; SimpleCredentials workflowuser = new SimpleCredentials("workflowuser", new char[]{}); workflowuser.setAttribute(NO_SYSTEM_IMPERSONATION, Boolean.TRUE); this.workflowSession = session.impersonate(workflowuser); ((HippoSession)workflowSession).disableVirtualLayers(); configurationId = session.getRootNode().getNode(CONFIGURATION_PATH + "/" + WORKFLOWS_PATH).getIdentifier(); workflowLogger = new WorkflowLogger(workflowSession); }
public ConstantCredentialsStrategy( final String userID, final String preAuthenticationToken ) { Assert.hasText( userID ); Assert.hasText( preAuthenticationToken ); SimpleCredentials creds = new SimpleCredentials( userID, PASSWORD ); creds.setAttribute( ATTR_PRE_AUTHENTICATION_TOKEN, preAuthenticationToken ); this.credentials = creds; }
/** * Return the credentials attributes. */ private Map<String, Object> getAttributeMap(SimpleCredentials creds) { HashMap<String, Object> map = new HashMap<String, Object>(); String[] keys = creds.getAttributeNames(); for (int i = 0; i < keys.length; i++) { map.put(keys[i], creds.getAttribute(keys[i])); } return map; }
@Override protected void setUp() throws Exception { super.setUp(); SimpleCredentials creds = new SimpleCredentials("u", "u".toCharArray()); UserManager uMgr = ((JackrabbitSession) superuser).getUserManager(); User u = uMgr.createUser(creds.getUserID(), creds.getUserID()); Group g = uMgr.createGroup("g"); g.addMember(u); uPrincipal = u.getPrincipal(); gPrincipal = g.getPrincipal(); Node n = superuser.getNode(testRoot).addNode(nodeName1); testPath = n.getPath(); Property p = n.setProperty(propertyName1, "value"); propPath = p.getPath(); Privilege[] privs = AccessControlUtils.privilegesFromNames(superuser, Privilege.JCR_VERSION_MANAGEMENT, Privilege.JCR_ADD_CHILD_NODES, Privilege.JCR_MODIFY_PROPERTIES); AccessControlUtils.addAccessControlEntry(superuser, n.getPath(), gPrincipal, privs, true); AccessControlUtils.addAccessControlEntry(superuser, n.getPath(), uPrincipal, new String[] {Privilege.JCR_VERSION_MANAGEMENT}, false); Node child = n.addNode(nodeName2); childPath = child.getPath(); superuser.save(); userSession = getHelper().getRepository().login(creds); // NOTE the following precondition defined by the test-setup! assertTrue(userSession.nodeExists(testPath)); assertTrue(userSession.nodeExists(childPath)); }
@Test public void testNewUserCanLogin() throws RepositoryException, NotExecutableException { String uid = createUserId(); User u = null; Session s = null; try { u = userMgr.createUser(uid, "pw"); superuser.save(); Credentials creds = new SimpleCredentials(uid, "pw".toCharArray()); s = superuser.getRepository().login(creds); } finally { if (u != null) { u.remove(); superuser.save(); } if (s != null) { s.logout(); } } }
@Test public void testLoginAfterChangePassword() throws RepositoryException { user.changePassword("changed"); superuser.save(); // make sure the user can login with the new pw Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(), "changed".toCharArray())); s.logout(); }
public static void main(String[] args) throws Exception { Repository repository = new TransientRepository(); Session session = repository.login( new SimpleCredentials("username", "password".toCharArray())); try { Node root = session.getRootNode(); System.out.println(root.getPath()); } finally { session.logout(); } }
@Test public void testUserIDFromSession() throws RepositoryException, NotExecutableException { User u = null; Session uSession = null; try { String uid = createUserId(); u = userMgr.createUser(uid, "pw"); superuser.save(); uSession = superuser.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray())); assertEquals(u.getID(), uSession.getUserID()); } finally { if (uSession != null) { uSession.logout(); } if (u != null) { u.remove(); superuser.save(); } } }
private void basicCrudTest(Repository repository) throws RepositoryException { Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray())); Node rootNode = session.getRootNode(); Node child = JcrUtils.getOrAddNode(rootNode, "child", "oak:Unstructured"); child.setProperty("foo3", "bar3"); session.logout(); System.out.println("Basic test passed"); }
@Override protected void beforeSuite() throws Exception { long start = System.currentTimeMillis(); admin = loginWriter(); userManager = ((JackrabbitSession) admin).getUserManager(); Principal userPrincipal = userManager.createUser(TEST_USER_ID, TEST_USER_ID).getPrincipal(); AccessControlManager acm = admin.getAccessControlManager(); JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acm, "/"); acl.addEntry(userPrincipal, AccessControlUtils.privilegesFromNames(acm, PrivilegeConstants.JCR_READ), true); acm.setPolicy("/", acl); Node a = admin.getRootNode().addNode(ROOT_NODE_NAME, "nt:folder"); for (int i = 1; i < 10000; i++) { a.addNode("node" + i, "nt:folder"); acl = AccessControlUtils.getAccessControlList(acm, ROOT_PATH + "/node" + i); acl.addEntry(userPrincipal, AccessControlUtils.privilegesFromNames(acm, PrivilegeConstants.JCR_READ), true); acm.setPolicy(ROOT_PATH + "/node" + i, acl); } admin.save(); reader = login(new SimpleCredentials(TEST_USER_ID, TEST_USER_ID.toCharArray())); long end = System.currentTimeMillis(); System.out.println("setup time " + (end - start)); }
public void testAdvancedImpersonationTest() throws RepositoryException { // EXERCISE: change the permission setup such that the test-user is allowed to make himself an impersonator of 'another' user. Session testSession = superuser.getRepository().login(ExerciseUtility.getTestCredentials(testUser.getID())); sessionList.add(testSession); UserManager uMgr = ((JackrabbitSession) testSession).getUserManager(); User another = uMgr.getAuthorizable(anotherUser.getID(), User.class); assertNotNull(another); Principal princ = uMgr.getAuthorizable(testUser.getID()).getPrincipal(); another.getImpersonation().grantImpersonation(princ); testSession.save(); testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0])).logout(); // EXERCISE: change the impersonation of 'anotherUser' again such that the impersonate call fails // EXERCISE: withouth changing the permission setup. what API calls do you have at hand? try { Session s = testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0])); sessionList.add(s); fail("Test user must no longer be able to edit the impersonation of the test user"); } catch (LoginException e) { // success } } }
public void testTransientUserCannotLogin() throws RepositoryException, UnsupportedRepositoryOperationException { Session s = null; String uid = "testUser"; UserManager umgr = ((JackrabbitSession) superuser).getUserManager(); umgr.autoSave(false); try { // other users created in the default workspace... umgr.createUser(uid, uid); // the new user must be able to login to the repo s = getHelper().getRepository().login(new SimpleCredentials(uid, uid.toCharArray())); fail("Non-saved user node -> must not be able to login."); } catch (LoginException e) { // success } finally { if (s != null) { s.logout(); } superuser.refresh(false); Authorizable a = ((JackrabbitSession) superuser).getUserManager().getAuthorizable(uid); if (a != null) { a.remove(); superuser.save(); } umgr.autoSave(true); } } }
@Test public void testEnableUser() throws Exception { user.disable("readonly user is disabled!"); superuser.save(); // enable user again user.disable(null); superuser.save(); assertFalse(user.isDisabled()); assertNull(user.getDisabledReason()); // -> login must succeed again getHelper().getRepository().login(new SimpleCredentials(user.getID(), "pw".toCharArray())).logout(); }
@Override public void before() throws Exception { super.before(); User u = userMgr.createUser(uid, "pw"); adminSession.save(); AccessControlUtils.addAccessControlEntry(adminSession, Text.getRelativeParent(getTargetPath(), 1), u.getPrincipal(), new String[] {Privilege.JCR_ALL}, true); AccessControlUtils.addAccessControlEntry(adminSession, null, u.getPrincipal(), new String[] {PrivilegeConstants.JCR_NAMESPACE_MANAGEMENT}, true); adminSession.save(); testSession = adminSession.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray())); }
@Test public void testLoginDisabledUser() throws Exception { user.disable("readonly user is disabled!"); superuser.save(); // -> login must fail try { Session ss = getHelper().getRepository().login(new SimpleCredentials(user.getID(), "pw".toCharArray())); ss.logout(); fail("A disabled user must not be allowed to login any more"); } catch (LoginException e) { // success } }
public void testImpersonateTestUser() throws RepositoryException { Principal principal = null; // EXERCISE: fill in the correct principal such that the test passes. Impersonation impersonation = anotherUser.getImpersonation(); impersonation.grantImpersonation(principal); superuser.save(); Session testSession = superuser.getRepository().login(ExerciseUtility.getTestCredentials(testUser.getID())); sessionList.add(testSession); Session impersonated = testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0])); sessionList.add(impersonated); assertEquals(anotherUser.getID(), impersonated.getUserID()); }
public void testUnknownUserLogin() throws RepositoryException { String uid = getTestPrincipal().getName(); assertNull(userMgr.getAuthorizable(uid)); try { Session s = superuser.getRepository().login(new SimpleCredentials(uid, uid.toCharArray())); s.logout(); fail("An unknown user should not be allowed to execute the login."); } catch (Exception e) { // ok. } }
@Test public void testImpersonateDisabledUser() throws Exception { user.disable("readonly user is disabled!"); superuser.save(); // -> impersonating this user must fail try { Session ss = superuser.impersonate(new SimpleCredentials(user.getID(), new char[0])); ss.logout(); fail("A disabled user cannot be impersonated any more."); } catch (LoginException e) { // success } }