Search in sources :

Example 71 with Credentials

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

the class L11_PasswordTest method testCreateUserAndLogin.

public void testCreateUserAndLogin() throws RepositoryException {
    testUser = userManager.createUser(testId, TEST_PW);
    superuser.save();
    // EXERCISE build the credentials
    Credentials creds = null;
    getHelper().getRepository().login(creds).logout();
}
Also used : Credentials(javax.jcr.Credentials)

Example 72 with Credentials

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

the class UserTest method testLoginWithGetCredentials.

@Test
public void testLoginWithGetCredentials() throws RepositoryException, NotExecutableException {
    try {
        Credentials creds = user.getCredentials();
        Session s = getHelper().getRepository().login(creds);
        s.logout();
        fail("Login using credentials exposed on user must fail.");
    } catch (UnsupportedRepositoryOperationException e) {
        throw new NotExecutableException(e.getMessage());
    } catch (LoginException e) {
    // success
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) LoginException(javax.jcr.LoginException) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 73 with Credentials

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

the class UserManagerImplTest method testNewUserCanLogin.

public void testNewUserCanLogin() throws RepositoryException, NotExecutableException {
    String uid = getTestPrincipal().getName();
    String pw = buildPassword(uid);
    User u = null;
    Session s = null;
    try {
        u = userMgr.createUser(uid, pw);
        save(superuser);
        Credentials creds = new SimpleCredentials(uid, pw.toCharArray());
        s = superuser.getRepository().login(creds);
    } finally {
        if (u != null) {
            u.remove();
            save(superuser);
        }
        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)

Example 74 with Credentials

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

the class UserImplTest method testLoginWithCryptedCredentials.

public void testLoginWithCryptedCredentials() throws RepositoryException {
    User u = (User) uMgr.getAuthorizable(uID);
    Credentials creds = u.getCredentials();
    assertTrue(creds instanceof CryptedSimpleCredentials);
    try {
        Session s = getHelper().getRepository().login(u.getCredentials());
        s.logout();
        fail("Login using CryptedSimpleCredentials must fail.");
    } catch (LoginException e) {
    // success
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) CryptedSimpleCredentials(org.apache.jackrabbit.core.security.authentication.CryptedSimpleCredentials) LoginException(javax.jcr.LoginException) SimpleCredentials(javax.jcr.SimpleCredentials) CryptedSimpleCredentials(org.apache.jackrabbit.core.security.authentication.CryptedSimpleCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

Example 75 with Credentials

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

the class UserImplTest method testUserImplHasCryptedSimplCredentials.

public void testUserImplHasCryptedSimplCredentials() throws RepositoryException, NotExecutableException {
    User user = getTestUser(superuser);
    Credentials creds = user.getCredentials();
    assertNotNull(creds);
    assertTrue(creds instanceof CryptedSimpleCredentials);
    assertEquals(((CryptedSimpleCredentials) creds).getUserID(), user.getID());
}
Also used : User(org.apache.jackrabbit.api.security.user.User) CryptedSimpleCredentials(org.apache.jackrabbit.core.security.authentication.CryptedSimpleCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) CryptedSimpleCredentials(org.apache.jackrabbit.core.security.authentication.CryptedSimpleCredentials) Credentials(javax.jcr.Credentials)

Aggregations

Credentials (javax.jcr.Credentials)86 SimpleCredentials (javax.jcr.SimpleCredentials)53 Test (org.junit.Test)33 GuestCredentials (javax.jcr.GuestCredentials)26 Session (javax.jcr.Session)17 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)14 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)13 RepositoryException (javax.jcr.RepositoryException)12 User (org.apache.jackrabbit.api.security.user.User)12 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)12 LoginException (javax.security.auth.login.LoginException)8 ArrayList (java.util.ArrayList)7 LoginException (javax.jcr.LoginException)6 Subject (javax.security.auth.Subject)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Repository (javax.jcr.Repository)5 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)5 Principal (java.security.Principal)4 Map (java.util.Map)4