Search in sources :

Example 1 with IdProviderControllerExecutionParams

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

the class IdProviderResponseWrapper method handleError.

private void handleError(final int sc) {
    if (!errorHandled && isUnauthorizedError(sc) && !isErrorAlreadyHandled()) {
        try {
            final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().functionName("handle401").servletRequest(request).response(response).build();
            final boolean responseSerialized = idProviderControllerService.execute(executionParams) != null;
            if (responseSerialized) {
                errorHandled = true;
            }
        } catch (IOException e) {
            throw Exceptions.unchecked(e);
        }
    }
}
Also used : IOException(java.io.IOException) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams)

Example 2 with IdProviderControllerExecutionParams

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

the class IdentityHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.request = new PortalRequest();
    final ContentService contentService = Mockito.mock(ContentService.class);
    final IdProviderControllerService idProviderControllerService = Mockito.mock(IdProviderControllerService.class);
    final HttpServletRequest rawRequest = Mockito.mock(HttpServletRequest.class);
    Mockito.when(idProviderControllerService.execute(Mockito.any())).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        final IdProviderControllerExecutionParams arg = (IdProviderControllerExecutionParams) args[0];
        if (IdProviderKey.from("myidprovider").equals(arg.getIdProviderKey()) && "get".equals(arg.getFunctionName())) {
            return PortalResponse.create().build();
        }
        return null;
    });
    this.handler = new IdentityHandler();
    this.handler.setContentService(contentService);
    this.handler.setIdProviderControllerService(idProviderControllerService);
    this.request.setMethod(HttpMethod.GET);
    this.request.setEndpointPath("/_/idprovider/myidprovider?param1=value1");
    this.request.setRawPath("/site/draft/_/idprovider/myidprovider?param1=value1");
    this.request.setRawRequest(rawRequest);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IdProviderControllerService(com.enonic.xp.portal.idprovider.IdProviderControllerService) ContentService(com.enonic.xp.content.ContentService) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with IdProviderControllerExecutionParams

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

the class IdProviderControllerServiceImplTest method executeWithoutVirtualHost.

@Test
public void executeWithoutVirtualHost() throws IOException {
    final HttpServletRequest httpServletRequest = createHttpServletRequest();
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().servletRequest(httpServletRequest).functionName("myfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNull(portalResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) Test(org.junit.jupiter.api.Test)

Example 4 with IdProviderControllerExecutionParams

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

the class IdProviderControllerServiceImplTest method executeIdProviderWithoutApplication.

@Test
public void executeIdProviderWithoutApplication() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("myemptyidprovider")).functionName("myfunction").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 5 with IdProviderControllerExecutionParams

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

the class IdProviderControllerServiceImplTest method execute.

@Test
public void execute() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("myidprovider")).functionName("myfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNotNull(portalResponse);
    assertEquals(HttpStatus.OK, portalResponse.getStatus());
    assertEquals("myapplication/myfunction", portalResponse.getBody());
}
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)

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