- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 groovy 的新手,我已经按照以下方式在 grails 中实现了 CSRF token 。
在 resource.groovy 中添加 CSRF 过滤器
csrfFilter(CsrfFilter, new HttpSessionCsrfTokenRepository()) {
accessDeniedHandler = ref('fnAccessDeniedHandler')
requireCsrfProtectionMatcher = ref('fnRequireCsrfProtectionMatcher')
}
最佳答案
ref 中的值必须是一个 bean( https://docs.grails.org/latest/guide/spring.html )。如果要覆盖 accessDeniedHandler 和 requireCsrfProtectionMatcher,则需要创建自定义类,并在 resources.groovy 中创建 bean。例如,要创建 bean fnAccessDeniedHandler,您将执行以下操作。
在resources.groovy中添加以下内容
fnAccessDeniedHandler(CustomAccessDeniedHandler)
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
public static final Logger LOG
= Logger.getLogger(CustomAccessDeniedHandler.class);
@Override
public void handle(
HttpServletRequest request,
HttpServletResponse response,
AccessDeniedException exc) throws IOException, ServletException {
Authentication auth
= SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
LOG.warn("User: " + auth.getName()
+ " attempted to access the protected URL: "
+ request.getRequestURI());
}
response.sendRedirect(request.getContextPath() + "/accessDenied");
}
}
关于grails - 如何在 grails 中编写 accessDeniedHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48307781/
我已经实现了一个自定义的 AccessDeniedHandler: public class MyAccessDeniedHandler implements AccessDeniedHandler
我是 groovy 的新手,我已经按照以下方式在 grails 中实现了 CSRF token 。 在 resource.groovy 中添加 CSRF 过滤器 csrfFilter(CsrfFilt
我有以下 Spring Security 配置: @Configuration @EnableWebSecurity public class WebSecurityConfig extends We
我有一个 spring 3 应用程序,其配置如下。当任何用户尝试访问页面但他/她未登录时,我会收到一个Access is Denied 异常以及丑陋的堆栈跟踪。我如何处理此异常而不让它转储堆栈跟踪。我
我引用了有关配置 CSRF 保护的 Spring Security 文档: Instead by default Spring Security’s CSRF protection will prod
我是一名优秀的程序员,十分优秀!