Search in sources :

Example 11 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class UserAccessControlProvider method init.

//----------------------------------------------< AccessControlProvider >---
/**
     * @see org.apache.jackrabbit.core.security.authorization.AccessControlProvider#init(Session, Map)
     */
@Override
public void init(Session systemSession, Map configuration) throws RepositoryException {
    super.init(systemSession, configuration);
    if (systemSession instanceof SessionImpl) {
        SessionImpl sImpl = (SessionImpl) systemSession;
        String userAdminName = (configuration.containsKey(USER_ADMIN_GROUP_NAME)) ? configuration.get(USER_ADMIN_GROUP_NAME).toString() : USER_ADMIN_GROUP_NAME;
        String groupAdminName = (configuration.containsKey(GROUP_ADMIN_GROUP_NAME)) ? configuration.get(GROUP_ADMIN_GROUP_NAME).toString() : GROUP_ADMIN_GROUP_NAME;
        // make sure the groups exist (and possibly create them).
        UserManager uMgr = sImpl.getUserManager();
        userAdminGroup = initGroup(uMgr, userAdminName);
        if (userAdminGroup != null && userAdminGroup instanceof ItemBasedPrincipal) {
            userAdminGroupPath = ((ItemBasedPrincipal) userAdminGroup).getPath();
        }
        groupAdminGroup = initGroup(uMgr, groupAdminName);
        if (groupAdminGroup != null && groupAdminGroup instanceof ItemBasedPrincipal) {
            groupAdminGroupPath = ((ItemBasedPrincipal) groupAdminGroup).getPath();
        }
        Principal administrators = initGroup(uMgr, SecurityConstants.ADMINISTRATORS_NAME);
        if (administrators != null && administrators instanceof ItemBasedPrincipal) {
            administratorsGroupPath = ((ItemBasedPrincipal) administrators).getPath();
        }
        usersPath = (uMgr instanceof UserManagerImpl) ? ((UserManagerImpl) uMgr).getUsersPath() : UserConstants.USERS_PATH;
        groupsPath = (uMgr instanceof UserManagerImpl) ? ((UserManagerImpl) uMgr).getGroupsPath() : UserConstants.GROUPS_PATH;
        membersInProperty = !(uMgr instanceof UserManagerImpl) || !((UserManagerImpl) uMgr).hasMemberSplitSize();
        if (configuration.containsKey(PARAM_ANONYMOUS_ID)) {
            anonymousId = (String) configuration.get(PARAM_ANONYMOUS_ID);
        } else {
            anonymousId = SecurityConstants.ANONYMOUS_ID;
        }
        if (configuration.containsKey(PARAM_ANONYMOUS_ACCESS)) {
            anonymousAccess = Boolean.parseBoolean((String) configuration.get(PARAM_ANONYMOUS_ACCESS));
        } else {
            anonymousAccess = true;
        }
    } else {
        throw new RepositoryException("SessionImpl (system session) expected.");
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) AnonymousPrincipal(org.apache.jackrabbit.core.security.AnonymousPrincipal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) Principal(java.security.Principal)

Example 12 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class GarbageCollectorTest method runGC.

private void runGC(Session session, boolean all) throws Exception {
    GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
    gc.setMarkEventListener(this);
    gc.setPersistenceManagerScan(false);
    if (gc.getDataStore() instanceof FileDataStore) {
        // make sure the file is old (access time resolution is 2 seconds)
        Thread.sleep(2000);
    }
    gc.mark();
    gc.stopScan();
    if (all) {
        gc.getDataStore().clearInUse();
    }
    gc.sweep();
    gc.close();
}
Also used : SessionImpl(org.apache.jackrabbit.core.SessionImpl) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Example 13 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class GarbageCollectorTest method testConcurrentGC.

public void testConcurrentGC() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    final SynchronousChannel sync = new SynchronousChannel();
    final Node node = root.addNode("slowBlob");
    final int blobLength = 1000;
    final ValueFactory vf = session.getValueFactory();
    new Thread() {

        public void run() {
            try {
                node.setProperty("slowBlob", vf.createBinary(new InputStream() {

                    int pos;

                    public int read() throws IOException {
                        pos++;
                        if (pos < blobLength) {
                            return pos % 80 == 0 ? '\n' : '.';
                        } else if (pos == blobLength) {
                            try {
                                sync.put("x");
                                // deleted
                                sync.take();
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            return 'x';
                        }
                        return -1;
                    }
                }));
                node.getSession().save();
                sync.put("saved");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
    assertEquals("x", sync.take());
    DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
    gc.setPersistenceManagerScan(false);
    gc.mark();
    gc.sweep();
    sync.put("deleted");
    assertEquals("saved", sync.take());
    InputStream in = node.getProperty("slowBlob").getBinary().getStream();
    for (int pos = 1; pos < blobLength; pos++) {
        int expected = pos % 80 == 0 ? '\n' : '.';
        assertEquals(expected, in.read());
    }
    assertEquals('x', in.read());
    in.close();
    gc.close();
}
Also used : InputStream(java.io.InputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) IOException(java.io.IOException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) SynchronousChannel(EDU.oswego.cs.dl.util.concurrent.SynchronousChannel) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector)

Example 14 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class GCThread method run.

public void run() {
    try {
        GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
        gc.setMarkEventListener(this);
        while (!stop) {
            LOG.debug("Scanning...");
            gc.mark();
            int count = listIdentifiers(gc);
            LOG.debug("Stop; currently " + count + " identifiers");
            gc.stopScan();
            int numDeleted = gc.sweep();
            if (numDeleted > 0) {
                LOG.debug("Deleted " + numDeleted + " identifiers");
            }
            LOG.debug("Waiting...");
            Thread.sleep(10);
        }
        gc.close();
    } catch (Exception ex) {
        LOG.error("Error scanning", ex);
        exception = ex;
    }
}
Also used : SessionImpl(org.apache.jackrabbit.core.SessionImpl) RepositoryException(javax.jcr.RepositoryException) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Example 15 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class GarbageCollectorTest method testCloseSessionWhileRunningGc.

public void testCloseSessionWhileRunningGc() throws Exception {
    final Session session = getHelper().getReadWriteSession();
    final DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
    gc.setPersistenceManagerScan(false);
    final Exception[] ex = new Exception[1];
    gc.setMarkEventListener(new MarkEventListener() {

        boolean closed;

        public void beforeScanning(Node n) throws RepositoryException {
            closeTest();
        }

        private void closeTest() {
            if (closed) {
                ex[0] = new Exception("Scanning after the session is closed");
            }
            closed = true;
            session.logout();
        }
    });
    try {
        gc.mark();
        fail("Exception 'session has been closed' expected");
    } catch (RepositoryException e) {
        LOG.debug("Expected exception caught: " + e.getMessage());
    }
    if (ex[0] != null) {
        throw ex[0];
    }
    gc.close();
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) MarkEventListener(org.apache.jackrabbit.api.management.MarkEventListener) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector)

Aggregations

SessionImpl (org.apache.jackrabbit.core.SessionImpl)63 RepositoryException (javax.jcr.RepositoryException)16 Node (javax.jcr.Node)12 Value (javax.jcr.Value)11 Name (org.apache.jackrabbit.spi.Name)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Session (javax.jcr.Session)9 NodeImpl (org.apache.jackrabbit.core.NodeImpl)8 NodeId (org.apache.jackrabbit.core.id.NodeId)8 Principal (java.security.Principal)7 DataStoreGarbageCollector (org.apache.jackrabbit.api.management.DataStoreGarbageCollector)7 NodeIterator (javax.jcr.NodeIterator)6 Privilege (javax.jcr.security.Privilege)6 UserManager (org.apache.jackrabbit.api.security.user.UserManager)6 Path (org.apache.jackrabbit.spi.Path)6 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)5 PathMap (org.apache.jackrabbit.spi.commons.name.PathMap)5 InvalidItemStateException (javax.jcr.InvalidItemStateException)4 LockException (javax.jcr.lock.LockException)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4