Search in sources :

Example 36 with GuestCredentials

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

the class CompatibilityIssuesTest method testSearchDescendentUsingXPath.

@Test
public void testSearchDescendentUsingXPath() throws Exception {
    Session adminSession = getAdminSession();
    String testNodePath = "/home/users/geometrixx-outdoors/emily.andrews@mailinator.com/social/relationships/following/aaron.mcdonald@mailinator.com";
    Node testNode = JcrUtils.getOrCreateByPath(testNodePath, null, adminSession);
    testNode.setProperty("id", "aaron.mcdonald@mailinator.com");
    AccessControlManager acMgr = adminSession.getAccessControlManager();
    JackrabbitAccessControlList tmpl = AccessControlUtils.getAccessControlList(acMgr, "/home/users/geometrixx-outdoors");
    ValueFactory vf = adminSession.getValueFactory();
    Map<String, Value> restrictions = new HashMap<String, Value>();
    restrictions.put("rep:glob", vf.createValue("*/social/relationships/following/*"));
    tmpl.addEntry(EveryonePrincipal.getInstance(), new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ) }, true, restrictions);
    acMgr.setPolicy(tmpl.getPath(), tmpl);
    adminSession.save();
    Session anonymousSession = getRepository().login(new GuestCredentials());
    QueryManager qm = anonymousSession.getWorkspace().getQueryManager();
    Query q = qm.createQuery("/jcr:root/home//social/relationships/following//*[@id='aaron.mcdonald@mailinator.com']", Query.XPATH);
    QueryResult r = q.execute();
    RowIterator it = r.getRows();
    Assert.assertTrue(it.hasNext());
    anonymousSession.logout();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Query(javax.jcr.query.Query) HashMap(java.util.HashMap) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Value(javax.jcr.Value) QueryManager(javax.jcr.query.QueryManager) GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session) Test(org.junit.Test)

Example 37 with GuestCredentials

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

the class PreAuthDefaultExternalLoginModuleTest method testGuest.

@Test
public void testGuest() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(new GuestCredentials());
        assertEquals(UserConstants.DEFAULT_ANONYMOUS_ID, cs.getAuthInfo().getUserID());
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) GuestCredentials(javax.jcr.GuestCredentials) Test(org.junit.Test)

Example 38 with GuestCredentials

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

the class AbstractLoginTest method buildCredentials.

private Credentials buildCredentials(Repository repository, Credentials credentials) throws RepositoryException {
    Credentials creds;
    if ("admin".equals(runAsUser)) {
        creds = credentials;
    } else if ("anonymous".equals(runAsUser)) {
        creds = new GuestCredentials();
    } else {
        creds = new SimpleCredentials(USER, USER.toCharArray());
    }
    if (runWithToken) {
        Configuration.setConfiguration(ConfigurationUtil.getJackrabbit2Configuration(ConfigurationParameters.EMPTY));
        if (creds instanceof SimpleCredentials) {
            SimpleCredentials sc = (SimpleCredentials) creds;
            sc.setAttribute(".token", "");
            repository.login(sc).logout();
            creds = new TokenCredentials(sc.getAttribute(".token").toString());
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return creds;
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)

Example 39 with GuestCredentials

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

the class CugPermissionProviderTest method testIsGrantedNonExistingLocation.

/**
     * @see org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider#isGranted(org.apache.jackrabbit.oak.plugins.tree.TreeLocation, long)
     */
@Test
public void testIsGrantedNonExistingLocation() throws Exception {
    ContentSession anonymous = login(new GuestCredentials());
    try {
        // additionally create a root that doesn't have access to the root node
        Root anonymousRoot = anonymous.getLatestRoot();
        for (Root r : new Root[] { anonymousRoot, root }) {
            TreeLocation location = TreeLocation.create(r, "/path/to/non/existing/tree");
            assertFalse(cugPermProvider.isGranted(location, Permissions.READ));
            assertFalse(cugPermProvider.isGranted(location, Permissions.READ_NODE));
            assertFalse(cugPermProvider.isGranted(location, Permissions.READ_PROPERTY));
            assertFalse(cugPermProvider.isGranted(location, Permissions.ALL));
            assertFalse(cugPermProvider.isGranted(location, Permissions.ADD_NODE));
            assertFalse(cugPermProvider.isGranted(location, Permissions.READ_ACCESS_CONTROL));
        }
    } finally {
        anonymous.close();
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) GuestCredentials(javax.jcr.GuestCredentials) Test(org.junit.Test)

Aggregations

GuestCredentials (javax.jcr.GuestCredentials)39 Test (org.junit.Test)25 SimpleCredentials (javax.jcr.SimpleCredentials)13 Credentials (javax.jcr.Credentials)12 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)12 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)10 Session (javax.jcr.Session)8 LoginException (javax.security.auth.login.LoginException)7 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Subject (javax.security.auth.Subject)4 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)4 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)4 ArrayList (java.util.ArrayList)3 Repository (javax.jcr.Repository)3 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)3 Map (java.util.Map)2 RepositoryException (javax.jcr.RepositoryException)2 AccessControlManager (javax.jcr.security.AccessControlManager)2