Search in sources :

Example 11 with SimpleCredentials

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

the class SessionImplTest method testSessionAttributes.

/**
     * JCR-1932: Session.getAttributes( ) call always returns an empty array
     *
     * @see <a href="https://issues.apache.org/jira/browse/JCR-1932">JCR-1932</a>
     */
public void testSessionAttributes() throws RepositoryException {
    SimpleCredentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
    credentials.setAttribute("test", "attribute");
    Session session = getHelper().getRepository().login(credentials);
    try {
        String[] names = session.getAttributeNames();
        assertEquals(1, names.length);
        assertEquals("test", names[0]);
        assertEquals("attribute", session.getAttribute("test"));
    } finally {
        session.logout();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 12 with SimpleCredentials

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

the class SimpleBench method test.

void test(int run) throws Exception {
    this.run = run;
    new File("target/jcr.log").delete();
    FileUtils.deleteQuietly(new File("repository"));
    start();
    repository = new TransientRepository();
    Session session = repository.login(new SimpleCredentials("", "".toCharArray()));
    if (session.getRootNode().hasNode("test")) {
        session.getRootNode().getNode("test").remove();
        session.save();
    }
    session.getRootNode().addNode("test");
    session.save();
    end("init");
    Node node = session.getRootNode().getNode("test");
    Node n = null;
    int len = run == 0 ? 100 : 1000;
    start();
    for (int i = 0; i < len; i++) {
        if (i % 100 == 0) {
            n = node.addNode("sub" + i);
        }
        Node x = n.addNode("x" + (i % 100));
        x.setProperty("name", "John");
        x.setProperty("firstName", "Doe");
        session.save();
    }
    end("addNodes");
    session.logout();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) File(java.io.File) Session(javax.jcr.Session)

Example 13 with SimpleCredentials

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

the class TokenBasedAuthenticationTest method testDoCreateToken.

public void testDoCreateToken() {
    assertFalse(TokenBasedAuthentication.doCreateToken(creds));
    assertFalse(TokenBasedAuthentication.doCreateToken(simpleCreds));
    assertFalse(TokenBasedAuthentication.doCreateToken(tokenCreds));
    SimpleCredentials sc = new SimpleCredentials("uid", "pw".toCharArray());
    sc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, null);
    assertFalse(TokenBasedAuthentication.doCreateToken(sc));
    sc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "somevalue");
    assertFalse(TokenBasedAuthentication.doCreateToken(sc));
    sc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "");
    assertTrue(TokenBasedAuthentication.doCreateToken(sc));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials)

Example 14 with SimpleCredentials

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

the class TokenBasedLoginTest method testConcurrentLoginOfDifferentUsers.

/**
     * Tests concurrent login of 3 different users on the Repository including
     * token creation.
     * Test copied and slightly adjusted from org.apache.jackrabbit.core.ConcurrentLoginTest
     */
public void testConcurrentLoginOfDifferentUsers() throws RepositoryException, NotExecutableException {
    final Exception[] exception = new Exception[1];
    List<Thread> testRunner = new ArrayList<Thread>();
    for (int i = 0; i < 10; i++) {
        testRunner.add(new Thread(new Runnable() {

            public void run() {
                for (int i = 0; i < 100; i++) {
                    try {
                        SimpleCredentials c;
                        double rand = 3 * Math.random();
                        int index = (int) Math.floor(rand);
                        switch(index) {
                            case 0:
                                c = new SimpleCredentials(testuser.getID(), testuser.getID().toCharArray());
                                break;
                            case 1:
                                c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_PWD).toCharArray());
                                break;
                            default:
                                c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_PWD).toCharArray());
                                break;
                        }
                        c.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "");
                        Session s = getHelper().getRepository().login(c);
                        try {
                            Set<TokenCredentials> tcs = ((SessionImpl) s).getSubject().getPublicCredentials(TokenCredentials.class);
                            assertFalse(tcs.isEmpty());
                        } finally {
                            s.logout();
                        }
                    } catch (Exception e) {
                        exception[0] = e;
                        break;
                    }
                }
            }
        }));
    }
    // start threads
    for (Object aTestRunner : testRunner) {
        ((Thread) aTestRunner).start();
    }
    // join threads
    for (Object aTestRunner : testRunner) {
        try {
            ((Thread) aTestRunner).join();
        } catch (InterruptedException e) {
            fail(e.toString());
        }
    }
    if (exception[0] != null) {
        fail(exception[0].toString());
    }
}
Also used : ArrayList(java.util.ArrayList) LoginException(javax.jcr.LoginException) RepositoryException(javax.jcr.RepositoryException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) SimpleCredentials(javax.jcr.SimpleCredentials) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)

Example 15 with SimpleCredentials

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

the class TokenProviderTest method testCreateTokenIsCaseInsensitive.

public void testCreateTokenIsCaseInsensitive() throws Exception {
    String upperCaseUserId = userId.toUpperCase();
    TokenInfo info = tokenProvider.createToken(testuser, new SimpleCredentials(upperCaseUserId, new char[0]));
    assertTokenInfo(info);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials)

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