Search in sources :

Example 71 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class AuthorizableFolderEditorTest method createSourceContent.

@Override
protected void createSourceContent(final Session session) throws Exception {
    UserManager userMgr = ((JackrabbitSession) session).getUserManager();
    userMgr.autoSave(false);
    Group group = userMgr.createGroup(TEST_GROUP);
    User user = userMgr.createUser(TEST_USER, "secret");
    group.addMember(user);
    session.save();
    // simulate the error, set node types to incorrect values
    Node home = session.getNode("/home");
    home.setPrimaryType(JcrConstants.NT_UNSTRUCTURED);
    home.getNode("users").setPrimaryType(JcrConstants.NT_UNSTRUCTURED);
    home.getNode("groups").setPrimaryType(JcrConstants.NT_UNSTRUCTURED);
    home.addNode("control", JcrConstants.NT_UNSTRUCTURED);
    session.save();
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Node(javax.jcr.Node) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 72 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class MemberBaseTest method runTest.

@Override
public void runTest() throws Exception {
    Session s = null;
    try {
        // use system session login to avoid measuring the login-performance here
        s = systemLogin();
        UserManager uMgr = ((JackrabbitSession) s).getUserManager();
        for (int i = 0; i <= 1000; i++) {
            testMembership((Group) uMgr.getAuthorizableByPath(groupPaths.get(random.nextInt(numberOfGroups))), (User) uMgr.getAuthorizableByPath(memberPaths.get(random.nextInt(numberOfMembers))));
        }
    } catch (RepositoryException e) {
        System.out.println(e.getMessage());
    } finally {
        if (s != null) {
            s.logout();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 73 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class MemberBaseTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    super.beforeSuite();
    Session s = loginAdministrative();
    try {
        List<String> memberIds = new ArrayList<String>(numberOfMembers);
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        for (int i = 0; i <= numberOfMembers; i++) {
            User u = userManager.createUser(USER + i, null, new PrincipalImpl(USER + i), REL_TEST_PATH);
            memberPaths.add(u.getPath());
            memberIds.add(USER + i);
        }
        String[] idArray = memberIds.toArray(new String[memberIds.size()]);
        for (int i = 0, j = 1; i <= numberOfGroups; i++, j++) {
            Group g = userManager.createGroup(new PrincipalImpl(GROUP + i), REL_TEST_PATH);
            groupPaths.add(g.getPath());
            if (nested) {
                g.addMembers(ObjectArrays.concat(idArray, GROUP + j));
            } else {
                g.addMembers(idArray);
            }
        }
    } finally {
        s.save();
        s.logout();
    }
    System.out.println("setup done");
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ArrayList(java.util.ArrayList) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 74 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class IsMemberTest method afterSuite.

@Override
public void afterSuite() throws Exception {
    Session s = loginAdministrative();
    try {
        Authorizable authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(GROUP + "0");
        if (authorizable != null) {
            Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
            n.remove();
        }
        authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(USER + "0");
        if (authorizable != null) {
            Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
            n.remove();
        }
        s.save();
    } finally {
        s.logout();
    }
}
Also used : Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 75 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class IsMemberTest method runTest.

@Override
public void runTest() throws Exception {
    Session s = null;
    try {
        // use system session login to avoid measuring the login-performance here
        s = systemLogin();
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        for (int i = 0; i <= 1000; i++) {
            Group g = getRandomGroup(userManager);
            boolean isMember = isMember(g, getRandomUser(userManager));
        //System.out.println(USER + i + " is " + (isMember? "" : "not ")+ "member of " +groupId);
        }
    } catch (RepositoryException e) {
        System.out.println(e.getMessage());
    } finally {
        if (s != null) {
            s.logout();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Aggregations

JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)114 UserManager (org.apache.jackrabbit.api.security.user.UserManager)51 Session (javax.jcr.Session)50 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)34 Node (javax.jcr.Node)25 Group (org.apache.jackrabbit.api.security.user.Group)25 User (org.apache.jackrabbit.api.security.user.User)24 Principal (java.security.Principal)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)17 Test (org.junit.Test)16 SimpleCredentials (javax.jcr.SimpleCredentials)15 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)11 RepositoryException (javax.jcr.RepositoryException)10 PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)9 PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)9 Privilege (javax.jcr.security.Privilege)8 LoginException (javax.jcr.LoginException)6 Property (javax.jcr.Property)6 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)6 Item (javax.jcr.Item)5