Search in sources :

Example 51 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class SystemUserTest method testGetUserByID.

@Test
public void testGetUserByID() throws RepositoryException, NotExecutableException {
    user = createUser(uid);
    Authorizable authorizable = userMgr.getAuthorizable(user.getID());
    assertNotNull(authorizable);
    assertFalse(authorizable.isGroup());
    assertFalse(((User) authorizable).isAdmin());
    assertTrue(((User) authorizable).isSystemUser());
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Test(org.junit.Test)

Example 52 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class UserImportFromJackrabbit method testUUIDBehaviorReplaceFromRenamed.

/**
     * @since Oak 1.2
     */
@Test
public void testUUIDBehaviorReplaceFromRenamed() throws Exception {
    // create authorizable
    User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
    String initialPath = u.getPath();
    String movedPath = Text.getRelativeParent(initialPath, 1) + '/' + randomNodeName;
    importSession.move(initialPath, movedPath);
    importSession.save();
    // import 'correct' jr2 package which contains the encoded ID in the node name
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"" + uid + "\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:disabled\" sv:type=\"String\"><sv:value>disabledUser</sv:value></sv:property>" + "</sv:node>";
    doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
    Authorizable newUser = getUserManager().getAuthorizable(uid);
    // replace should update the path
    assertEquals("user path", Text.getRelativeParent(initialPath, 1) + '/' + uid, newUser.getPath());
    Node n = importSession.getNode(newUser.getPath());
    assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
    assertEquals(UserConstants.REP_AUTHORIZABLE_ID, uid, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
    assertEquals(UserConstants.REP_AUTHORIZABLE_ID, uid, newUser.getID());
    // saving changes of the import must succeed.
    importSession.save();
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) PrincipalImpl(org.apache.jackrabbit.core.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 53 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class UserImportFromJackrabbit method testUUIDBehaviorRemove.

/**
     * @since Oak 1.2
     */
@Test
public void testUUIDBehaviorRemove() throws Exception {
    // create authorizable
    User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
    String initialPath = u.getPath();
    importSession.save();
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:disabled\" sv:type=\"String\"><sv:value>disabledUser</sv:value></sv:property>" + "</sv:node>";
    doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
    Authorizable newUser = getUserManager().getAuthorizable(uid);
    // IMPORT_UUID_COLLISION_REMOVE_EXISTING should result in the user to
    // be imported a the new path
    assertEquals(getTargetPath(), Text.getRelativeParent(newUser.getPath(), 1));
    assertFalse(initialPath.equals(newUser.getPath()));
    Node n = importSession.getNode(newUser.getPath());
    assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
    assertEquals(uid, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
    // saving changes of the import -> must succeed
    importSession.save();
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) PrincipalImpl(org.apache.jackrabbit.core.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 54 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class UserImportFromJackrabbit method testUUIDBehaviorReplaceFromRenamed2.

/**
     * @since Oak 1.2
     */
@Test
public void testUUIDBehaviorReplaceFromRenamed2() throws Exception {
    // create authorizable
    User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
    String initialPath = u.getPath();
    String movedPath = Text.getRelativeParent(initialPath, 1) + '/' + randomNodeName;
    importSession.move(initialPath, movedPath);
    importSession.save();
    // we need to include the new node name in the sysview import, so that the importer uses the correct name.
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"" + randomNodeName + "\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:disabled\" sv:type=\"String\"><sv:value>disabledUser</sv:value></sv:property>" + "</sv:node>";
    doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
    Authorizable newUser = getUserManager().getAuthorizable(uid);
    // replace should retain path
    assertEquals("user path", movedPath, newUser.getPath());
    Node n = importSession.getNode(newUser.getPath());
    assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
    assertEquals(UserConstants.REP_AUTHORIZABLE_ID, randomNodeName, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
    // the mismatch, which for the diff looks like a modified ID.
    try {
        importSession.save();
        fail("Importing an authorizable with mismatch between authorizableId and uuid must fail.");
    } catch (ConstraintViolationException e) {
        // success
        assertTrue(e.getMessage().contains("OakConstraint0022"));
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PrincipalImpl(org.apache.jackrabbit.core.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 55 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class UserQueryTest method testCondition1.

@Test
public void testCondition1() throws RepositoryException {
    Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {

        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.and(builder.eq("profile/@cute", vf.createValue(true)), builder.not(builder.eq("@color", vf.createValue("black")))));
        }
    });
    Iterator<User> expected = Iterators.filter(users.iterator(), new Predicate<User>() {

        public boolean apply(User user) {
            try {
                Value[] cute = user.getProperty("profile/cute");
                Value[] black = user.getProperty("color");
                return cute != null && cute.length == 1 && cute[0].getBoolean() && !(black != null && black.length == 1 && black[0].getString().equals("black"));
            } catch (RepositoryException e) {
                fail(e.getMessage());
            }
            return false;
        }
    });
    assertTrue(result.hasNext());
    assertSameElements(result, expected);
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Query(org.apache.jackrabbit.api.security.user.Query) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Aggregations

Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)466 Test (org.junit.Test)254 User (org.apache.jackrabbit.api.security.user.User)104 Group (org.apache.jackrabbit.api.security.user.Group)101 UserManager (org.apache.jackrabbit.api.security.user.UserManager)93 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)64 Principal (java.security.Principal)58 Node (javax.jcr.Node)55 RepositoryException (javax.jcr.RepositoryException)55 Query (org.apache.jackrabbit.api.security.user.Query)50 Session (javax.jcr.Session)49 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)45 Value (javax.jcr.Value)29 NodeImpl (org.apache.jackrabbit.core.NodeImpl)29 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)28 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)24 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)24 SimpleCredentials (javax.jcr.SimpleCredentials)21 HashMap (java.util.HashMap)18 QueryBuilder (org.apache.jackrabbit.api.security.user.QueryBuilder)16