我有一个控制器:-
@CrossOrigin(origins = "http://localhost", maxAge = 3600)
@RestController
@RequestMapping("/user")
public class UserController {
@RequestMapping(value = "/login", method = RequestMethod.get)
public String login(@RequestBody User login) throws ServletException{
}
}
我还有另一GenericFilterBean堂课。这是为了执行一些安全功能,例如验证令牌等。
public class JwtFilter extends GenericFilterBean {
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain)
throws IOException, ServletException {
final HttpServletRequest request = (HttpServletRequest) req;
final HttpServletResponse response = (HttpServletResponse) res;
final String authHeader = request.getHeader("authorization");
if ("OPTIONS".equals(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
chain.doFilter(req, res);
} else {
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
new ModelAndView("user/login");// this way i am trying to call one controller method.
throw new ServletException("Missing or invalid Authorization header"); // this is throws one exception. This is only for the dev purpose.
}else {
final String token = authHeader.substring(7);
try {
final Claims claims = Jwts.parser().setSigningKey("secretkey").parseClaimsJws(token).getBody();
request.setAttribute("claims", claims);
} catch (final SignatureException e) {
throw new ServletException("Invalid token");
}
chain.doFilter(req, res);
}
}
}
}
我的问题来自于doFilter我如何调用控制器方法的方法login
此new ModelAndView("user/login");代码不起作用。所以请建议一些方法来做到这一点。
MM们
相关分类