Search in sources :

Example 1 with AdminPrincipal

use of org.apache.jackrabbit.core.security.principal.AdminPrincipal in project jackrabbit by apache.

the class SessionFactory method createAdminSession.

public SessionImpl createAdminSession(String workspace) throws RepositoryException {
    Principal admin = new AdminPrincipal(SecurityConstants.ADMIN_ID);
    Subject subject = new Subject(true, Collections.singleton(admin), Collections.emptySet(), Collections.emptySet());
    return context.getRepository().createSession(subject, workspace);
}
Also used : AdminPrincipal(org.apache.jackrabbit.core.security.principal.AdminPrincipal) Principal(java.security.Principal) AdminPrincipal(org.apache.jackrabbit.core.security.principal.AdminPrincipal) Subject(javax.security.auth.Subject)

Example 2 with AdminPrincipal

use of org.apache.jackrabbit.core.security.principal.AdminPrincipal in project jackrabbit by apache.

the class AdministratorTest method testGetPrincipal.

public void testGetPrincipal() throws RepositoryException {
    Authorizable admin = userMgr.getAuthorizable(adminId);
    assertNotNull(admin);
    assertFalse(admin.isGroup());
    assertTrue(admin.getPrincipal() instanceof AdminPrincipal);
}
Also used : AdminPrincipal(org.apache.jackrabbit.core.security.principal.AdminPrincipal) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Example 3 with AdminPrincipal

use of org.apache.jackrabbit.core.security.principal.AdminPrincipal in project jackrabbit by apache.

the class ImpersonationImplTest method testAdminPrincipalAsImpersonator.

public void testAdminPrincipalAsImpersonator() throws RepositoryException, NotExecutableException {
    String adminId = superuser.getUserID();
    Authorizable a = userMgr.getAuthorizable(adminId);
    if (a == null || a.isGroup() || !((User) a).isAdmin()) {
        throw new NotExecutableException(adminId + " is not administators ID");
    }
    Principal adminPrincipal = new AdminPrincipal(adminId);
    // admin cannot be add/remove to set of impersonators of 'u' but is
    // always allowed to impersonate that user.
    User u = (User) userMgr.getAuthorizable(uID);
    Impersonation impersonation = u.getImpersonation();
    assertFalse(impersonation.grantImpersonation(adminPrincipal));
    assertFalse(impersonation.revokeImpersonation(adminPrincipal));
    assertTrue(impersonation.allows(buildSubject(adminPrincipal)));
    // same if the impersonation object of the admin itself is used.
    Impersonation adminImpersonation = ((User) a).getImpersonation();
    assertFalse(adminImpersonation.grantImpersonation(adminPrincipal));
    assertFalse(adminImpersonation.revokeImpersonation(adminPrincipal));
    assertTrue(impersonation.allows(buildSubject(adminPrincipal)));
}
Also used : AdminPrincipal(org.apache.jackrabbit.core.security.principal.AdminPrincipal) Impersonation(org.apache.jackrabbit.api.security.user.Impersonation) User(org.apache.jackrabbit.api.security.user.User) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AdminPrincipal(org.apache.jackrabbit.core.security.principal.AdminPrincipal) SystemPrincipal(org.apache.jackrabbit.core.security.SystemPrincipal) Principal(java.security.Principal)

Aggregations

AdminPrincipal (org.apache.jackrabbit.core.security.principal.AdminPrincipal)3 Principal (java.security.Principal)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 Subject (javax.security.auth.Subject)1 Impersonation (org.apache.jackrabbit.api.security.user.Impersonation)1 User (org.apache.jackrabbit.api.security.user.User)1 SystemPrincipal (org.apache.jackrabbit.core.security.SystemPrincipal)1 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)1