本文整理汇总了Java中org.springframework.security.web.csrf.CsrfException类的典型用法代码示例。如果您正苦于以下问题:Java CsrfException类的具体用法?Java CsrfException怎么用?Java CsrfException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CsrfException类属于org.springframework.security.web.csrf包,在下文中一共展示了CsrfException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: handle
import org.springframework.security.web.csrf.CsrfException; //导入依赖的package包/类
public void handle(HttpServletRequest request, HttpServletResponse response,
AccessDeniedException accessDeniedException) throws IOException, ServletException {
if (accessDeniedException instanceof CsrfException && !response.isCommitted()) {
// Remove the session cookie so that client knows it's time to obtain a new CSRF token
String pCookieName = "CSRF-TOKEN";
Cookie cookie = new Cookie(pCookieName, "");
cookie.setMaxAge(0);
cookie.setHttpOnly(false);
cookie.setPath("/");
response.addCookie(cookie);
}
accessDeniedHandlerImpl.handle(request, response, accessDeniedException);
}
开发者ID:RawSanj,项目名称:blogAggr,代码行数:16,代码来源:CustomAccessDeniedHandler.java
示例2: handle
import org.springframework.security.web.csrf.CsrfException; //导入依赖的package包/类
@Override
public void handle(final HttpServletRequest request,
final HttpServletResponse response,
final AccessDeniedException ex) throws IOException {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
final boolean sessionExists = request.getSession(false) != null;
if (ex instanceof MissingCsrfTokenException) {
LOG.warn("Missing CSRF token for requestURI={} for user {} with session={} and message: {}",
request.getRequestURI(), getActiveUserInfo(), sessionExists, ex.getMessage());
} else if (ex instanceof CsrfException) {
LOG.warn("Invalid CSRF token for requestURI={} for user {} with session={} and message: {}",
request.getRequestURI(), getActiveUserInfo(), sessionExists, ex.getMessage());
} else {
LOG.warn("Access denied for requestURI={} for user {} with exception {} message: {}",
request.getRequestURI(), getActiveUserInfo(), ex.getClass().getName(), ex.getMessage());
}
if (!response.isCommitted()) {
response.setContentType("application/json");
response.getWriter().print("{\"status\": \"FORBIDDEN\"}");
response.getWriter().flush();
response.getWriter().close();
}
}
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:29,代码来源:CustomAccessDeniedHandler.java
示例3: accessDeniedHandler
import org.springframework.security.web.csrf.CsrfException; //导入依赖的package包/类
@Bean
public AccessDeniedHandler accessDeniedHandler() {
LinkedHashMap<Class<? extends AccessDeniedException>, AccessDeniedHandler> handlers = new LinkedHashMap<>();
handlers.put(CsrfException.class, new CsrfTokenExceptionHandler());
return new DelegatingAccessDeniedHandler(handlers, new AccessDeniedHandlerImpl());
}
开发者ID:vitalii-dmytruk,项目名称:ConfLab,代码行数:7,代码来源:WebSecurityConfig.java
注:本文中的org.springframework.security.web.csrf.CsrfException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论