Search in sources :

Example 1 with LoginException

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

the class UserTest method testLoginWithOldPassword.

@Test
public void testLoginWithOldPassword() throws RepositoryException, NotExecutableException {
    try {
        user.changePassword("changed");
        superuser.save();
        Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(), testPw.toCharArray()));
        s.logout();
        fail("user pw has changed. login must fail.");
    } catch (LoginException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) LoginException(javax.jcr.LoginException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 2 with LoginException

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

the class UserTest method testLoginDisabledUser.

@Test
public void testLoginDisabledUser() throws Exception {
    user.disable("readonly user is disabled!");
    superuser.save();
    // -> login must fail
    try {
        Session ss = getHelper().getRepository().login(new SimpleCredentials(user.getID(), "pw".toCharArray()));
        ss.logout();
        fail("A disabled user must not be allowed to login any more");
    } catch (LoginException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) LoginException(javax.jcr.LoginException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 3 with LoginException

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

the class UserTest method testImpersonateDisabledUser.

@Test
public void testImpersonateDisabledUser() throws Exception {
    user.disable("readonly user is disabled!");
    superuser.save();
    // -> impersonating this user must fail
    try {
        Session ss = superuser.impersonate(new SimpleCredentials(user.getID(), new char[0]));
        ss.logout();
        fail("A disabled user cannot be impersonated any more.");
    } catch (LoginException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) LoginException(javax.jcr.LoginException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 4 with LoginException

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

the class UserTest method testLoginWithOldPassword2.

@Test
public void testLoginWithOldPassword2() throws RepositoryException, NotExecutableException {
    try {
        user.changePassword("changed", testPw);
        superuser.save();
        Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(), testPw.toCharArray()));
        s.logout();
        fail("superuser pw has changed. login must fail.");
    } catch (LoginException e) {
    // success
    } finally {
        user.changePassword(testPw);
        superuser.save();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) LoginException(javax.jcr.LoginException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 5 with LoginException

use of javax.jcr.LoginException in project sling by apache.

the class AbstractSlingRepository2 method loginService.

// service login
/**
     * Actual implementation of the {@link #loginService(String, String)} method
     * taking into account the bundle calling this method.
     * <p/>
     * This method uses the
     * {@link AbstractSlingRepositoryManager#getServiceUserMapper()
     * ServiceUserMapper} service to map the named service to a user and then
     * calls the {@link #createServiceSession(String, String)} method actually
     * create a session for that user.
     *
     * @param subServiceName An optional subService identifier (may be
     *            {@code null})
     * @param workspace The workspace to access or {@code null} to access the
     *            {@link #getDefaultWorkspace() default workspace}
     * @return A session authenticated with the service user
     * @throws LoginException if the service name cannot be derived or if
     *             logging is as the user to which the service name maps is not
     *             allowed
     * @throws RepositoryException If a general error occurs while creating the
     *             session
     */
@Override
public final Session loginService(final String subServiceName, final String workspace) throws LoginException, RepositoryException {
    final ServiceUserMapper serviceUserMapper = this.getSlingRepositoryManager().getServiceUserMapper();
    final String userName = (serviceUserMapper != null) ? serviceUserMapper.getServiceUserID(this.usingBundle, subServiceName) : null;
    if (userName == null) {
        throw new LoginException("Cannot derive user name for bundle " + usingBundle + " and sub service " + subServiceName);
    }
    return createServiceSession(userName, workspace);
}
Also used : ServiceUserMapper(org.apache.sling.serviceusermapping.ServiceUserMapper) LoginException(javax.jcr.LoginException)

Aggregations

LoginException (javax.jcr.LoginException)28 Session (javax.jcr.Session)20 SimpleCredentials (javax.jcr.SimpleCredentials)20 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)13 Credentials (javax.jcr.Credentials)8 Test (org.junit.Test)6 RepositoryException (javax.jcr.RepositoryException)5 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 User (org.apache.jackrabbit.api.security.user.User)4 UserManager (org.apache.jackrabbit.api.security.user.UserManager)4 IOException (java.io.IOException)3 AccessDeniedException (javax.jcr.AccessDeniedException)2 GuestCredentials (javax.jcr.GuestCredentials)2 Node (javax.jcr.Node)2 ServletException (javax.servlet.ServletException)2 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 ServiceUserMapper (org.apache.sling.serviceusermapping.ServiceUserMapper)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 AccessControlException (java.security.AccessControlException)1