Search in sources :

Example 31 with Credentials

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

the class UserImplTest method testGetCredentials.

@Test
public void testGetCredentials() throws Exception {
    user = userMgr.createUser(uid, uid);
    root.commit();
    Credentials creds = user.getCredentials();
    assertTrue(creds instanceof CredentialsImpl);
    CredentialsImpl cImpl = (CredentialsImpl) creds;
    assertEquals(uid, cImpl.getUserId());
    assertTrue(PasswordUtil.isSame(cImpl.getPasswordHash(), uid));
}
Also used : UserIdCredentials(org.apache.jackrabbit.oak.spi.security.user.UserIdCredentials) Credentials(javax.jcr.Credentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 32 with Credentials

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

the class L11_PasswordTest method testCreateUserWithoutPasswordAndLogin.

public void testCreateUserWithoutPasswordAndLogin() throws RepositoryException {
    testUser = userManager.createUser(testId, null);
    superuser.save();
    // EXERCISE: build the credentials and fix the test-case such that it no longer fails
    Credentials creds = null;
    getHelper().getRepository().login(creds).logout();
}
Also used : Credentials(javax.jcr.Credentials)

Example 33 with Credentials

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

the class L13_SystemUserTest method testGetCredentials.

@Test
public void testGetCredentials() throws RepositoryException {
    // EXERCISE look at the Credentials object returned from the system user and compare it with the result from PasswordTest#getCredentials()
    Credentials creds = systemUser.getCredentials();
    // EXERCISE fix the expectation
    Credentials expected = null;
    assertEquals(expected, creds);
}
Also used : Credentials(javax.jcr.Credentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) L3_PrecedenceRulesTest(org.apache.jackrabbit.oak.exercise.security.authorization.permission.L3_PrecedenceRulesTest) Test(org.junit.Test)

Example 34 with Credentials

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

the class CompositeTokenProviderTest method testNullProvider.

@Test
public void testNullProvider() {
    TokenProvider tp = CompositeTokenProvider.newInstance();
    assertSame(tp, CompositeTokenProvider.newInstance(ImmutableList.<TokenProvider>of()));
    Credentials creds = new Credentials() {
    };
    assertFalse(tp.doCreateToken(null));
    assertFalse(tp.doCreateToken(creds));
    assertNull(tp.createToken(null, null));
    assertNull(tp.createToken("userID", ImmutableMap.<String, String>of()));
    assertNull(tp.createToken(null));
    assertNull(tp.createToken(creds));
    assertNull(tp.getTokenInfo(null));
    assertNull(tp.getTokenInfo("anyString"));
}
Also used : GuestCredentials(javax.jcr.GuestCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Example 35 with Credentials

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

the class OakServlet method service.

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        Credentials credentials = null;
        String authorization = request.getHeader("Authorization");
        if (authorization != null && authorization.startsWith("Basic ")) {
            String[] basic = Base64.decode(authorization.substring("Basic ".length())).split(":");
            credentials = new SimpleCredentials(basic[0], basic[1].toCharArray());
        } else {
            throw new LoginException();
        }
        ContentSession session = repository.login(credentials, null);
        try {
            Root root = session.getLatestRoot();
            request.setAttribute("root", root);
            // Find the longest part of the given path that matches
            // an existing node. The tail part might be used when
            // creating new nodes or when exposing virtual resources.
            // Note that we need to traverse the path in reverse
            // direction as some parent nodes may be read-protected.
            String head = request.getPathInfo();
            String tail = "";
            Tree tree = root.getTree(head);
            while (!tree.exists()) {
                if (tree.isRoot()) {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return;
                }
                tail = "/" + tree.getName() + tail;
                tree = tree.getParent();
            }
            request.setAttribute("tree", tree);
            request.setAttribute("path", tail);
            super.service(request, response);
        } finally {
            session.close();
        }
    } catch (NoSuchWorkspaceException e) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } catch (LoginException e) {
        response.setHeader("WWW-Authenticate", "Basic realm=\"Oak\"");
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) SimpleCredentials(javax.jcr.SimpleCredentials) Root(org.apache.jackrabbit.oak.api.Root) LoginException(javax.security.auth.login.LoginException) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) 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