use of org.apache.jackrabbit.oak.api.ContentRepository in project jackrabbit-oak by apache.
the class SuggestionIntervalTest method createRepository.
@Override
protected ContentRepository createRepository() {
LuceneIndexProvider provider = new LuceneIndexProvider();
ContentRepository repository = new Oak().with(new InitialContent()).with(new OpenSecurityProvider()).with((QueryIndexProvider) provider).with((Observer) provider).with(new LuceneIndexEditorProvider()).createContentRepository();
clock = new Clock.Virtual();
try {
clock.waitUntil(System.currentTimeMillis());
} catch (Exception e) {
//eat exception if clock couldn't wait... that was just courteous anyway!
}
LuceneIndexEditorContext.setClock(clock);
return repository;
}
use of org.apache.jackrabbit.oak.api.ContentRepository in project jackrabbit-oak by apache.
the class UserInitializerTest method testAnonymousConfiguration.
/**
* @since OAK 1.0 The anonymous user is optional.
*/
@Test
public void testAnonymousConfiguration() throws Exception {
Map<String, Object> userParams = new HashMap();
userParams.put(UserConstants.PARAM_ANONYMOUS_ID, "");
ConfigurationParameters params = ConfigurationParameters.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams));
SecurityProvider sp = new SecurityProviderImpl(params);
final ContentRepository repo = new Oak().with(new InitialContent()).with(new PropertyIndexEditorProvider()).with(new PropertyIndexProvider()).with(new TypeEditorProvider()).with(sp).createContentRepository();
ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {
@Override
public ContentSession run() throws Exception {
return repo.login(null, null);
}
});
try {
Root root = cs.getLatestRoot();
UserConfiguration uc = sp.getConfiguration(UserConfiguration.class);
UserManager umgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
Authorizable anonymous = umgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
assertNull(anonymous);
} finally {
cs.close();
}
// login as admin should fail
ContentSession anonymousSession = null;
try {
anonymousSession = repo.login(new GuestCredentials(), null);
fail();
} catch (LoginException e) {
//success
} finally {
if (anonymousSession != null) {
anonymousSession.close();
}
}
}
use of org.apache.jackrabbit.oak.api.ContentRepository in project sling by apache.
the class RepositoryTestHelper method createOakRepository.
public static Repository createOakRepository(NodeStore nodeStore) {
DefaultWhiteboard whiteboard = new DefaultWhiteboard();
final Oak oak = new Oak(nodeStore).with(new InitialContent()).with(JcrConflictHandler.createJcrConflictHandler()).with(new EditorHook(new VersionEditorProvider())).with(new OpenSecurityProvider()).with(new NamespaceEditorProvider()).with(new TypeEditorProvider()).with(new ConflictValidatorProvider()).with(//getDefaultWorkspace())
"default").with(whiteboard);
// if (commitRateLimiter != null) {
// oak.with(commitRateLimiter);
// }
final ContentRepository contentRepository = oak.createContentRepository();
return new RepositoryImpl(contentRepository, whiteboard, new OpenSecurityProvider(), 1000, null);
}
use of org.apache.jackrabbit.oak.api.ContentRepository in project jackrabbit-oak by apache.
the class OakTest method testContentRepositoryReuse.
@Test
public void testContentRepositoryReuse() throws Exception {
Oak oak = new Oak().with(new OpenSecurityProvider());
ContentRepository r0 = null;
ContentRepository r1 = null;
try {
r0 = oak.createContentRepository();
r1 = oak.createContentRepository();
assertEquals(r0, r1);
} finally {
if (r0 != null) {
((Closeable) r0).close();
}
}
}
use of org.apache.jackrabbit.oak.api.ContentRepository in project jackrabbit-oak by apache.
the class OakTest method testWithDefaultWorkspaceName.
@Test
public void testWithDefaultWorkspaceName() throws Exception {
ContentRepository repo = new Oak().with("test").with(new OpenSecurityProvider()).createContentRepository();
String[] valid = new String[] { null, "test" };
for (String wspName : valid) {
ContentSession cs = null;
try {
cs = repo.login(null, wspName);
assertEquals("test", cs.getWorkspaceName());
} finally {
if (cs != null) {
cs.close();
}
}
}
String[] invalid = new String[] { "", "another", Oak.DEFAULT_WORKSPACE_NAME };
for (String wspName : invalid) {
ContentSession cs = null;
try {
cs = repo.login(null, wspName);
fail("invalid workspace nam");
} catch (NoSuchWorkspaceException e) {
// success
} finally {
if (cs != null) {
cs.close();
}
}
}
}
Aggregations