Search in sources :

Example 6 with IdProviderControllerExecutionParams

use of com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams in project xp by enonic.

the class IdProviderControllerServiceImplTest method executeWithVirtualHost.

@Test
public void executeWithVirtualHost() throws IOException {
    final HttpServletRequest httpServletRequest = createHttpServletRequest();
    final VirtualHost virtualHost = Mockito.mock(VirtualHost.class);
    Mockito.when(virtualHost.getDefaultIdProviderKey()).thenReturn(IdProviderKey.from("myuserstore"));
    Mockito.when(virtualHost.getTarget()).thenReturn("/");
    Mockito.when(httpServletRequest.getAttribute(VirtualHost.class.getName())).thenReturn(virtualHost);
    VirtualHostHelper.setVirtualHost(httpServletRequest, virtualHost);
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().servletRequest(httpServletRequest).functionName("myfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNotNull(portalResponse);
    assertEquals(HttpStatus.OK, portalResponse.getStatus());
    assertEquals("myapplication/myfunction", portalResponse.getBody());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PortalResponse(com.enonic.xp.portal.PortalResponse) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) Test(org.junit.jupiter.api.Test)

Example 7 with IdProviderControllerExecutionParams

use of com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams in project xp by enonic.

the class IdProviderFilter method doHandle.

@Override
protected void doHandle(final HttpServletRequest req, final HttpServletResponse res, final FilterChain chain) throws Exception {
    // If the current user is not authenticated
    final AuthenticationInfo authInfo = ContextAccessor.current().getAuthInfo();
    if (!authInfo.isAuthenticated()) {
        // Executes the function autoLogin of the IdProvider
        IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().functionName("autoLogin").servletRequest(req).build();
        idProviderControllerService.execute(executionParams);
    }
    // Wraps the response to handle 403 errors
    final IdProviderResponseWrapper responseWrapper = new IdProviderResponseWrapper(idProviderControllerService, req, res);
    final IdProviderRequestWrapper requestWrapper = new IdProviderRequestWrapper(req);
    chain.doFilter(requestWrapper, responseWrapper);
}
Also used : AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams)

Example 8 with IdProviderControllerExecutionParams

use of com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams in project xp by enonic.

the class IdProviderControllerServiceImplTest method executeMissingIdProvider.

@Test
public void executeMissingIdProvider() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("missingidprovider")).functionName("missingfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNull(portalResponse);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) PortalRequest(com.enonic.xp.portal.PortalRequest) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) Test(org.junit.jupiter.api.Test)

Example 9 with IdProviderControllerExecutionParams

use of com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams in project xp by enonic.

the class IdProviderControllerServiceImplTest method executeMissingFunction.

@Test
public void executeMissingFunction() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("myemptyidprovider")).functionName("missingfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNull(portalResponse);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) PortalRequest(com.enonic.xp.portal.PortalRequest) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) Test(org.junit.jupiter.api.Test)

Example 10 with IdProviderControllerExecutionParams

use of com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams in project xp by enonic.

the class IdentityHandlerWorker method execute.

@Override
public PortalResponse execute() throws Exception {
    final ContentResolverResult resolvedContent = contentResolver.resolve(this.request);
    this.request.setContent(resolvedContent.getContent());
    this.request.setSite(resolvedContent.getNearestSite());
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().idProviderKey(idProviderKey).functionName(idProviderFunction).portalRequest(this.request).build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    if (portalResponse == null) {
        throw WebException.notFound(String.format("ID Provider function [%s] not found for id provider [%s]", idProviderFunction, idProviderKey));
    } else {
        return portalResponse;
    }
}
Also used : ContentResolverResult(com.enonic.xp.portal.impl.ContentResolverResult) PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams)

Aggregations

IdProviderControllerExecutionParams (com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams)10 PortalResponse (com.enonic.xp.portal.PortalResponse)7 AbstractControllerTest (com.enonic.xp.portal.impl.controller.AbstractControllerTest)6 Test (org.junit.jupiter.api.Test)6 PortalRequest (com.enonic.xp.portal.PortalRequest)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ContentService (com.enonic.xp.content.ContentService)1 IdProviderControllerService (com.enonic.xp.portal.idprovider.IdProviderControllerService)1 ContentResolverResult (com.enonic.xp.portal.impl.ContentResolverResult)1 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)1 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)1 IOException (java.io.IOException)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1