![e7d2464ab2770bdc5b5104e29d28f49c.png](https://img-blog.csdnimg.cn/img_convert/e7d2464ab2770bdc5b5104e29d28f49c.png)
1. 前言
欢迎阅读 Spring Security 实战干货 系列文章 。最近有开发小伙伴提了一个有趣的问题。他正在做一个项目,涉及两种风格,一种是给小程序出接口,安全上使用无状态的JWT Token;另一种是管理后台使用的是Freemarker,也就是前后端不分离的Session机制。用Spring Security该怎么办?
2. 解决方案
我们可以通过多次继承WebSecurityConfigurerAdapter构建多个HttpSecurity
。HttpSecurity
对象会告诉我们如何验证用户的身份,如何进行访问控制,采取的何种策略等等。
如果你看过之前的教程,我们是这么配置的:
/**
* 单策略配置
*
* @author felord.cn
* @see org.springframework.boot.autoconfigure.security.servlet.SpringBootWebSecurityConfiguration
* @since 14 :58 2019/10/15
*/
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true, jsr250Enabled = true, securedEnabled = true)
@EnableWebSecurity
@ConditionalOnClass(WebSecurityConfigurerAdapter.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class CustomSpringBootWebSecurityConfiguration {
/**
* The type Default configurer adapter.
*/
@Configuration
@Order(SecurityProperties.BASIC_AUTH_ORDER)
static class DefaultConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override