Search in sources :

Example 76 with SimpleCredentials

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

the class TokenConfigurationImplOSGiTest method before.

@Override
public void before() throws Exception {
    super.before();
    tokenConfiguration.setSecurityProvider(getSecurityProvider());
    context.registerInjectActivateService(tokenConfiguration, ImmutableMap.<String, Object>of(TokenProvider.PARAM_TOKEN_EXPIRATION, 25, TokenProvider.PARAM_TOKEN_LENGTH, 4));
    sc = new SimpleCredentials(getTestUser().getID(), new char[0]);
    sc.setAttribute(TokenConstants.TOKEN_ATTRIBUTE, "");
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials)

Example 77 with SimpleCredentials

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

the class Jackrabbit2ConfigurationTest method testSimpleCredentialsWithAttribute.

@Test
public void testSimpleCredentialsWithAttribute() throws Exception {
    ContentSession cs = null;
    try {
        SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
        sc.setAttribute(".token", "");
        cs = login(sc);
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 78 with SimpleCredentials

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

the class Jackrabbit2ConfigurationTest method testValidTokenCredentials.

@Test
public void testValidTokenCredentials() throws Exception {
    Root root = adminSession.getLatestRoot();
    TokenConfiguration tc = getSecurityProvider().getConfiguration(TokenConfiguration.class);
    TokenProvider tp = tc.getTokenProvider(root);
    SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
    TokenInfo info = tp.createToken(sc.getUserID(), Collections.<String, Object>emptyMap());
    ContentSession cs = login(new TokenCredentials(info.getToken()));
    try {
        assertEquals(sc.getUserID(), cs.getAuthInfo().getUserID());
    } finally {
        cs.close();
    }
}
Also used : TokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration) TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) SimpleCredentials(javax.jcr.SimpleCredentials) Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 79 with SimpleCredentials

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

the class AbstractAddMembersByIdTest method addExistingMemberWithoutAccess.

Set<String> addExistingMemberWithoutAccess() throws Exception {
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testGroup.getPath());
    if (acl != null) {
        if (acl.addEntry(getTestUser().getPrincipal(), privilegesFromNames(PrivilegeConstants.JCR_READ, PrivilegeConstants.REP_USER_MANAGEMENT), true)) {
            acMgr.setPolicy(testGroup.getPath(), acl);
            root.commit();
        }
    }
    String userId = getTestUser().getID();
    ContentSession testSession = null;
    try {
        testSession = login(new SimpleCredentials(userId, userId.toCharArray()));
        Root testRoot = testSession.getLatestRoot();
        assertFalse(testRoot.getTree(memberGroup.getPath()).exists());
        Group gr = getUserManager(testRoot).getAuthorizable(testGroup.getID(), Group.class);
        Set<String> failed = gr.addMembers(memberGroup.getID());
        testRoot.commit();
        return failed;
    } finally {
        if (testSession != null) {
            testSession.close();
        }
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) SimpleCredentials(javax.jcr.SimpleCredentials) Group(org.apache.jackrabbit.api.security.user.Group) Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 80 with SimpleCredentials

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

the class UserAuthenticationTest method testAuthenticateIdMismatch.

@Test
public void testAuthenticateIdMismatch() throws Exception {
    try {
        authentication.authenticate(new SimpleCredentials("unknownUser", "pw".toCharArray()));
        fail("LoginException expected");
    } catch (LoginException e) {
        // success
        assertTrue(e instanceof FailedLoginException);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) FailedLoginException(javax.security.auth.login.FailedLoginException) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

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