@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf() //跨站
.disable() //关闭跨站检测
.authorizeRequests() //验证策略
.antMatchers(WHITE_LIST).permitAll()
.anyRequest().authenticated() //默认其它的请求都需要认证
.and()
.formLogin()
.loginPage(SecurityConstants.LOGIN_PAGE)
.failureUrl(SecurityConstants.FAILURE_URL)
.permitAll()
.defaultSuccessUrl(SecurityConstants.DEFAULT_SUCCESS_URL, true)
.permitAll()
.and()
.exceptionHandling()
.accessDeniedPage(SecurityConstants.ACCESS_DENIED_PAGE);
/*
* 本次 json web token 权限控制的核心配置部分
* 在 Spring Security 开始判断本次会话是否有权限时的前一瞬间
* 通过添加过滤器将 token 解析,将用户所有的权限写入本次 Spring Security 的会话
*/
http.addFilterBefore(new JwtAuthenticationFilterListener(this.komsProperties),
UsernamePasswordAuthenticationFilter.class);
//禁用缓存
http.headers().cacheControl();
}
添加白名单
private static String[] WHITE_LIST;
.antMatchers(WHITE_LIST).permitAll()