class PermissionMidware {

    /**
     * Logger.
     */
    private static final Logger LOGGER = LogManager.getLogger(PermissionMidware.class);

    /**
     * Language service.
     */
    @Inject
    private LangPropsService langPropsService;
    /**
     * Role query service.
     */
    @Inject
    private RoleQueryService roleQueryService;

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

        Stopwatchs.start("Check Permissions");
        try {
            final JSONObject exception = new JSONObject();
            exception.put(Keys.MSG, langPropsService.get("noPermissionLabel"));
            exception.put(Keys.CODE, 403);

            final String prefix = "permission.rule.url.";
            final String requestURI = StringUtils.substringAfter(context.requestURI(), Latkes.getContextPath());
            final String method = context.method();
            String rule = prefix;

            try {
                final RouteResolution routeResolution = RouteHandler.doMatch(requestURI, method);
                rule += routeResolution.getMatchedUriTemplate() + "." + method;
            } catch (final Exception e) {
                LOGGER.log(Level.ERROR, "Match method failed", e);

                context.sendError(500);
                context.abort();
                return;
            }

            final Set<String> requisitePermissions = Symphonys.URL_PERMISSION_RULES.get(rule);
            if (null == requisitePermissions) {
                context.handle();
                return;
            }

            final JSONObject user = Sessions.getUser();
            final String roleId = null != user ? user.optString(User.USER_ROLE) : Role.ROLE_ID_C_VISITOR;
            final String userName = null != user ? " " + user.optString(User.USER_NAME) + " " : "";
            final Set<String> grantPermissions = roleQueryService.getPermissions(roleId);

            if (!Permission.hasPermission(requisitePermissions, grantPermissions)) {
                final Map<String, Object> errDataModel = new HashMap<>();
                String noPermissionLabel = langPropsService.get("noPermissionLabel");
                final JSONObject role = roleQueryService.getRole(roleId);
                noPermissionLabel = noPermissionLabel.replace("{roleName}", role.optString(Role.ROLE_NAME));
                noPermissionLabel = noPermissionLabel.replace("{user}", userName);
                errDataModel.put("noPermissionLabel", noPermissionLabel);

                context.sendError(403, errDataModel);
                context.abort();
                return;
            }

            context.handle();
        } finally {
            Stopwatchs.end();
        }
    
<no_super_class>