Search in sources :

Example 21 with SimpleCredentials

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

the class CompatTokenProviderTest method testIsExpired.

public void testIsExpired() throws Exception {
    TokenInfo info = tokenProvider.createToken(testuser, new SimpleCredentials(userId, userId.toCharArray()));
    long loginTime = waitForSystemTimeIncrement(System.currentTimeMillis());
    assertFalse(info.isExpired(loginTime));
    assertTrue(info.isExpired(loginTime + TokenBasedAuthentication.TOKEN_EXPIRATION));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials)

Example 22 with SimpleCredentials

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

the class RemoveOrphanVersionHistoryTest method testWorkspaceRemoveOrphanVersionHistory.

/**
     * Test orphan version history cleaning in multiple workspace.
     * @throws RepositoryException if an error occurs.
     */
public void testWorkspaceRemoveOrphanVersionHistory() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    Session session = n.getSession();
    VersionHistory vh = n.getVersionHistory();
    String vhUuid = vh.getUUID();
    assertExists(session, vhUuid);
    // First version
    Version v10 = n.checkin();
    n.checkout();
    Workspace defaultWorkspace = n.getSession().getWorkspace();
    Session otherWsSession = n.getSession().getRepository().login(new SimpleCredentials("superuser", "".toCharArray()), workspaceName);
    // Clone the node in another workspace
    otherWsSession.getWorkspace().clone(defaultWorkspace.getName(), n.getPath(), n.getPath(), false);
    Node otherWsRootNode = otherWsSession.getRootNode();
    Node clonedNode = otherWsRootNode.getNode(n.getPath().substring(1));
    // Ensure that version histories are the same
    assertEquals(vhUuid, clonedNode.getVersionHistory().getUUID());
    Version v11 = clonedNode.checkin();
    clonedNode.checkout();
    // Remove node
    n.remove();
    testRootNode.save();
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove the first version
    vh.removeVersion(v10.getName());
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove cloned node
    clonedNode.remove();
    otherWsRootNode.save();
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove the last version
    vh.removeVersion(v11.getName());
    try {
        session.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed from the default workspace");
    } catch (ItemNotFoundException e) {
    // Expected
    }
    try {
        otherWsSession.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed from the other workspace");
    } catch (ItemNotFoundException e) {
    // Expected
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 23 with SimpleCredentials

use of javax.jcr.SimpleCredentials 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)

Example 24 with SimpleCredentials

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

the class UserTest method testChangePassword.

public void testChangePassword() throws RepositoryException, NotExecutableException {
    String oldPw = getHelper().getProperty("javax.jcr.tck.superuser.pwd");
    if (oldPw == null) {
        // missing property
        throw new NotExecutableException();
    }
    User user = getTestUser(superuser);
    try {
        user.changePassword("pw");
        save(superuser);
        // make sure the user can login with the new pw
        Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(), "pw".toCharArray()));
        s.logout();
    } finally {
        user.changePassword(oldPw);
        save(superuser);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 25 with SimpleCredentials

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

the class UserTest method testChangePasswordWithOldPassword2.

public void testChangePasswordWithOldPassword2() throws RepositoryException, NotExecutableException {
    String oldPw = getHelper().getProperty("javax.jcr.tck.superuser.pwd");
    if (oldPw == null) {
        // missing property
        throw new NotExecutableException();
    }
    User user = getTestUser(superuser);
    try {
        user.changePassword("pw", oldPw);
        save(superuser);
        Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(), oldPw.toCharArray()));
        s.logout();
        fail("superuser pw has changed. login must fail.");
    } catch (LoginException e) {
    // success
    } finally {
        user.changePassword(oldPw);
        save(superuser);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) LoginException(javax.jcr.LoginException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

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