Search in sources :

Example 1 with General

use of uk.nhs.digital.website.beans.General in project hippo by NHS-digital-website.

the class GeneralArticleComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest hstRequest, final HstResponse hstResponse) {
    super.doBeforeRender(hstRequest, hstResponse);
    final HstRequestContext context = RequestContextProvider.get();
    HttpServletRequest request = context.getServletRequest();
    Object bean = hstRequest.getAttribute(REQUEST_ATTR_DOCUMENT);
    if (bean != null && bean instanceof HippoBean) {
        General generalDocument = (General) bean;
        if (StringUtils.isNotBlank(generalDocument.getEarlyAccessKey()) && !generalDocument.getEarlyAccessKey().equals(request.getParameter("key"))) {
            LOGGER.debug("Early access key is set and no or wrong key is being used. Redirecting to 404 error code");
            hstResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
            HstResponseUtils.sendRedirect(hstRequest, hstResponse, "/error/404");
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) General(uk.nhs.digital.website.beans.General) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)1 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)1 General (uk.nhs.digital.website.beans.General)1