Java Code Examples for org.apache.jackrabbit.api.security.user.User#getPath()

The following examples show how to use org.apache.jackrabbit.api.security.user.User#getPath() . 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: TestUserContentPackage.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: TestUserContentPackage.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: TestUserContentPackage.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
@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 vote down vote up
@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 5 votes vote down vote up
@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 6
Source File: TestUserContentPackage.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
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 7
Source File: TestUserContentPackage.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
private User installUserA(ImportMode mode, boolean usePkgPath, boolean expectPkgPath) throws RepositoryException, IOException, PackageException {
    UserManager mgr = ((JackrabbitSession) admin).getUserManager();
    assertNull("test-user-a must not exist", mgr.getAuthorizable(ID_TEST_USER_A));

    User u;
    if (usePkgPath) {
        u = mgr.createUser(ID_TEST_USER_A, ID_TEST_PASSWORD, new PrincipalImpl(ID_TEST_USER_A), PARENT_PATH_TEST_USER_A);
    } else {
        u = mgr.createUser(ID_TEST_USER_A, ID_TEST_PASSWORD);
    }
    final String authPath = u.getPath();
    if (usePkgPath) {
        assertEquals("authorizable path must be correct", PARENT_PATH_TEST_USER_A, Text.getRelativeParent(authPath, 1));
    } else {
        assertNotSame("authorizable path must be different than the one in the package", PARENT_PATH_TEST_USER_A, Text.getRelativeParent(authPath, 1));
    }

    // create test property and node
    u.setProperty(NAME_USER_PROPERTY, admin.getValueFactory().createValue("initial"));
    admin.getNode(u.getPath()).addNode(NAME_PROFILE_PRIVATE_NODE, NodeType.NT_UNSTRUCTURED);

    admin.save();

    JcrPackage pack = packMgr.upload(getStream("/test-packages/test_user_a.zip"), false);
    assertNotNull(pack);
    ImportOptions opts = getDefaultOptions();
    if (mode != null) {
        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);

    // check path
    if (expectPkgPath) {
        assertEquals("authorizable path must be correct", PARENT_PATH_TEST_USER_A, Text.getRelativeParent(userA.getPath(), 1));
    } else {
        assertEquals("authorizable path must be correct", authPath, userA.getPath());
    }

    // check import mode dependent stuff
    if (mode == null || mode == ImportMode.REPLACE) {
        assertProperty(userA.getPath() + "/" + NAME_USER_PROPERTY, "a");
        assertProperty(userA.getPath() + "/" + NAME_PROFILE_FULLNAME, "Test User");
        assertNodeExists(userA.getPath() + "/" + NAME_PROFILE_NODE);
        assertNodeMissing(userA.getPath() + "/" + NAME_PROFILE_PRIVATE_NODE);
    } else if (mode == ImportMode.UPDATE) {
        assertProperty(userA.getPath() + "/" + NAME_USER_PROPERTY, "a");
        assertProperty(userA.getPath() + "/" + NAME_PROFILE_FULLNAME, "Test User");
        assertNodeExists(userA.getPath() + "/" + NAME_PROFILE_NODE);
        assertNodeExists(userA.getPath() + "/" + NAME_PROFILE_PRIVATE_NODE);
    } else if (mode == ImportMode.MERGE) {
        assertProperty(userA.getPath() + "/" + NAME_USER_PROPERTY, "initial");
        assertProperty(userA.getPath() + "/" + NAME_PROFILE_FULLNAME, "Test User");
        assertNodeExists(userA.getPath() + "/" + NAME_PROFILE_NODE);
        assertNodeExists(userA.getPath() + "/" + NAME_PROFILE_PRIVATE_NODE);
    }

    return userA;
}