Search in sources :

Example 56 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit by apache.

the class AuthorizableImplTest method testMultiValuedToSingle.

public void testMultiValuedToSingle() throws Exception {
    AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
    UserManager uMgr = getUserManager(superuser);
    try {
        Value v = superuser.getValueFactory().createValue("anyValue");
        Value[] vs = new Value[] { v, v };
        user.setProperty("someProp", vs);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        user.setProperty("someProp", v);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
    } finally {
        if (user.removeProperty("someProp") && !uMgr.isAutoSave()) {
            superuser.save();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue)

Example 57 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit by apache.

the class AuthorizableImplTest method testSingleToMultiValued.

public void testSingleToMultiValued() throws Exception {
    AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
    UserManager uMgr = getUserManager(superuser);
    try {
        Value v = superuser.getValueFactory().createValue("anyValue");
        user.setProperty("someProp", v);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        Value[] vs = new Value[] { v, v };
        user.setProperty("someProp", vs);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
    } finally {
        if (user.removeProperty("someProp") && !uMgr.isAutoSave()) {
            superuser.save();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue)

Example 58 with UserManager

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

the class IsMemberTest method beforeSuite.

@Override
protected void beforeSuite() throws Exception {
    super.beforeSuite();
    Session s = loginAdministrative();
    try {
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        Group gr = userManager.createGroup(new PrincipalImpl(GROUP + 0), REL_TEST_PATH);
        gPaths.add(gr.getPath());
        for (int i = 1; i < GROUP_CNT; i++) {
            Group g = userManager.createGroup(new PrincipalImpl(GROUP + i), REL_TEST_PATH);
            if (nestedGroups) {
                g.addMember(gr);
            }
            gr = g;
            gPaths.add(gr.getPath());
        }
        int cnt = 0;
        for (int i = 0; i <= numberOfUsers; i++) {
            User u = userManager.createUser(USER + i, null, new PrincipalImpl(USER + i), REL_TEST_PATH);
            uPaths.add(u.getPath());
            getRandomGroup(userManager).addMember(u);
            if (++cnt == 20000) {
                s.save();
            }
        }
    } 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) 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 59 with UserManager

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

the class GetGroupPrincipalsTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    super.beforeSuite();
    session = loginAdministrative();
    UserManager userManager = ((JackrabbitSession) session).getUserManager();
    Authorizable user = userManager.getAuthorizable(USER);
    if (user == null) {
        user = userManager.createUser(USER, USER);
        principalName = user.getPrincipal().getName();
    }
    // make sure we have a least a single group the user is member of.
    Group gr = userManager.createGroup(new PrincipalImpl(GROUP), "test");
    gr.addMember(user);
    for (int i = 1; i < numberOfGroups; i++) {
        Group g = userManager.createGroup(new PrincipalImpl(GROUP + i), "test");
        if (!nestedGroups) {
            g.addMember(user);
        } else {
            g.addMember(gr);
        }
        gr = g;
    }
    session.save();
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)

Example 60 with UserManager

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

the class RemoveMembersTest 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();
        String groupPath = groupPaths.get(random.nextInt(GROUP_CNT));
        Group g = (Group) userManager.getAuthorizableByPath(groupPath);
        removeMembers(userManager, g, s);
    } catch (RepositoryException e) {
        if (s.hasPendingChanges()) {
            s.refresh(false);
        }
    } 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

UserManager (org.apache.jackrabbit.api.security.user.UserManager)234 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)93 Test (org.junit.Test)90 Group (org.apache.jackrabbit.api.security.user.Group)81 User (org.apache.jackrabbit.api.security.user.User)72 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)52 Session (javax.jcr.Session)45 RepositoryException (javax.jcr.RepositoryException)40 Principal (java.security.Principal)38 SimpleCredentials (javax.jcr.SimpleCredentials)34 AccessDeniedException (javax.jcr.AccessDeniedException)19 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)19 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)17 Node (javax.jcr.Node)15 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)14 Value (javax.jcr.Value)11 Root (org.apache.jackrabbit.oak.api.Root)11 AccessControlManager (javax.jcr.security.AccessControlManager)9 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)9