Examples of SlingRepository


Examples of org.apache.sling.jcr.api.SlingRepository

   
    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;
View Full Code Here

Examples of org.apache.sling.jcr.api.SlingRepository

     */
    public static ResourceResolverFactory newResourceResolverFactory(final ResourceResolverType type) {
        ResourceResolverTypeAdapter adapter = getResourceResolverTypeAdapter(type);
        ResourceResolverFactory factory = adapter.newResourceResolverFactory();
        if (factory == null) {
            SlingRepository repository = adapter.newSlingRepository();
            if (repository == null) {
                throw new RuntimeException("Adapter neither provides resource resolver factory nor sling repository.");
            }
            factory = new MockJcrResourceResolverFactory(repository);
        }
View Full Code Here

Examples of org.apache.sling.jcr.api.SlingRepository

    @Override
    public DavLocatorFactory getLocatorFactory() {
        if (locatorFactory == null) {

            // configured default workspace name
            SlingRepository slingRepo = (SlingRepository) getRepository();
            String workspace = slingRepo.getDefaultWorkspace();

            // no configuration, try to login and acquire the default name
            if (workspace == null || workspace.length() == 0) {
                Session tmp = null;
                try {
                    tmp = slingRepo.login();
                    workspace = tmp.getWorkspace().getName();
                } catch (Throwable t) {
                    // TODO: log !!
                    workspace = "default"; // fall back name
                } finally {
View Full Code Here

Examples of org.apache.sling.jcr.api.SlingRepository

            // request to the "root", redirect to the default workspace if
            // directly addressing the servlet and if the default workspace name
            // is not null (in which case we'd need to login to find out the
            // actual workspace name, SLING-256)
            SlingRepository slingRepo = (SlingRepository) getRepository();
            if (slingRepo.getDefaultWorkspace() == null) {

                // if we don't have a default workspace to redirect to, we
                // cannot handle the request and fail with not found
                response.sendError(
                    HttpServletResponse.SC_NOT_FOUND,
                    "JCR workspace name required, please add it to the end of the URL"
                        + " (for the Jackrabbit embedded repository the default name is 'default') ");

            } else {

                // else redirect to the same URI with the default workspace
                // appended
                String uri = request.getRequestURI();
                if (pinfo == null) {
                    uri += "/";
                }
                uri += slingRepo.getDefaultWorkspace();
                response.sendRedirect(uri);

            }
        }
    }
View Full Code Here

Examples of org.apache.sling.jcr.api.SlingRepository

        when(workspace.getObservationManager()).thenReturn(observationManager);

        Session session = mock(Session.class);
        when(session.getWorkspace()).thenReturn(workspace);

        SlingRepository repository = mock(SlingRepository.class);
        when(repository.loginAdministrative(null)).thenReturn(session);

        EventAdmin eventAdmin = mock(EventAdmin.class);
        ServiceReference serviceRef = mock(ServiceReference.class);
        ServiceReference[] serviceRefs = new ServiceReference[]{serviceRef};
        BundleContext bundleContext = mock(BundleContext.class);
View Full Code Here

Examples of org.apache.sling.jcr.api.SlingRepository

    private Closeable listener;

    @Activate
    protected void activate(final ComponentContext context) throws RepositoryException {

        SlingRepository repository = (SlingRepository) context.locateService(REPOSITORY_REFERNENCE_NAME,
            this.repositoryReference);
        if (repository == null) {
            // concurrent unregistration of SlingRepository service
            // don't care, this component is going to be deactivated
            // so we just stop working
View Full Code Here

Examples of org.apache.sling.jcr.api.SlingRepository

                                ? (String) authenticationInfo.get(ResourceResolverFactory.SUBSERVICE)
                                : null;

                        final BundleContext bc = ((Bundle) serviceBundleObject).getBundleContext();

                        final SlingRepository repo = (SlingRepository) bc.getService(repositoryReference);
                        if (repo == null) {
                            log.warn(
                                "getResourceProviderInternal: Cannot login service because cannot get SlingRepository on behalf of bundle {} ({})",
                                bc.getBundle().getSymbolicName(), bc.getBundle().getBundleId());
                            throw new LoginException(); // TODO: correct ??
                        }

                        try {
                            session = repo.loginService(subServiceName, workspace);
                            holder.setRepositoryReference(bc, repositoryReference);
                            holder.setSession(session);
                        } finally {
                            // unget the repository if the service cannot
                            // login to it, otherwise the repository service
View Full Code Here

Examples of org.apache.sling.jcr.api.SlingRepository

    @Test
    public void testAuthenticateWithoutPath() throws Exception {
        String serviceName = "service";
        RepositoryTransportAuthenticationProvider repositoryTransportAuthenticationProvider = new RepositoryTransportAuthenticationProvider(serviceName);

        SlingRepository repo = mock(SlingRepository.class);
        TransportAuthenticationContext context = mock(TransportAuthenticationContext.class);
        try {
            repositoryTransportAuthenticationProvider.authenticate(repo, context);
            fail("cannot authenticate a null path");
        } catch (TransportAuthenticationException e) {
View Full Code Here

Examples of org.apache.sling.jcr.api.SlingRepository

    @Test
    public void testAuthenticateWithPathAndNoPrivilege() throws Exception {
        String serviceName = "service";
        RepositoryTransportAuthenticationProvider repositoryTransportAuthenticationProvider = new RepositoryTransportAuthenticationProvider(serviceName);

        SlingRepository repo = mock(SlingRepository.class);
        TransportAuthenticationContext context = new TransportAuthenticationContext();
        context.addAttribute("path", "/foo/bar");
        try {
            repositoryTransportAuthenticationProvider.authenticate(repo, context);
            fail("cannot authenticate a without privileges");
View Full Code Here

Examples of org.apache.sling.jcr.api.SlingRepository

        String path = "/foo/bar";
        context.addAttribute("path", path);
        String privilege = Privilege.JCR_WRITE;
        context.addAttribute("privilege", privilege);

        SlingRepository repo = mock(SlingRepository.class);
        Session authenticatedSession = mock(Session.class);
        when(authenticatedSession.hasPermission(path, privilege)).thenReturn(true);
        when(repo.loginService(serviceName, null)).thenReturn(authenticatedSession);

        RepositoryTransportAuthenticationProvider repositoryTransportAuthenticationProvider = new RepositoryTransportAuthenticationProvider(serviceName);
        Session session = repositoryTransportAuthenticationProvider.authenticate(repo, context);
        assertNotNull(session);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.