org.apache.jackrabbit.api.security.user.User Java Examples
The following examples show how to use
org.apache.jackrabbit.api.security.user.User.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserServiceImpl.java From publick-sling-blog with Apache License 2.0 | 6 votes |
/** * Get the authorable status of the current user. * * @param session The current session. * @return true if the current user is an admin or author. */ public boolean isAuthorable(Session session) { boolean authorable = false; JackrabbitSession js = (JackrabbitSession)session; try { Group authors = (Group)js.getUserManager().getAuthorizable(PublickConstants.GROUP_ID_AUTHORS); User user = (User)js.getUserManager().getAuthorizable(js.getUserID()); authorable = user.isAdmin() || authors.isMember(user); } catch (RepositoryException e) { LOGGER.error("Could not determine group membership", e); } return authorable; }
Example #2
Source File: ForAuthorizable.java From APM with Apache License 2.0 | 6 votes |
public ActionResult process(final Context context) { ActionResult actionResult = context.createActionResult(); try { if (shouldBeGroup) { Group group = context.getAuthorizableManager().getGroup(id); context.setCurrentAuthorizable(group); actionResult.logMessage("Group with id: " + group.getID() + " set as current authorizable"); } else { User user = context.getAuthorizableManager().getUser(id); context.setCurrentAuthorizable(user); actionResult.logMessage("User with id: " + user.getID() + " set as current authorizable"); } } catch (RepositoryException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; }
Example #3
Source File: TestUserContentPackage.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Test public void installUserA_Profile_Picture() throws RepositoryException, IOException, PackageException { // install default user at package path User userA = installUserA(ImportMode.REPLACE, true, true); String authPath = userA.getPath(); assertPropertyMissing(authPath + "/" + NAME_PROFILE_PROPERTY); // install updated profile JcrPackage pack = packMgr.upload(getStream("/test-packages/test_user_a_profile_picture.zip"), false); assertNotNull(pack); pack.install(getDefaultOptions()); assertProperty(authPath + "/" + NAME_PROFILE_FULLNAME, "Test User"); assertProperty(authPath + "/" + NAME_PROFILE_PROPERTY, "a"); assertNodeExists(authPath + "/" + NAME_PROFILE_PICTURE_NODE); }
Example #4
Source File: TestUserContentPackage.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Test public void installUserA_Profile_Picture_Moved() throws RepositoryException, IOException, PackageException { // install default user at package path User userA = installUserA(ImportMode.UPDATE, false, false); String authPath = userA.getPath(); assertPropertyMissing(authPath + "/" + NAME_PROFILE_PROPERTY); // install updated profile JcrPackage pack = packMgr.upload(getStream("/test-packages/test_user_a_profile_picture.zip"), false); assertNotNull(pack); pack.install(getDefaultOptions()); assertProperty(authPath + "/" + NAME_PROFILE_FULLNAME, "Test User"); assertProperty(authPath + "/" + NAME_PROFILE_PROPERTY, "a"); assertNodeExists(authPath + "/" + NAME_PROFILE_PICTURE_NODE); }
Example #5
Source File: TestUserContentPackage.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Test public void installUserA_Profile_Moved() throws RepositoryException, IOException, PackageException { // install default user at package path User userA = installUserA(ImportMode.UPDATE, false, false); String authPath = userA.getPath(); assertPropertyMissing(authPath + "/" + NAME_PROFILE_PROPERTY); // install updated profile JcrPackage pack = packMgr.upload(getStream("/test-packages/test_user_a_profile.zip"), false); assertNotNull(pack); pack.install(getDefaultOptions()); assertProperty(authPath + "/" + NAME_PROFILE_FULLNAME, "Test User"); assertProperty(authPath + "/" + NAME_PROFILE_PROPERTY, "a"); }
Example #6
Source File: DestroyUser.java From APM with Apache License 2.0 | 6 votes |
@Override public ActionResult simulate(Context context) throws ActionExecutionException { ActionResult actionResult; try { User user = context.getAuthorizableManager().getUser(userId); context.setCurrentAuthorizable(user); Action removeFromGroups = new RemoveParents(getGroups(user)); ActionResult purgeResult = purge.simulate(context); ActionResult removeFromGroupsResult = removeFromGroups.execute(context); ActionResult removeResult = remove.simulate(context); actionResult = purgeResult.merge(removeFromGroupsResult, removeResult); } catch (RepositoryException | ActionExecutionException e) { actionResult = context.createActionResult(); actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; }
Example #7
Source File: DestroyUser.java From APM with Apache License 2.0 | 6 votes |
@Override public ActionResult execute(Context context) throws ActionExecutionException { ActionResult actionResult; try { User user = context.getAuthorizableManager().getUser(userId); context.setCurrentAuthorizable(user); Action removeFromGroups = new RemoveParents(getGroups(user)); ActionResult purgeResult = purge.execute(context); ActionResult removeFromGroupsResult = removeFromGroups.execute(context); ActionResult removeResult = remove.execute(context); actionResult = purgeResult.merge(removeFromGroupsResult, removeResult); } catch (RepositoryException | ActionExecutionException e) { actionResult = context.createActionResult(); actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; }
Example #8
Source File: TestUserContentPackage.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Test public void installUserA_Profile() throws RepositoryException, IOException, PackageException { // install default user at package path User userA = installUserA(ImportMode.REPLACE, true, true); String authPath = userA.getPath(); assertPropertyMissing(authPath + "/" + NAME_PROFILE_PROPERTY); // install updated profile JcrPackage pack = packMgr.upload(getStream("/test-packages/test_user_a_profile.zip"), false); assertNotNull(pack); pack.install(getDefaultOptions()); assertProperty(authPath + "/" + NAME_PROFILE_FULLNAME, "Test User"); assertProperty(authPath + "/" + NAME_PROFILE_PROPERTY, "a"); }
Example #9
Source File: WCMUse.java From publick-sling-blog with Apache License 2.0 | 6 votes |
/** * Get the authorable status of the current user. * TODO: remove and use UserService * * @return true if the current user is an admin or author. */ public boolean isAuthorable() { boolean authorable = false; JackrabbitSession js = (JackrabbitSession)getSession(); try { Group authors = (Group)js.getUserManager().getAuthorizable(PublickConstants.GROUP_ID_AUTHORS); User user = (User)js.getUserManager().getAuthorizable(js.getUserID()); authorable = user.isAdmin() || authors.isMember(user); } catch (RepositoryException e) { LOGGER.error("Could not determine group membership", e); } return authorable; }
Example #10
Source File: Activator.java From aem-password-reset with Apache License 2.0 | 6 votes |
@Activate public void start(ActivatorConfiguration config) { String[] authorizableIds = config.pwdreset_authorizables(); Session session = null; try { ResourceResolver resolver = resolverFactory.getAdministrativeResourceResolver(null); UserManager userManager = resolver.adaptTo(UserManager.class); session = resolver.adaptTo(Session.class); for (String authorizable : authorizableIds) { try { Authorizable user = userManager.getAuthorizable(authorizable); if (user != null) { ((User) user).changePassword(authorizable); if (!userManager.isAutoSave()) { session.save(); } log.info("Changed the password for {}", authorizable); } else { log.error("Could not find authorizable {}", authorizable); } } catch (RepositoryException repEx) { log.error("Could not change password for {}", authorizable, repEx); } } } catch (LoginException loginEx) { log.error("Could not login to the repository", loginEx); } finally { if(session != null) { session.logout(); } } }
Example #11
Source File: TestGroupMergePackage.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * Installs a package that contains a "test-group" and a "test-user-a" as member of the group. */ @Test public void installGroupA() throws RepositoryException, IOException, PackageException { UserManager mgr = ((JackrabbitSession) admin).getUserManager(); assertNull("test-group must not exist", mgr.getAuthorizable("test-group")); assertNull("test-user-a must not exist", mgr.getAuthorizable("test-user-a")); JcrPackage pack = packMgr.upload(getStream("/test-packages/group_with_a.zip"), false); assertNotNull(pack); pack.install(getDefaultOptions()); // check if group exists Group grp = (Group) mgr.getAuthorizable("test-group"); assertNotNull("test-group must exist", grp); User userA = (User) mgr.getAuthorizable("test-user-a"); assertNotNull("test-user-a must exist", userA); assertTrue("test-user-a is member of test-group", grp.isMember(userA)); }
Example #12
Source File: TestAceOrder.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Override public void setUp() throws Exception { super.setUp(); uMgr = ((JackrabbitSession) admin).getUserManager(); User testuser = uMgr.createUser(NAME_TEST_USER, null); admin.save(); acMgr = admin.getAccessControlManager(); Node tmp = admin.getRootNode().addNode("testroot").addNode("secured"); JackrabbitAccessControlList list = AccessControlUtils.getAccessControlList(acMgr, tmp.getPath()); Privilege[] writePrivilege = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_WRITE); ValueFactory vf = admin.getValueFactory(); Principal everyone = ((JackrabbitSession) admin).getPrincipalManager().getEveryone(); list.addEntry(everyone, writePrivilege, true, ImmutableMap.of("rep:glob", vf.createValue("/foo"))); list.addEntry(testuser.getPrincipal(), writePrivilege, false, ImmutableMap.of("rep:glob", vf.createValue("/foo"))); list.addEntry(everyone, writePrivilege, true, ImmutableMap.of("rep:glob", vf.createValue("/bar"))); acMgr.setPolicy(tmp.getPath(), list); expectedEntries = ImmutableList.copyOf(list.getAccessControlEntries()); admin.refresh(false); }
Example #13
Source File: UserPage.java From sling-samples with Apache License 2.0 | 6 votes |
private static Map<String, String> mapUserProperties(final User user) throws RepositoryException { final Map<String, String> userProperties = new HashMap<>(); final Iterator<String> keys = user.getPropertyNames(); while (keys.hasNext()) { final String key = keys.next(); final Value[] values = user.getProperty(key); if (values != null && values.length > 0) { if (values.length == 1) { userProperties.put(key, values[0].getString()); } else { final String[] strings = new String[values.length]; for (int i = 0; i < values.length; i++) { strings[i] = values[i].getString(); } userProperties.put(key, Arrays.toString(strings)); } } } return userProperties; }
Example #14
Source File: AdminPermissionCheckerTest.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Test public void testAdminGroup() throws Exception { JackrabbitSession jackrabbitSession = (JackrabbitSession) admin; Authorizable admins = jackrabbitSession.getUserManager().getAuthorizable("administrators"); if (admins == null) { admins = jackrabbitSession.getUserManager().createGroup("administrators"); } Group adminsGroup = (Group) admins; User testUser = (User) jackrabbitSession.getUserManager().getAuthorizable(TEST_USER); if (testUser == null) { testUser = jackrabbitSession.getUserManager().createUser(TEST_USER, TEST_USER); } adminsGroup.addMember(testUser); admin.save(); Session session = repository.login(new SimpleCredentials(TEST_USER, TEST_USER.toCharArray())); try { assertTrue( "user \"" + TEST_USER + "\" has been added to administrators group thus should have admin permissions", AdminPermissionChecker.hasAdministrativePermissions(session)); } finally { session.logout(); } }
Example #15
Source File: AdminPermissionCheckerTest.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Test public void testAdditionalAdminGroup() throws Exception { JackrabbitSession jackrabbitSession = (JackrabbitSession) admin; Authorizable admins = jackrabbitSession.getUserManager().getAuthorizable("myadmins"); if (admins == null) { admins = jackrabbitSession.getUserManager().createGroup("myadmins"); } Group adminsGroup = (Group) admins; User testUser = (User) jackrabbitSession.getUserManager().getAuthorizable(TEST_USER); if (testUser == null) { testUser = jackrabbitSession.getUserManager().createUser(TEST_USER, TEST_USER); } adminsGroup.addMember(testUser); admin.save(); Session session = repository.login(new SimpleCredentials(TEST_USER, TEST_USER.toCharArray())); try { assertTrue( "user \"" + TEST_USER + "\" has been added to additional administrators group thus should have admin permissions", AdminPermissionChecker.hasAdministrativePermissions(session, "myadmins")); } finally { session.logout(); } }
Example #16
Source File: ContextImpl.java From APM with Apache License 2.0 | 5 votes |
@Override public Group getCurrentGroup() throws ActionExecutionException { if (getCurrentAuthorizable() instanceof User) { throw new ActionExecutionException("Current authorizable is not a group"); } return (Group) currentAuthorizable; }
Example #17
Source File: ContextImpl.java From APM with Apache License 2.0 | 5 votes |
@Override public User getCurrentUser() throws ActionExecutionException { if (getCurrentAuthorizable() instanceof Group) { throw new ActionExecutionException("Current authorizable is not a user"); } return (User) currentAuthorizable; }
Example #18
Source File: PrincipalBasedTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Override @After public void tearDown() throws Exception { try { User u = userManager.getAuthorizable(SYSTEM_USER_ID, User.class); if (u != null) { u.remove(); admin.save(); } } finally { super.tearDown(); shutdownRepository(); initRepository(); } }
Example #19
Source File: AuthorizableManagerImpl.java From APM with Apache License 2.0 | 5 votes |
@Override public User createSystemUser(String id, String path) throws RepositoryException { User user = userManager.createSystemUser(id, path); existingAuthorizables.put(id, user); removedAuthorizables.remove(id); return user; }
Example #20
Source File: TestUserContentPackage.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void installUserA_Policy_Moved() throws RepositoryException, IOException, PackageException { UserManager mgr = ((JackrabbitSession) admin).getUserManager(); assertNull("test-user-a must not exist", mgr.getAuthorizable(ID_TEST_USER_A)); User u = mgr.createUser(ID_TEST_USER_A, "nonce"); String authPath = u.getPath(); assertNotSame("authorizable path must be different than the one in the package", PARENT_PATH_TEST_USER_A, Text.getRelativeParent(authPath, 1)); // assert that user does not have an ACL setup assertPermissionMissing(authPath, true, new String[]{"jcr:all"}, "everyone", null); JcrPackage pack = packMgr.upload(getStream("/test-packages/test_user_a_policy.zip"), false); assertNotNull(pack); ImportOptions opts = getDefaultOptions(); opts.setImportMode(ImportMode.MERGE); opts.setAccessControlHandling(AccessControlHandling.MERGE_PRESERVE); pack.install(opts); // check if user exists User userA = (User) mgr.getAuthorizable(ID_TEST_USER_A); assertNotNull("test-user-a must exist", userA); authPath = u.getPath(); // assert that user has an ACL setup assertPermission(authPath, true, new String[]{"jcr:all"}, "everyone", null); }
Example #21
Source File: TestUserContentPackage.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void install_user_with_rep_cache(ImportMode mode) throws RepositoryException, IOException, PackageException { UserManager mgr = ((JackrabbitSession) admin).getUserManager(); assertNull("test-user-a must not exist", mgr.getAuthorizable(ID_TEST_USER_A)); // install user package JcrPackage pack = packMgr.upload(getStream("/test-packages/test_user_with_rep_cache.zip"), false); assertNotNull(pack); ImportOptions opts = getDefaultOptions(); opts.setImportMode(mode); pack.install(opts); // check if user exists User userA = (User) mgr.getAuthorizable(ID_TEST_USER_A); assertNotNull("test-user-a must exist", userA); }
Example #22
Source File: TestUserContentPackage.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void install_moved_user_with_rep_cache(ImportMode mode) throws RepositoryException, IOException, PackageException { UserManager mgr = ((JackrabbitSession) admin).getUserManager(); User u = mgr.createUser(ID_TEST_USER_A, ID_TEST_PASSWORD); String newPath = u.getPath() + "_moved"; admin.move(u.getPath(), newPath); admin.save(); Group g = mgr.createGroup(ID_TEST_GROUP_A); g.addMember(u); admin.save(); // login to the repository to generate some rep:cache nodes repository.login(new SimpleCredentials(ID_TEST_USER_A, ID_TEST_PASSWORD.toCharArray())).logout(); admin.refresh(false); // ensure that there is a rep:cache node assertNodeExists(newPath + "/rep:cache"); // install user package JcrPackage pack = packMgr.upload(getStream("/test-packages/test_user_a.zip"), false); assertNotNull(pack); ImportOptions opts = getDefaultOptions(); opts.setImportMode(mode); pack.install(opts); // check if user exists User userA = (User) mgr.getAuthorizable(ID_TEST_USER_A); assertNotNull("test-user-a must exist", userA); }
Example #23
Source File: ImportTests.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testImportWithoutRootAccess() throws IOException, RepositoryException, ConfigurationException { Assume.assumeTrue(!isOak()); // Create test user UserManager userManager = ((JackrabbitSession)admin).getUserManager(); String userId = "user1"; String userPwd = "pwd1"; User user1 = userManager.createUser(userId, userPwd); Principal principal1 = user1.getPrincipal(); // Create /tmp folder admin.getRootNode().addNode("tmp"); admin.save(); // Setup test user ACLs such that the // root node is not accessible AccessControlUtils.addAccessControlEntry(admin, null, principal1, new String[]{"jcr:namespaceManagement","jcr:nodeTypeDefinitionManagement"}, true); AccessControlUtils.addAccessControlEntry(admin, "/", principal1, new String[]{"jcr:all"}, false); AccessControlUtils.addAccessControlEntry(admin, "/tmp", principal1, new String[]{"jcr:all"}, true); admin.save(); // Import with a session associated to the test user Session session = repository.login(new SimpleCredentials(userId, userPwd.toCharArray())); ZipArchive archive = new ZipArchive(getTempFile("/test-packages/tmp.zip")); archive.open(true); ImportOptions opts = getDefaultOptions(); Importer importer = new Importer(opts); importer.run(archive, session, "/"); session.logout(); assertNodeExists("/tmp/foo/bar/tobi"); }
Example #24
Source File: ImportTests.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testImportWithoutRootAndTmpAccess() throws IOException, RepositoryException, ConfigurationException { Assume.assumeTrue(!isOak()); // Create test user UserManager userManager = ((JackrabbitSession)admin).getUserManager(); String userId = "user1"; String userPwd = "pwd1"; User user1 = userManager.createUser(userId, userPwd); Principal principal1 = user1.getPrincipal(); // Create /tmp folder admin.getRootNode().addNode("tmp").addNode("foo"); admin.save(); // Setup test user ACLs such that the // root node is not accessible AccessControlUtils.addAccessControlEntry(admin, null, principal1, new String[]{"jcr:namespaceManagement","jcr:nodeTypeDefinitionManagement"}, true); AccessControlUtils.addAccessControlEntry(admin, "/", principal1, new String[]{"jcr:all"}, false); AccessControlUtils.addAccessControlEntry(admin, "/tmp/foo", principal1, new String[]{"jcr:all"}, true); admin.save(); // Import with a session associated to the test user Session session = repository.login(new SimpleCredentials(userId, userPwd.toCharArray())); ZipArchive archive = new ZipArchive(getTempFile("/test-packages/tmp_foo.zip")); archive.open(true); ImportOptions opts = getDefaultOptions(); Importer importer = new Importer(opts); importer.run(archive, session, "/"); session.logout(); assertNodeExists("/tmp/foo/bar/tobi"); }
Example #25
Source File: TestPackageInstall.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Installs a package with an install hook and a not allowed user */ @Test public void testHookWithNotAllowedNonAdminUser() throws RepositoryException, IOException, PackageException { if (admin.nodeExists("/testroot")) { admin.getNode("/testroot").remove(); } admin.getRootNode().addNode("testroot", "nt:unstructured").addNode("testnode", "nt:unstructured"); admin.save(); // Create test user UserManager userManager = ((JackrabbitSession)admin).getUserManager(); String userId = "user1"; String userPwd = "pwd1"; User user1 = userManager.createUser(userId, userPwd); Principal principal1 = user1.getPrincipal(); // Setup test user ACLs that there are no restrictions AccessControlUtils.addAccessControlEntry(admin, null, principal1, new String[]{"jcr:namespaceManagement","jcr:nodeTypeDefinitionManagement"}, true); AccessControlUtils.addAccessControlEntry(admin, "/", principal1, new String[]{"jcr:all"}, true); admin.save(); Session userSession = repository.login(new SimpleCredentials(userId, userPwd.toCharArray())); try { packMgr = new JcrPackageManagerImpl(userSession, new String[0], null, null); PackageEventDispatcherImpl dispatcher = new PackageEventDispatcherImpl(); dispatcher.bindPackageEventListener(new ActivityLog(), Collections.singletonMap("component.id", (Object) "1234")); packMgr.setDispatcher(dispatcher); JcrPackage pack = packMgr.upload(getStream("/test-packages/test_hook.zip"), false); assertNotNull(pack); thrown.expect(PackageException.class); thrown.expectMessage("Package extraction requires admin session as it has a hook"); packMgr.getInternalRegistry().installPackage(userSession, new JcrRegisteredPackage(pack), getDefaultOptions(), true); } finally { userSession.logout(); } }
Example #26
Source File: TestPackageInstall.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Installs a package with an install hook and an explicitly allowed user */ @Test public void testHookWithAllowedNonAdminUser() throws RepositoryException, IOException, PackageException { if (admin.nodeExists("/testroot")) { admin.getNode("/testroot").remove(); } admin.getRootNode().addNode("testroot", "nt:unstructured").addNode("testnode", "nt:unstructured"); admin.save(); // Create test user UserManager userManager = ((JackrabbitSession)admin).getUserManager(); String userId = "user1"; String userPwd = "pwd1"; User user1 = userManager.createUser(userId, userPwd); Principal principal1 = user1.getPrincipal(); // Setup test user ACLs that there are no restrictions AccessControlUtils.addAccessControlEntry(admin, null, principal1, new String[]{"jcr:namespaceManagement","jcr:nodeTypeDefinitionManagement"}, true); AccessControlUtils.addAccessControlEntry(admin, "/", principal1, new String[]{"jcr:all"}, true); admin.save(); Session userSession = repository.login(new SimpleCredentials(userId, userPwd.toCharArray())); try { packMgr = new JcrPackageManagerImpl(userSession, new String[0], new String[] {"user1"}, null); PackageEventDispatcherImpl dispatcher = new PackageEventDispatcherImpl(); dispatcher.bindPackageEventListener(new ActivityLog(), Collections.singletonMap("component.id", (Object) "1234")); packMgr.setDispatcher(dispatcher); JcrPackage pack = packMgr.upload(getStream("/test-packages/test_hook.zip"), false); assertNotNull(pack); packMgr.getInternalRegistry().installPackage(userSession, new JcrRegisteredPackage(pack), getDefaultOptions(), true); assertTrue(admin.propertyExists("/testroot/hook-example")); } finally { userSession.logout(); } }
Example #27
Source File: TestPackageInstall.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Tests if package installation works w/o RW access to / and /tmp. * this currently fails, due to the creation of the snapshot. * also see {@link TestNoRootAccessExport#exportNoRootAccess()} */ @Test @Ignore("JCRVLT-100") public void testInstallWithoutRootAndTmpAccess() throws IOException, RepositoryException, ConfigurationException, PackageException { JcrPackage pack = packMgr.upload(getStream("/test-packages/tmp_foo.zip"), true, true); assertNotNull(pack); assertTrue(pack.isValid()); PackageId id = pack.getPackage().getId(); pack.close(); // Create test user UserManager userManager = ((JackrabbitSession)admin).getUserManager(); String userId = "user1"; String userPwd = "pwd1"; User user1 = userManager.createUser(userId, userPwd); Principal principal1 = user1.getPrincipal(); // Create /tmp folder admin.getRootNode().addNode("tmp").addNode("foo"); admin.save(); // Setup test user ACLs such that the // root node is not accessible AccessControlUtils.addAccessControlEntry(admin, null, principal1, new String[]{"jcr:namespaceManagement","jcr:nodeTypeDefinitionManagement"}, true); AccessControlUtils.addAccessControlEntry(admin, "/", principal1, new String[]{"jcr:all"}, false); AccessControlUtils.addAccessControlEntry(admin, ((JcrPackageRegistry)packMgr.getRegistry()).getPackRootPaths()[0], principal1, new String[]{"jcr:all"}, true); AccessControlUtils.addAccessControlEntry(admin, "/tmp/foo", principal1, new String[]{"jcr:all"}, true); admin.save(); Session session = repository.login(new SimpleCredentials(userId, userPwd.toCharArray())); JcrPackageManagerImpl userPackMgr = new JcrPackageManagerImpl(session, new String[0], null, null); pack = userPackMgr.open(id); ImportOptions opts = getDefaultOptions(); pack.install(opts); pack.close(); session.logout(); assertNodeExists("/tmp/foo/bar/tobi"); }
Example #28
Source File: TestPackageInstall.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Test if package extraction works w/o RW access to / and /tmp. */ @Test public void testExtractWithoutRootAndTmpAccess() throws IOException, RepositoryException, ConfigurationException, PackageException { Assume.assumeTrue(!isOak()); JcrPackage pack = packMgr.upload(getStream("/test-packages/tmp_foo.zip"), true, true); assertNotNull(pack); assertTrue(pack.isValid()); PackageId id = pack.getPackage().getId(); pack.close(); // Create test user UserManager userManager = ((JackrabbitSession)admin).getUserManager(); String userId = "user1"; String userPwd = "pwd1"; User user1 = userManager.createUser(userId, userPwd); Principal principal1 = user1.getPrincipal(); // Create /tmp folder admin.getRootNode().addNode("tmp").addNode("foo"); admin.save(); // Setup test user ACLs such that the // root node is not accessible AccessControlUtils.addAccessControlEntry(admin, null, principal1, new String[]{"jcr:namespaceManagement","jcr:nodeTypeDefinitionManagement"}, true); AccessControlUtils.addAccessControlEntry(admin, "/", principal1, new String[]{"jcr:all"}, false); AccessControlUtils.addAccessControlEntry(admin, ((JcrPackageRegistry)packMgr.getRegistry()).getPackRootPaths()[0], principal1, new String[]{"jcr:all"}, true); AccessControlUtils.addAccessControlEntry(admin, "/tmp/foo", principal1, new String[]{"jcr:all"}, true); admin.save(); Session session = repository.login(new SimpleCredentials(userId, userPwd.toCharArray())); JcrPackageManagerImpl userPackMgr = new JcrPackageManagerImpl(session, new String[0], null, null); pack = userPackMgr.open(id); ImportOptions opts = getDefaultOptions(); pack.extract(opts); pack.close(); session.logout(); assertNodeExists("/tmp/foo/bar/tobi"); }
Example #29
Source File: TestGroupMergePackage.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void assertABC(UserManager mgr) throws RepositoryException { // check if group exists Group grp = (Group) mgr.getAuthorizable("test-group"); assertNotNull("test-group must exist", grp); User userA = (User) mgr.getAuthorizable("test-user-a"); User userB = (User) mgr.getAuthorizable("test-user-b"); User userC = (User) mgr.getAuthorizable("test-user-c"); assertNotNull("test-user-a must exist", userA); assertNotNull("test-user-b must exist", userB); assertNotNull("test-user-c must exist", userC); assertTrue("test-user-a is member of test-group", grp.isMember(userA)); assertTrue("test-user-b is member of test-group", grp.isMember(userB)); assertTrue("test-user-c is member of test-group", grp.isMember(userC)); }
Example #30
Source File: AuthorizableManagerImpl.java From APM with Apache License 2.0 | 5 votes |
@Override public User createMockUser(String id) { User user = new MockUser(id); existingAuthorizables.put(id, user); removedAuthorizables.remove(id); return user; }