Search in sources :

Example 41 with SimpleCredentials

use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.

the class LoginModuleImplTest method testUnknownUserLogin.

@Test
public void testUnknownUserLogin() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials("unknown", "".toCharArray()));
        fail("Unknown user must not be able to login");
    } catch (LoginException e) {
    // success
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 42 with SimpleCredentials

use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.

the class LoginModuleImplTest method testSelfImpersonation.

@Test
public void testSelfImpersonation() throws Exception {
    ContentSession cs = null;
    try {
        createTestUser();
        SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PW.toCharArray());
        cs = login(sc);
        AuthInfo authInfo = cs.getAuthInfo();
        assertEquals(USER_ID, authInfo.getUserID());
        cs.close();
        sc = new SimpleCredentials(USER_ID, new char[0]);
        ImpersonationCredentials ic = new ImpersonationCredentials(sc, authInfo);
        cs = login(ic);
        authInfo = cs.getAuthInfo();
        assertEquals(USER_ID, authInfo.getUserID());
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 43 with SimpleCredentials

use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.

the class LoginModuleImplTest method testAnonymousLogin.

@Test
public void testAnonymousLogin() throws Exception {
    String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters());
    UserManager userMgr = getUserManager(root);
    // verify initial user-content looks like expected
    Authorizable anonymous = userMgr.getAuthorizable(anonymousID);
    assertNotNull(anonymous);
    assertFalse(root.getTree(anonymous.getPath()).hasProperty(UserConstants.REP_PASSWORD));
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(anonymousID, new char[0]));
        fail("Login with anonymousID should fail since the initial setup doesn't provide a password.");
    } catch (LoginException e) {
    // success
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 44 with SimpleCredentials

use of javax.jcr.SimpleCredentials in project jackrabbit by apache.

the class SimpleSecurityManager method getUserID.

/**
     * @see JackrabbitSecurityManager#getUserID(javax.security.auth.Subject, String)
     */
public String getUserID(Subject subject, String workspaceName) throws RepositoryException {
    String uid = null;
    // if SimpleCredentials are present, the UserID can easily be retrieved.
    Iterator<SimpleCredentials> creds = subject.getPublicCredentials(SimpleCredentials.class).iterator();
    if (creds.hasNext()) {
        SimpleCredentials sc = creds.next();
        uid = sc.getUserID();
    } else if (anonymID != null && !subject.getPrincipals(AnonymousPrincipal.class).isEmpty()) {
        uid = anonymID;
    } else {
        // of the first non-group principal.
        for (Principal p : subject.getPrincipals()) {
            if (!(p instanceof Group)) {
                uid = p.getName();
                break;
            }
        }
    }
    return uid;
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Group(java.security.acl.Group) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) AnonymousPrincipal(org.apache.jackrabbit.core.security.AnonymousPrincipal) UserPrincipal(org.apache.jackrabbit.core.security.UserPrincipal) AdminPrincipal(org.apache.jackrabbit.core.security.principal.AdminPrincipal) Principal(java.security.Principal)

Example 45 with SimpleCredentials

use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.

the class LoginModuleImpl method createAuthInfo.

private AuthInfo createAuthInfo(@Nonnull Set<? extends Principal> principals) {
    Credentials creds;
    if (credentials instanceof ImpersonationCredentials) {
        creds = ((ImpersonationCredentials) credentials).getBaseCredentials();
    } else {
        creds = credentials;
    }
    Map<String, Object> attributes = new HashMap<String, Object>();
    Object shared = sharedState.get(SHARED_KEY_ATTRIBUTES);
    if (shared instanceof Map) {
        for (Object key : ((Map) shared).keySet()) {
            attributes.put(key.toString(), ((Map) shared).get(key));
        }
    } else if (creds instanceof SimpleCredentials) {
        SimpleCredentials sc = (SimpleCredentials) creds;
        for (String attrName : sc.getAttributeNames()) {
            attributes.put(attrName, sc.getAttribute(attrName));
        }
    }
    return new AuthInfoImpl(userId, attributes, principals);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) GuestCredentials(javax.jcr.GuestCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials)

Aggregations

SimpleCredentials (javax.jcr.SimpleCredentials)289 Test (org.junit.Test)142 Session (javax.jcr.Session)83 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)60 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)53 User (org.apache.jackrabbit.api.security.user.User)41 Credentials (javax.jcr.Credentials)39 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)35 UserManager (org.apache.jackrabbit.api.security.user.UserManager)34 LoginException (javax.security.auth.login.LoginException)30 Node (javax.jcr.Node)28 RepositoryException (javax.jcr.RepositoryException)25 Principal (java.security.Principal)22 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)21 GuestCredentials (javax.jcr.GuestCredentials)20 LoginException (javax.jcr.LoginException)19 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)19 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)18 Before (org.junit.Before)18 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)17