use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class AdminSiteHandler method doHandle.
@Override
protected WebResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) {
final WebResponse response = super.doHandle(webRequest, webResponse, webHandlerChain);
final PortalRequest request = PortalRequestAccessor.get(webRequest.getRawRequest());
final RenderMode mode = request.getMode();
if (mode == RenderMode.LIVE || request.getEndpointPath() != null) {
return response;
}
final PortalResponse.Builder builder = PortalResponse.create(response);
if (mode == RenderMode.INLINE || mode == RenderMode.EDIT) {
builder.header("X-Frame-Options", "SAMEORIGIN");
}
if (mode == RenderMode.EDIT) {
builder.removeHeader("Content-Security-Policy");
} else if (!nullToEmpty(previewContentSecurityPolicy).isBlank() && !response.getHeaders().containsKey("Content-Security-Policy")) {
builder.header("Content-Security-Policy", previewContentSecurityPolicy);
}
return builder.build();
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class AdminToolPortalHandler method createPortalRequest.
@Override
protected PortalRequest createPortalRequest(final WebRequest webRequest, final WebResponse webResponse) {
final PortalRequest portalRequest = new PortalRequest(webRequest);
final DescriptorKey descriptorKey = getDescriptorKey(webRequest);
if (descriptorKey == null) {
portalRequest.setBaseUri(ADMIN_TOOL_START);
portalRequest.setApplicationKey(DEFAULT_DESCRIPTOR_KEY.getApplicationKey());
} else {
portalRequest.setBaseUri(ADMIN_TOOL_PREFIX + descriptorKey.getApplicationKey() + "/" + descriptorKey.getName());
portalRequest.setApplicationKey(descriptorKey.getApplicationKey());
}
portalRequest.setMode(RenderMode.ADMIN);
return portalRequest;
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class AdminSiteHandlerTest method testInlineAssetRequest.
@Test
public void testInlineAssetRequest() {
this.request.setRawPath("/admin/site/inline/repo/draft/_/asset/com.enonic.app.superhero:1622131535374/css/style.css");
PortalRequest portalRequest = this.handler.createPortalRequest(this.request, this.response);
assertEquals("/admin/site/inline", portalRequest.getBaseUri());
assertEquals("com.enonic.cms.repo", portalRequest.getRepositoryId().toString());
assertEquals("draft", portalRequest.getBranch().toString());
assertEquals("/", portalRequest.getContentPath().toString());
assertEquals("inline", portalRequest.getMode().toString());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class WidgetHandlerTest method setup.
@BeforeEach
public final void setup() {
this.request = new PortalRequest();
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
this.controllerScript = Mockito.mock(ControllerScript.class);
Mockito.when(controllerScriptFactory.fromDir(Mockito.any())).thenReturn(this.controllerScript);
final PortalResponse portalResponse = PortalResponse.create().build();
Mockito.when(this.controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
this.contentService = Mockito.mock(ContentService.class);
this.widgetDescriptorService = Mockito.mock(WidgetDescriptorService.class);
this.handler = new WidgetHandler();
this.handler.setControllerScriptFactory(controllerScriptFactory);
this.handler.setWidgetDescriptorService(this.widgetDescriptorService);
HttpServletRequest rawRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(rawRequest.isUserInRole(Mockito.anyString())).thenReturn(Boolean.TRUE);
this.request.setRawRequest(rawRequest);
this.request.setMethod(HttpMethod.GET);
this.request.setContentPath(ContentPath.from("/site/somepath/content"));
this.request.setEndpointPath("/_/widgets/demo/mywidget");
this.request.setRawPath("/admin/tool/_/widgets/demo/mywidget");
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class AdminToolHandlerTest method setup.
@BeforeEach
public final void setup() throws Exception {
this.adminToolDescriptorService = Mockito.mock(AdminToolDescriptorService.class);
ControllerScript controllerScript = Mockito.mock(ControllerScript.class);
this.portalResponse = PortalResponse.create().build();
Mockito.when(controllerScript.execute(Mockito.any(PortalRequest.class))).thenReturn(this.portalResponse);
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
Mockito.when(controllerScriptFactory.fromDir(Mockito.any(ResourceKey.class))).thenReturn(controllerScript);
this.handler = new AdminToolHandler();
this.handler.setAdminToolDescriptorService(this.adminToolDescriptorService);
this.handler.setControllerScriptFactory(controllerScriptFactory);
this.rawRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(this.rawRequest.isUserInRole(Mockito.anyString())).thenReturn(true);
this.portalRequest = new PortalRequest();
this.portalRequest.setRawRequest(this.rawRequest);
this.portalRequest.setMode(RenderMode.ADMIN);
final DescriptorKey defaultDescriptorKey = AdminToolPortalHandler.DEFAULT_DESCRIPTOR_KEY;
this.portalRequest.setBaseUri(AdminToolPortalHandler.ADMIN_TOOL_PREFIX + defaultDescriptorKey.getApplicationKey() + "/" + defaultDescriptorKey.getName());
this.portalRequest.setApplicationKey(defaultDescriptorKey.getApplicationKey());
this.webResponse = WebResponse.create().build();
this.chain = Mockito.mock(WebHandlerChain.class);
}
Aggregations