本文整理汇总了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);
}
示例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();
}
}
示例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());
}