Search in sources :

Example 86 with SimpleCredentials

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

the class UserManagerTest method testNewUserCanLogin.

@Test
public void testNewUserCanLogin() throws RepositoryException, NotExecutableException {
    String uid = createUserId();
    User u = null;
    Session s = null;
    try {
        u = userMgr.createUser(uid, "pw");
        superuser.save();
        Credentials creds = new SimpleCredentials(uid, "pw".toCharArray());
        s = superuser.getRepository().login(creds);
    } finally {
        if (u != null) {
            u.remove();
            superuser.save();
        }
        if (s != null) {
            s.logout();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session) Test(org.junit.Test)

Example 87 with SimpleCredentials

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

the class UserManagerTest method testCreateUserIdDifferentFromPrincipalName.

@Test
public void testCreateUserIdDifferentFromPrincipalName() throws RepositoryException, NotExecutableException {
    User u = null;
    Session uSession = null;
    try {
        Principal p = getTestPrincipal();
        String uid = createUserId();
        u = userMgr.createUser(uid, "pw", p, null);
        superuser.save();
        String msg = "Creating a User with principal-name distinct from Principal-name must succeed as long as both are unique.";
        assertEquals(msg, u.getID(), uid);
        assertEquals(msg, p.getName(), u.getPrincipal().getName());
        assertFalse(msg, u.getID().equals(u.getPrincipal().getName()));
        // make sure the userID exposed by a Session corresponding to that
        // user is equal to the users ID.
        uSession = superuser.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray()));
        assertEquals(uid, uSession.getUserID());
    } finally {
        if (uSession != null) {
            uSession.logout();
        }
        if (u != null) {
            u.remove();
            superuser.save();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Session(javax.jcr.Session) Test(org.junit.Test)

Example 88 with SimpleCredentials

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

the class UserManagerTest method testUnknownUserLogin.

@Test
public void testUnknownUserLogin() throws RepositoryException {
    String uid = createUserId();
    assertNull(userMgr.getAuthorizable(uid));
    try {
        Session s = superuser.getRepository().login(new SimpleCredentials(uid, uid.toCharArray()));
        s.logout();
        fail("An unknown user should not be allowed to execute the login.");
    } catch (Exception e) {
    // ok.
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) RepositoryException(javax.jcr.RepositoryException) AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 89 with SimpleCredentials

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

the class UserManagerTest method testUserIDFromSession.

@Test
public void testUserIDFromSession() throws RepositoryException, NotExecutableException {
    User u = null;
    Session uSession = null;
    try {
        String uid = createUserId();
        u = userMgr.createUser(uid, "pw");
        superuser.save();
        uSession = superuser.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray()));
        assertEquals(u.getID(), uSession.getUserID());
    } finally {
        if (uSession != null) {
            uSession.logout();
        }
        if (u != null) {
            u.remove();
            superuser.save();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) Session(javax.jcr.Session) Test(org.junit.Test)

Example 90 with SimpleCredentials

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

the class JsonIndexCommand method openSession.

public static Session openSession(NodeStore nodeStore) throws RepositoryException {
    if (nodeStore == null) {
        return null;
    }
    StatisticsProvider statisticsProvider = StatisticsProvider.NOOP;
    Oak oak = new Oak(nodeStore).with(ManagementFactory.getPlatformMBeanServer());
    oak.getWhiteboard().register(StatisticsProvider.class, statisticsProvider, Collections.emptyMap());
    LuceneIndexProvider provider = createLuceneIndexProvider();
    oak.with((QueryIndexProvider) provider).with((Observer) provider).with(createLuceneIndexEditorProvider());
    Jcr jcr = new Jcr(oak);
    Repository repository = jcr.createRepository();
    return repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Repository(javax.jcr.Repository) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) Oak(org.apache.jackrabbit.oak.Oak) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) LuceneIndexProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider)

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