Keep it simple, stupidhtml
@Override
public void configure(WebSecurity web) {
web.ignoring()
.antMatchers(HttpMethod.OPTIONS, "/**")
.antMatchers("/app/**/*.{js,html}")
.antMatchers("/i18n/**")
.antMatchers("/swagger-ui/index.html")
.antMatchers("/test/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.exceptionHandling()
.authenticationEntryPoint(http401UnauthorizedEntryPoint())
.and()
.csrf()
.disable()
.headers()
.disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/auth/**").permitAll()
.antMatchers("/actuator/**").access(actuatorExp)
.antMatchers("/user/register/").hasAuthority(AuthoritiesConstants.API_REGISTER.getValue())
.antMatchers("/**").hasAuthority(AuthoritiesConstants.USER.getValue())
.antMatchers("/pick/**").hasAuthority(AuthoritiesConstants.PICKER.getValue())
.and()
.securityContext()
.securityContextRepository(new NullSecurityContextRepository())
.and()
.apply(securityConfigurerAdapter());
if (verificationSecurityConfigurer != null) {
http.apply(verificationSecurityConfigurer);
}
}
复制代码
WebSecurity 与 HttpSecurity 什么关系, 能不能统一到一块儿配置?java
HttpSeecurity 的配置从上到下没有层次感, 须要了解足够多的内部配置信息才能准确配置.web
"Explicit is better than implicit", Spring Security 默认启用的配置10+, 都是隐式配置, 可是须要显式的 disable .安全
下面也许更好session
http
.apply(sessionConfigurer)
.apply(csryConfigurer)
.apply(contextConfigurer)
.apply(authorizeConfigurer)
.apply(customConfigurer)
复制代码
实现获取 Token, 验证, 受权, 访问控制使用的都是 Filter. 并且 Filter 仍是 Servlet 规范的 Filter , 对使用者而言, 难免混淆.app
Filter 过于强大(强大到能够基于 FIlter 实现 Struts2 框架 ), 而 Spring Security 并未对此设限.框架
以异常处理来作业务逻辑. 这个也是不得已为之, 毕竟基于 Filteride
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException;
复制代码
Filter 的核心方法 doFilter 是没有返回值的 以异常处理作业务处理的问题, 就是重拾万恶的GOTO 语句优化
固然, Spring Security 被普遍使用的缘由在于它确实能够知足用户的安全需求, 尽管并很差用. 有没有更简单的安全框架, 也许 Shiro 是个不错的选择, 但我的并无进一步了解, 此处不表.ui
因为 Spring Security 是 Spring 官方默认实现, 在很长的一段时间内, 依然会是主流, 若是不能反抗, 那就享受吧.