Search in sources :

Example 96 with SimpleCredentials

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

the class PasswordForceInitialPasswordChangeTest method testAuthenticateMustChangePassword.

@Test
public void testAuthenticateMustChangePassword() throws Exception {
    Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
    try {
        a.authenticate(new SimpleCredentials(userId, userId.toCharArray()));
        fail("Credentials should be expired");
    } catch (CredentialExpiredException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) CredentialExpiredException(javax.security.auth.login.CredentialExpiredException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 97 with SimpleCredentials

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

the class PasswordExpiryTest method testAuthenticatePasswordExpired.

@Test
public void testAuthenticatePasswordExpired() throws Exception {
    Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
    // set password last modified to beginning of epoch
    root.getTree(getTestUser().getPath()).getChild(UserConstants.REP_PWD).setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED, 0);
    root.commit();
    try {
        a.authenticate(new SimpleCredentials(userId, userId.toCharArray()));
        fail("Credentials should be expired");
    } catch (CredentialExpiredException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) CredentialExpiredException(javax.security.auth.login.CredentialExpiredException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 98 with SimpleCredentials

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

the class ResetExpiredPasswordTest method authenticate.

private void authenticate(String expiredPw, Object newPw) throws LoginException {
    SimpleCredentials creds = new SimpleCredentials(userId, expiredPw.toCharArray());
    creds.setAttribute(UserConstants.CREDENTIALS_ATTRIBUTE_NEWPASSWORD, newPw);
    Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
    a.authenticate(creds);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication)

Example 99 with SimpleCredentials

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

the class RepositoryBootIT method repositoryLogin.

@Test
public void repositoryLogin() throws Exception {
    //Simple sanity test to see if repository is working
    Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
    session.logout();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Session(javax.jcr.Session) Test(org.junit.Test)

Example 100 with SimpleCredentials

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

the class ConcurrentAddNodesClusterIT method addNodes2.

@Test
public void addNodes2() throws Exception {
    for (int i = 0; i < 3; i++) {
        DocumentMK mk = new DocumentMK.Builder().setMongoDB(createConnection().getDB()).setAsyncDelay(0).setClusterId(i + 1).open();
        mks.add(mk);
    }
    final DocumentMK mk1 = mks.get(0);
    final DocumentMK mk2 = mks.get(1);
    final DocumentMK mk3 = mks.get(2);
    Repository r1 = new Jcr(mk1.getNodeStore()).createRepository();
    repos.add(r1);
    Repository r2 = new Jcr(mk2.getNodeStore()).createRepository();
    repos.add(r2);
    Repository r3 = new Jcr(mk3.getNodeStore()).createRepository();
    repos.add(r3);
    Session s1 = r1.login(new SimpleCredentials("admin", "admin".toCharArray()));
    Session s2 = r2.login(new SimpleCredentials("admin", "admin".toCharArray()));
    Session s3 = r3.login(new SimpleCredentials("admin", "admin".toCharArray()));
    ensureIndex(s1.getRootNode(), PROP_NAME);
    runBackgroundOps(mk1);
    runBackgroundOps(mk2);
    runBackgroundOps(mk3);
    // begin test
    Node root2 = s2.getRootNode().addNode("testroot-Worker-2", "nt:unstructured");
    createNodes(root2, "testnode0");
    s2.save();
    createNodes(root2, "testnode1");
    runBackgroundOps(mk1);
    runBackgroundOps(mk3);
    // publish 'testroot-Worker-2/testnode0'
    runBackgroundOps(mk2);
    Node root3 = s3.getRootNode().addNode("testroot-Worker-3", "nt:unstructured");
    createNodes(root3, "testnode0");
    s2.save();
    createNodes(root2, "testnode2");
    // sees 'testroot-Worker-2/testnode0'
    runBackgroundOps(mk1);
    // sees 'testroot-Worker-2/testnode0'
    runBackgroundOps(mk3);
    // publish 'testroot-Worker-2/testnode1'
    runBackgroundOps(mk2);
    // subsequent read on mk3 will read already published docs from mk2
    s3.save();
    createNodes(root3, "testnode1");
    Node root1 = s1.getRootNode().addNode("testroot-Worker-1", "nt:unstructured");
    createNodes(root1, "testnode0");
    s2.save();
    createNodes(root2, "testnode3");
    runBackgroundOps(mk1);
    runBackgroundOps(mk3);
    runBackgroundOps(mk2);
    s1.save();
    createNodes(root1, "testnode1");
    s3.save();
    createNodes(root3, "testnode2");
    runBackgroundOps(mk1);
    s1.save();
    s1.logout();
    s2.logout();
    s3.logout();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Repository(javax.jcr.Repository) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) Node(javax.jcr.Node) Session(javax.jcr.Session) Test(org.junit.Test)

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