【发布时间】:2017-05-11 09:48:33
【问题描述】:
我正在配置我的 REST 的安全性,但我不知道如何保护我的方法,但是允许触发过滤器来设置我的权限
http
.authorizeRequests()
.antMatchers(PERSISTENCE_SERVICE_URL)
.hasAuthority(AUTHORITY_PERSISTENCE_SERVICE)
.and()
.csrf()
.disable();
在我的扩展 OncePerRequestFilter 的过滤器中做了这样的事情
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
this.authenticationImpl.init();
String jwt = request.getHeader("jwt");
String refresh = request.getHeader("refresh");
if(jwt != null) {
this.jwtPropertyExtractor.commitJwt(jwt, refresh);
String jwtId = this.jwtPropertyExtractor.getIdentityId();
String securityRole = this.jwtPropertyExtractor.getSecurityRole();
this.authenticationImpl.setIdentityId(jwtId);
this.authenticationImpl.updateSecurityRole(securityRole);
SecurityContextHolder.getContext().setAuthentication(this.authenticationImpl);
}
filterChain.doFilter(request, response); }
所以当我将.hasAuthority(AUTHORITY_PERSISTENCE_SERVICE) 放入我的配置时,我的过滤器甚至没有被触发,但我需要他设置我的身份验证。
【问题讨论】:
-
您的配置显示您尚未注册自定义过滤器