class CSRFMidware {

    /**
     * Language service.
     */
    @Inject
    private LangPropsService langPropsService;

    public void fill(final RequestContext context) {
        context.handle();

        final AbstractResponseRenderer renderer = context.getRenderer();
        if (null == renderer) {
            return;
        }
        final Map<String, Object> dataModel = renderer.getRenderDataModel();
        dataModel.put(Common.CSRF_TOKEN, Sessions.getCSRFToken(context));
    }

    public void check(final RequestContext context) {<FILL_FUNCTION_BODY>}
}

        final JSONObject exception = new JSONObject();
        exception.put(Keys.MSG, langPropsService.get("csrfCheckFailedLabel"));
        exception.put(Keys.CODE, StatusCodes.ERR);

        // 1. Check Referer
        final String referer = context.header("Referer");
        if (!StringUtils.startsWith(referer, StringUtils.substringBeforeLast(Latkes.getServePath(), ":"))) {
            context.renderJSON(exception);
            context.abort();
            return;
        }

        // 2. Check Token
        final String clientToken = context.header(Common.CSRF_TOKEN);
        final String serverToken = Sessions.getCSRFToken(context);

        if (!StringUtils.equals(clientToken, serverToken)) {
            context.renderJSON(exception);
            context.abort();
            return;
        }

        context.handle();
    
<no_super_class>