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());
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations