Search in sources :

Example 41 with Credentials

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

the class AuthenticationInfoTest method testGetCredentials.

@Test
public void testGetCredentials() {
    final AuthenticationInfo info = new AuthenticationInfo("test");
    assertNull(info.get(CREDENTIALS));
    assertFalse(info.containsKey(CREDENTIALS));
    final Credentials creds = new SimpleCredentials("user", new char[0]);
    info.put(CREDENTIALS, creds);
    assertSame(creds, info.get(CREDENTIALS));
    final String user = "user";
    final char[] pwd = new char[5];
    final AuthenticationInfo infoCred = new AuthenticationInfo("TEST", user, pwd);
    // credentials not stored in the object
    assertFalse(infoCred.containsKey(CREDENTIALS));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Example 42 with Credentials

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

the class AuthenticationInfoTest method testSetCredentials.

@Test
public void testSetCredentials() {
    final Credentials creds = new SimpleCredentials("user", new char[0]);
    final AuthenticationInfo info = new AuthenticationInfo("test");
    info.put(CREDENTIALS, creds);
    Assert.assertSame(creds, info.get(CREDENTIALS));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) Test(org.junit.Test)

Example 43 with Credentials

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

the class SystemUsersTest method assertSystemUser.

private void assertSystemUser(String name) throws RepositoryException {
    final SlingRepository repo = teleporter.getService(SlingRepository.class);
    final Session s = repo.loginAdministrative(null);
    try {
        final Credentials creds = new SimpleCredentials(name, new char[] {});
        try {
            s.impersonate(creds);
        } catch (RepositoryException rex) {
            fail("Impersonation as " + name + " failed: " + rex.toString());
        }
    } finally {
        s.logout();
    }
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) SimpleCredentials(javax.jcr.SimpleCredentials) RepositoryException(javax.jcr.RepositoryException) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

Example 44 with Credentials

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

the class DefaultLoginModule method commit.

//--------------------------------------------------------< LoginModule >---
/**
     * @see javax.security.auth.spi.LoginModule#commit()
     */
@Override
public boolean commit() throws LoginException {
    boolean success = super.commit();
    if (success && !disableTokenAuth) {
        if (TokenBasedAuthentication.doCreateToken(credentials)) {
            Session s = null;
            try {
                /*
                    use a different session instance to create the token
                    node in order to prevent concurrent modifications with
                    the shared system session.
                    */
                s = session.createSession(session.getWorkspace().getName());
                Credentials tc = TokenBasedAuthentication.createToken(user, credentials, tokenExpiration, s);
                if (tc != null) {
                    subject.getPublicCredentials().add(tc);
                }
            } catch (RepositoryException e) {
                LoginException le = new LoginException("Failed to commit: " + e.getMessage());
                le.initCause(e);
                throw le;
            } finally {
                if (s != null) {
                    s.logout();
                }
            }
        } else if (tokenCredentials != null) {
            subject.getPublicCredentials().add(tokenCredentials);
        }
    }
    return success;
}
Also used : LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) RepositoryException(javax.jcr.RepositoryException) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

Example 45 with Credentials

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

the class GarbageCollectorTest method testTransientObjects.

public void testTransientObjects() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    deleteMyNodes();
    Credentials cred = getHelper().getSuperuserCredentials();
    Session s2 = getHelper().getRepository().login(cred);
    root = s2.getRootNode();
    Node node2 = root.addNode("node3");
    Node n = node2.addNode("nodeWithBlob");
    ValueFactory vf = session.getValueFactory();
    n.setProperty("test", vf.createBinary(new RandomInputStream(10, 1000)));
    runGC(session, false);
    s2.save();
    InputStream in = n.getProperty("test").getBinary().getStream();
    InputStream in2 = new RandomInputStream(10, 1000);
    verifyInputStream(in, in2);
    deleteMyNodes();
    s2.logout();
}
Also used : InputStream(java.io.InputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

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