use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class OakVirtualInstanceBuilder method createNewRepository.
@Override
public VirtualInstanceBuilder createNewRepository() throws Exception {
nodeStore = new MemoryNodeStore();
SlingRepository repository = RepositoryTestHelper.newOakRepository(nodeStore);
factory = MockFactory.mockResourceResolverFactory(repository);
leaseCollection = new SimulatedLeaseCollection();
return this;
}
use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class DefaultLoginsHealthCheckTest method getTestResult.
private Result getTestResult(String login) throws Exception {
final DefaultLoginsHealthCheck c = new DefaultLoginsHealthCheck();
SetField.set(c, "logins", Arrays.asList(new String[] { login }));
final SlingRepository repo = Mockito.mock(SlingRepository.class);
SetField.set(c, "repository", repo);
final Session s = Mockito.mock(Session.class);
Mockito.when(repo.login(Matchers.any(Credentials.class))).thenAnswer(new Answer<Session>() {
@Override
public Session answer(InvocationOnMock invocation) {
final SimpleCredentials c = (SimpleCredentials) invocation.getArguments()[0];
if ("admin".equals(c.getUserID())) {
return s;
}
return null;
}
});
return c.execute();
}
use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class AbstractSlingRepositoryManager method initializeAndRegisterRepositoryService.
private void initializeAndRegisterRepositoryService() {
Throwable t = null;
try {
log.debug("start: calling acquireRepository()");
Repository newRepo = this.acquireRepository();
if (newRepo != null) {
// ensure we really have the repository
log.debug("start: got a Repository");
this.repository = newRepo;
synchronized (this.repoInitLock) {
this.masterSlingRepository = this.create(this.bundleContext.getBundle());
log.debug("start: setting up Loader");
this.loader = new Loader(this.masterSlingRepository, this.bundleContext);
log.debug("start: calling SlingRepositoryInitializer");
try {
executeRepositoryInitializers(this.masterSlingRepository);
} catch (Throwable e) {
t = e;
log.error("Exception in a SlingRepositoryInitializer, SlingRepository service registration aborted", t);
}
log.debug("start: calling registerService()");
this.repositoryService = registerService();
log.debug("start: registerService() successful, registration=" + repositoryService);
}
}
} catch (Throwable e) {
// consider an uncaught problem an error
log.error("start: Uncaught Throwable trying to access Repository, calling stopRepository()", e);
t = e;
} finally {
if (t != null) {
// repository might be partially started, stop anything left
stop();
}
}
}
use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class MockResolverProvider method getResourceResolver.
public static ResourceResolver getResourceResolver() throws RepositoryException, LoginException {
final SlingRepository repository = RepositoryProvider.instance().getRepository();
final BundleContext bundleContext = MockOsgi.newBundleContext();
bundleContext.registerService(PathMapper.class.getName(), new PathMapper(), null);
return new MockJcrResourceResolverFactory(repository, bundleContext).getAdministrativeResourceResolver(null);
}
use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class JcrProviderStateFactory method createProviderState.
@SuppressWarnings("deprecation")
JcrProviderState createProviderState(@Nonnull final Map<String, Object> authenticationInfo) throws LoginException {
boolean isLoginAdministrative = Boolean.TRUE.equals(authenticationInfo.get(ResourceProvider.AUTH_ADMIN));
// check whether a session is provided in the authenticationInfo
Session session = getSession(authenticationInfo);
if (session != null && !isLoginAdministrative) {
// was provided in the authenticationInfo
return createJcrProviderState(session, false, authenticationInfo, null);
}
BundleContext bc = null;
try {
final Bundle bundle = extractCallingBundle(authenticationInfo);
if (bundle != null) {
bc = bundle.getBundleContext();
final SlingRepository repo = bc.getService(repositoryReference);
if (repo == null) {
logger.warn("Cannot login {} because cannot get SlingRepository on behalf of bundle {} ({})", isLoginAdministrative ? "admin" : "service", bundle.getSymbolicName(), bundle.getBundleId());
// TODO: correct ??
throw new LoginException("Repository unavailable");
}
try {
if (isLoginAdministrative) {
session = repo.loginAdministrative(null);
} else {
final Object subService = authenticationInfo.get(ResourceResolverFactory.SUBSERVICE);
final String subServiceName = subService instanceof String ? (String) subService : null;
session = repo.loginService(subServiceName, null);
}
} catch (Throwable t) {
// closed and the session logged out
if (session == null) {
bc.ungetService(repositoryReference);
}
throw t;
}
} else if (isLoginAdministrative) {
throw new LoginException("Calling bundle missing in authentication info");
} else {
// requested non-admin session
final Credentials credentials = getCredentials(authenticationInfo);
session = repository.login(credentials, null);
}
} catch (final RepositoryException re) {
throw getLoginException(re);
}
return createJcrProviderState(session, true, authenticationInfo, bc);
}
Aggregations