Search in sources :

Example 96 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class DefaultSyncContext method createGroup.

/**
 * Creates a new repository group for the given external one.
 * Note that this method only creates the authorizable but does not perform any synchronization.
 *
 * @param externalGroup the external group
 * @return the repository group
 * @throws RepositoryException if an error occurs
 */
@NotNull
protected Group createGroup(@NotNull ExternalGroup externalGroup) throws RepositoryException {
    Principal principal = new PrincipalImpl(externalGroup.getPrincipalName());
    Group group = userManager.createGroup(externalGroup.getId(), principal, PathUtils.concatRelativePaths(config.group().getPathPrefix(), externalGroup.getIntermediatePath()));
    setExternalId(group, externalGroup);
    return group;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ExternalLoginAutoMembershipTest method testLoginSyncAutoMembershipSetup1.

@Test
public void testLoginSyncAutoMembershipSetup1() throws Exception {
    try (ContentSession cs = login(new SimpleCredentials(USER_ID, new char[0]))) {
        // the login must set the existing auto-membership principals to the subject
        Set<Principal> principals = cs.getAuthInfo().getPrincipals();
        assertTrue(principals.contains(setup1.gr.getPrincipal()));
        assertFalse(principals.contains(new PrincipalImpl(NON_EXISTING_NAME)));
        assertFalse(principals.contains(setup2.gr.getPrincipal()));
        assertFalse(principals.contains(setup3.gr.getPrincipal()));
        // however, the existing auto-membership group must _not_ have changed
        // and the test user must not be a stored member of this group.
        root.refresh();
        UserManager uMgr = getUserManager(root);
        User user = uMgr.getAuthorizable(USER_ID, User.class);
        Group gr = uMgr.getAuthorizable(setup1.gr.getID(), Group.class);
        assertFalse(gr.isDeclaredMember(user));
        assertFalse(gr.isMember(user));
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 98 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ExternalLoginAutoMembershipTest method testLoginAfterSyncSetup5.

@Test
public void testLoginAfterSyncSetup5() throws Exception {
    setup5.sync(USER_ID, false);
    try (ContentSession cs = login(new SimpleCredentials(USER_ID, new char[0]))) {
        // the login must not set any auto-membership principals to the subject
        // as auto-membership is not configured on this setup.
        Set<Principal> principals = cs.getAuthInfo().getPrincipals();
        Set<Principal> expected = ImmutableSet.of(EveryonePrincipal.getInstance(), userManager.getAuthorizable(USER_ID).getPrincipal());
        assertEquals(expected, principals);
        assertFalse(principals.contains(new PrincipalImpl(NON_EXISTING_NAME)));
        assertFalse(principals.contains(setup1.gr.getPrincipal()));
        assertFalse(principals.contains(setup2.gr.getPrincipal()));
        assertFalse(principals.contains(setup3.gr.getPrincipal()));
        assertFalse(principals.contains(setup4.gr.getPrincipal()));
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 99 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ExternalLoginAutoMembershipTest method testLoginAfterSyncSetup1.

@Test
public void testLoginAfterSyncSetup1() throws Exception {
    setup1.sync(USER_ID, false);
    try (ContentSession cs = login(new SimpleCredentials(USER_ID, new char[0]))) {
        // the login must set the configured + existing auto-membership principals
        // to the subject; non-existing auto-membership entries must be ignored.
        Set<Principal> principals = cs.getAuthInfo().getPrincipals();
        assertTrue(principals.contains(setup1.gr.getPrincipal()));
        assertFalse(principals.contains(new PrincipalImpl(NON_EXISTING_NAME)));
        assertFalse(principals.contains(setup2.gr.getPrincipal()));
        assertFalse(principals.contains(setup3.gr.getPrincipal()));
        // however, the existing auto-membership group must _not_ have changed
        // and the test user must not be a stored member of this group.
        root.refresh();
        UserManager uMgr = getUserManager(root);
        User user = uMgr.getAuthorizable(USER_ID, User.class);
        Group gr = uMgr.getAuthorizable(setup1.gr.getID(), Group.class);
        assertFalse(gr.isDeclaredMember(user));
        assertFalse(gr.isMember(user));
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 100 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ExternalLoginAutoMembershipTest method testLoginAfterSyncSetup4.

@Test
public void testLoginAfterSyncSetup4() throws Exception {
    setup4.sync(USER_ID, false);
    try (ContentSession cs = login(new SimpleCredentials(USER_ID, new char[0]))) {
        // the login must set the existing auto-membership principals to the subject
        Set<Principal> principals = cs.getAuthInfo().getPrincipals();
        assertTrue(principals.contains(setup4.gr.getPrincipal()));
        assertTrue(principals.contains(setup2.gr.getPrincipal()));
        assertFalse(principals.contains(new PrincipalImpl(NON_EXISTING_NAME)));
        assertFalse(principals.contains(setup1.gr.getPrincipal()));
        assertFalse(principals.contains(setup3.gr.getPrincipal()));
        // however, the existing auto-membership group must _not_ have changed
        // and the test user must not be a stored member of this group.
        root.refresh();
        UserManager uMgr = getUserManager(root);
        User user = uMgr.getAuthorizable(USER_ID, User.class);
        Group gr = uMgr.getAuthorizable(setup4.gr.getID(), Group.class);
        assertFalse(gr.isDeclaredMember(user));
        assertFalse(gr.isMember(user));
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Aggregations

PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)154 Test (org.junit.Test)122 Principal (java.security.Principal)76 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)38 Group (org.apache.jackrabbit.api.security.user.Group)33 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)33 UserManager (org.apache.jackrabbit.api.security.user.UserManager)30 User (org.apache.jackrabbit.api.security.user.User)29 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)19 SimpleCredentials (javax.jcr.SimpleCredentials)17 GroupPrincipal (org.apache.jackrabbit.api.security.principal.GroupPrincipal)17 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 Subject (javax.security.auth.Subject)13 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)13 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)12 Session (javax.jcr.Session)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 RepositoryException (javax.jcr.RepositoryException)8 Tree (org.apache.jackrabbit.oak.api.Tree)8 NotNull (org.jetbrains.annotations.NotNull)8