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.");
}
}
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();
}
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();
}
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;
}
}
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();
}
Aggregations