Search in sources :

Example 96 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class L4_PrivilegesAndPermissionsTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Property p = testRootNode.setProperty(propertyName1, "val");
    propertyPath = p.getPath();
    Node child = testRootNode.addNode(nodeName1);
    childPath = child.getPath();
    p = child.setProperty(propertyName2, "val");
    childPropertyPath = p.getPath();
    Node grandChild = child.addNode(nodeName2);
    grandChildPath = grandChild.getPath();
    testUser = ExerciseUtility.createTestUser(((JackrabbitSession) superuser).getUserManager());
    Group testGroup = ExerciseUtility.createTestGroup(((JackrabbitSession) superuser).getUserManager());
    testGroup.addMember(testUser);
    superuser.save();
    testPrincipal = testUser.getPrincipal();
    testGroupPrincipal = testGroup.getPrincipal();
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) Node(javax.jcr.Node) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Property(javax.jcr.Property)

Example 97 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class AbstractRandomizedTest method clearAuthorizables.

protected void clearAuthorizables() throws RepositoryException {
    for (JackrabbitSession s : writeSessions) {
        UserManager userManager = s.getUserManager();
        for (String id : ids) {
            Authorizable a = userManager.getAuthorizable(id);
            if (a != null) {
                a.remove();
            }
        }
        s.save();
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 98 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class RandomizedReadTest method setupPermissions.

private void setupPermissions(int principalIndex, String path, boolean allow, String... privilegeNames) throws Exception {
    for (JackrabbitSession session : writeSessions) {
        Principal principal = getPrincipal(session, principalIndex);
        AccessControlManager acm = session.getAccessControlManager();
        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acm, path);
        acl.addEntry(principal, AccessControlUtils.privilegesFromNames(acm, privilegeNames), allow);
        acm.setPolicy(path, acl);
        session.save();
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Principal(java.security.Principal)

Example 99 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class AbstractImportTest method before.

@Before
public void before() throws Exception {
    ConfigurationParameters config = getConfigurationParameters();
    if (config != null) {
        securityProvider = new SecurityProviderImpl(config);
    } else {
        securityProvider = new SecurityProviderImpl();
    }
    QueryEngineSettings queryEngineSettings = new QueryEngineSettings();
    queryEngineSettings.setFailTraversal(true);
    Jcr jcr = new Jcr();
    jcr.with(securityProvider);
    jcr.with(queryEngineSettings);
    repo = jcr.createRepository();
    adminSession = repo.login(new SimpleCredentials(UserConstants.DEFAULT_ADMIN_ID, UserConstants.DEFAULT_ADMIN_ID.toCharArray()));
    if (!(adminSession instanceof JackrabbitSession)) {
        throw new NotExecutableException();
    }
    userMgr = ((JackrabbitSession) adminSession).getUserManager();
    preTestAuthorizables.clear();
    Iterator<Authorizable> iter = userMgr.findAuthorizables("rep:principalName", null);
    while (iter.hasNext()) {
        String id = iter.next().getID();
        preTestAuthorizables.add(id);
    }
    // make sure the target node for group-import exists
    Authorizable administrators = userMgr.getAuthorizable(ADMINISTRATORS);
    if (userMgr.getAuthorizable(ADMINISTRATORS) == null) {
        userMgr.createGroup(new PrincipalImpl(ADMINISTRATORS));
    } else if (!administrators.isGroup()) {
        throw new NotExecutableException("Expected " + administrators.getID() + " to be a group.");
    }
    adminSession.save();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Before(org.junit.Before)

Example 100 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class SystemUserImportTest method testExistingPrincipal.

@Test
public void testExistingPrincipal() throws Exception {
    Principal existing = null;
    Session s = getImportSession();
    PrincipalIterator principalIterator = ((JackrabbitSession) s).getPrincipalManager().getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
    while (principalIterator.hasNext()) {
        Principal p = principalIterator.nextPrincipal();
        if (getUserManager().getAuthorizable(p) != null) {
            existing = p;
            break;
        }
    }
    if (existing == null) {
        throw new NotExecutableException();
    }
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:SystemUser</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>" + existing.getName() + "</sv:value></sv:property>" + "</sv:node>";
    try {
        doImport(getTargetPath(), xml);
        s.save();
        fail("Import must detect conflicting principals.");
    } catch (RepositoryException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) RepositoryException(javax.jcr.RepositoryException) Principal(java.security.Principal) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Aggregations

JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)114 UserManager (org.apache.jackrabbit.api.security.user.UserManager)51 Session (javax.jcr.Session)50 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)34 Node (javax.jcr.Node)25 Group (org.apache.jackrabbit.api.security.user.Group)25 User (org.apache.jackrabbit.api.security.user.User)24 Principal (java.security.Principal)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)17 Test (org.junit.Test)16 SimpleCredentials (javax.jcr.SimpleCredentials)15 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)11 RepositoryException (javax.jcr.RepositoryException)10 PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)9 PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)9 Privilege (javax.jcr.security.Privilege)8 LoginException (javax.jcr.LoginException)6 Property (javax.jcr.Property)6 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)6 Item (javax.jcr.Item)5