use of com.free.framework.plateform.csrf.annotation.ValidateToken in project free-framework by a601942905git.
the class CsrfTokenInterceptor method preHandle.
/**
* request请求处理之前
* @param request
* @param response
* @param handler
* @return
* @throws Exception
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// 此处一定要对类型判断,次handler并非一定是HandlerMethod
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
ValidateToken validateToken = method.getAnnotation(ValidateToken.class);
if (null != validateToken && validateToken.vlidate()) {
String requestToken = request.getParameter(CSRF_TOKEN);
boolean validateTokenFlag = validateToken(requestToken);
log.info("CsrfToken验证结果======>" + validateTokenFlag);
// 验证失败
if (!validateTokenFlag) {
return false;
}
// 验证通过移除csrfToken
WebContextUtils.removeSessionAttribute(CSRF_TOKEN);
}
}
return true;
}
Aggregations