Search in sources :

Example 26 with GuestCredentials

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

the class PreAuthTest method testSubjectAndCredentials.

@Test
public void testSubjectAndCredentials() throws Exception {
    final Subject subject = new Subject(true, principals, Collections.<Object>emptySet(), Collections.<Object>emptySet());
    ContentSession cs = Subject.doAsPrivileged(subject, new PrivilegedAction<ContentSession>() {

        @Override
        public ContentSession run() {
            ContentSession cs;
            try {
                cs = login(new GuestCredentials());
                return cs;
            } catch (Exception e) {
                return null;
            }
        }
    }, null);
    assertNull("Login should have failed.", cs);
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Subject(javax.security.auth.Subject) SystemSubject(org.apache.jackrabbit.oak.spi.security.authentication.SystemSubject) GuestCredentials(javax.jcr.GuestCredentials) LoginException(javax.security.auth.login.LoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 27 with GuestCredentials

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

the class TokenAuthenticationTest method testAuthenticateWithInvalidCredentials.

@Test
public void testAuthenticateWithInvalidCredentials() throws Exception {
    List<Credentials> invalid = new ArrayList<Credentials>();
    invalid.add(new GuestCredentials());
    invalid.add(new SimpleCredentials(userId, new char[0]));
    for (Credentials creds : invalid) {
        assertFalse(authentication.authenticate(creds));
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ArrayList(java.util.ArrayList) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) GuestCredentials(javax.jcr.GuestCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 28 with GuestCredentials

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

the class TokenLoginModuleTest method testGuestLogin.

@Test
public void testGuestLogin() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(new GuestCredentials());
        fail("GuestCredentials login should fail");
    } catch (LoginException e) {
    // success
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) GuestCredentials(javax.jcr.GuestCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 29 with GuestCredentials

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

the class TokenProviderImplReadOnlyTest method before.

@Override
public void before() throws Exception {
    super.before();
    AccessControlManager acMgr = getAccessControlManager(root);
    String userPath = getTestUser().getPath();
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, userPath);
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privilegesFromNames(PrivilegeConstants.JCR_READ));
    acMgr.setPolicy(userPath, acl);
    root.commit();
    cs = login(new GuestCredentials());
    readOnlyRoot = cs.getLatestRoot();
    readOnlyTp = new TokenProviderImpl(readOnlyRoot, getTokenConfig(), getUserConfiguration());
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) GuestCredentials(javax.jcr.GuestCredentials)

Example 30 with GuestCredentials

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

the class TokenProviderImplTest method testDoCreateToken.

@Test
public void testDoCreateToken() throws Exception {
    assertFalse(tokenProvider.doCreateToken(new GuestCredentials()));
    assertFalse(tokenProvider.doCreateToken(new TokenCredentials("token")));
    assertFalse(tokenProvider.doCreateToken(getAdminCredentials()));
    SimpleCredentials sc = new SimpleCredentials("uid", "pw".toCharArray());
    assertFalse(tokenProvider.doCreateToken(sc));
    sc.setAttribute("any_attribute", "value");
    assertFalse(tokenProvider.doCreateToken(sc));
    sc.setAttribute("rep:token_key", "value");
    assertFalse(tokenProvider.doCreateToken(sc));
    sc.setAttribute(".token", "existing");
    assertFalse(tokenProvider.doCreateToken(sc));
    sc.setAttribute(".token", "");
    assertTrue(tokenProvider.doCreateToken(sc));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Test(org.junit.Test)

Aggregations

GuestCredentials (javax.jcr.GuestCredentials)39 Test (org.junit.Test)25 SimpleCredentials (javax.jcr.SimpleCredentials)13 Credentials (javax.jcr.Credentials)12 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)12 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)10 Session (javax.jcr.Session)8 LoginException (javax.security.auth.login.LoginException)7 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Subject (javax.security.auth.Subject)4 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)4 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)4 ArrayList (java.util.ArrayList)3 Repository (javax.jcr.Repository)3 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)3 Map (java.util.Map)2 RepositoryException (javax.jcr.RepositoryException)2 AccessControlManager (javax.jcr.security.AccessControlManager)2