Search in sources :

Example 1 with Credentials

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

the class SessionProviderImpl method getSession.

/**
     * {@inheritDoc }
     */
public Session getSession(HttpServletRequest request, Repository repository, String workspace) throws LoginException, RepositoryException, ServletException {
    Session s = null;
    // JCR-3222: Check if a custom session provider is available as a
    // request attribute. If one is available, ask it first for a session.
    Object object = request.getAttribute(SessionProvider.class.getName());
    if (object instanceof SessionProvider) {
        SessionProvider provider = (SessionProvider) object;
        s = provider.getSession(request, repository, workspace);
        if (s != null) {
            externalSessions.put(s, provider);
        }
    }
    if (s == null) {
        Credentials creds = cp.getCredentials(request);
        if (creds == null) {
            s = repository.login(workspace);
        } else {
            s = repository.login(creds, workspace);
        }
    }
    return s;
}
Also used : Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

Example 2 with Credentials

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

the class Login method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String anon = "anonymous";
    String user = (String) ctx.get(this.userKey);
    String password = (String) ctx.get(this.passwordKey);
    String workspace = (String) ctx.get(this.workspaceKey);
    if (user == null) {
        user = anon;
    }
    if (password == null || (password.equals(anon) && !user.equals(anon))) {
        ConsoleReader reader = new ConsoleReader();
        password = reader.readLine("Password: ", (char) 0);
    }
    if (log.isDebugEnabled()) {
        log.debug("logging in as " + user);
    }
    Session session = null;
    Repository repo = CommandHelper.getRepository(ctx);
    Credentials credentials = new SimpleCredentials(user, password.toCharArray());
    if (workspace == null) {
        session = repo.login(credentials);
    } else {
        session = repo.login(credentials, workspace);
    }
    CommandHelper.setSession(ctx, session);
    CommandHelper.setCurrentNode(ctx, session.getRootNode());
    return false;
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Repository(javax.jcr.Repository) ConsoleReader(jline.ConsoleReader) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

Example 3 with Credentials

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

the class CustomCredentialsSupportTest method testLoginWithUnsupportedCredentials.

@Test
public void testLoginWithUnsupportedCredentials() throws Exception {
    List<Credentials> creds = ImmutableList.of(new SimpleCredentials("testUser", new char[0]), new GuestCredentials());
    for (Credentials c : creds) {
        try {
            login(c).close();
            fail("login must fail for credentials " + c);
        } catch (LoginException e) {
        // success
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) LoginException(javax.security.auth.login.LoginException) GuestCredentials(javax.jcr.GuestCredentials) GuestCredentials(javax.jcr.GuestCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Example 4 with Credentials

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

the class TokenExternalLoginModuleTest method testTokenCreation.

@Test
public void testTokenCreation() throws Exception {
    Credentials creds = createTestCredentials();
    assertTrue(credentialsSupport.setAttributes(creds, ImmutableMap.<String, Object>of(".token", "")));
    String expectedUserId = credentialsSupport.getUserId(creds);
    ContentSession cs = login(creds);
    try {
        assertEquals(expectedUserId, cs.getAuthInfo().getUserID());
        Map<String, ?> attributes = credentialsSupport.getAttributes(creds);
        String token = attributes.get(".token").toString();
        assertFalse(token.isEmpty());
        root.refresh();
        User user = getUserManager(root).getAuthorizable(expectedUserId, User.class);
        Tree tokenParent = root.getTree(user.getPath()).getChild(".tokens");
        assertTrue(tokenParent.exists());
        assertEquals(1, tokenParent.getChildrenCount(100));
    } finally {
        cs.close();
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Example 5 with Credentials

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

the class AbstractRepositoryTest method testLoginWithCredentials.

/**
     * Tests the {@link AbstractRepository#login(Credentials)} method.
     *
     * @throws RepositoryException if an error occurs
     */
public void testLoginWithCredentials() throws RepositoryException {
    Credentials credentials = new SimpleCredentials("", "".toCharArray());
    Repository repository = (Repository) record(AbstractRepository.class);
    repository.login(credentials, null);
    replay();
    repository.login(credentials);
    verify();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Repository(javax.jcr.Repository) SimpleCredentials(javax.jcr.SimpleCredentials) 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