RequestSecurityManagerImpl implements RequestSecurityManager { public boolean checkForInsecurePageRenderRequest(PageRenderRequestParameters parameters) throws IOException { if (!needsRedirect(parameters.getLogicalPageName())) return false; Link link = componentEventLinkEncoder.createPageRenderLink(parameters); response.sendRedirect(link); return true; } RequestSecurityManagerImpl(Request request, Response response,
                                      ComponentEventLinkEncoder componentEventLinkEncoder, MetaDataLocator locator, @Symbol(SymbolConstants.SECURE_ENABLED)
    boolean securityEnabled); boolean checkForInsecureComponentEventRequest(ComponentEventRequestParameters parameters); boolean checkForInsecurePageRenderRequest(PageRenderRequestParameters parameters); LinkSecurity checkPageSecurity(String pageName);  }
@Test public void check_request_is_secure() throws Exception { Request request = mockRequest(); Response response = mockResponse(); MetaDataLocator locator = mockMetaDataLocator(); ComponentEventLinkEncoder encoder = newMock(ComponentEventLinkEncoder.class); train_isSecure(request, true); replay(); PageRenderRequestParameters parameters = new PageRenderRequestParameters(PAGE_NAME, new EmptyEventContext(), false); RequestSecurityManager manager = new RequestSecurityManagerImpl(request, response, encoder, locator, true); assertFalse(manager.checkForInsecurePageRenderRequest(parameters)); verify(); }
@Test public void check_page_not_secure() throws Exception { Request request = mockRequest(); Response response = mockResponse(); MetaDataLocator locator = mockMetaDataLocator(); ComponentEventLinkEncoder encoder = newMock(ComponentEventLinkEncoder.class); train_isSecure(request, false); train_isSecure(locator, PAGE_NAME, false); replay(); PageRenderRequestParameters parameters = new PageRenderRequestParameters(PAGE_NAME, new EmptyEventContext(), false); RequestSecurityManager manager = new RequestSecurityManagerImpl(request, response, encoder, locator, true); assertFalse(manager.checkForInsecurePageRenderRequest(parameters)); verify(); }
@Test public void check_redirect_needed() throws Exception { Request request = mockRequest(); Response response = mockResponse(); MetaDataLocator locator = mockMetaDataLocator(); Link link = mockLink(); ComponentEventLinkEncoder encoder = newMock(ComponentEventLinkEncoder.class); train_isSecure(request, false); train_isSecure(locator, PAGE_NAME, true); PageRenderRequestParameters parameters = new PageRenderRequestParameters(PAGE_NAME, new EmptyEventContext(), false); train_createPageRenderLink(encoder, parameters, link); response.sendRedirect(link); replay(); RequestSecurityManager manager = new RequestSecurityManagerImpl(request, response, encoder, locator, true); assertTrue(manager.checkForInsecurePageRenderRequest(parameters)); verify(); }