多种登录方式说白了就是账号密码登录和第三方登录(免密码)。账号密码登录的账号可能是手机号、邮箱、身份证号等等,这些到了shiro处理的时候就是username+password的处理;而第三方登录在本系统只需要校验用户是否存在。
所涉及的类
开始
引入shiro maven
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>${shiro.version}</version>
</dependency>
配置基础的shiro
@Configuration
public class ShiroConfig {
@Bean
public ShiroRealm shiroRealm() {
ShiroRealm shiroRealm = new ShiroRealm();
shiroRealm.setCredentialsMatcher(new SimpleCredentialsMatcher());
return shiroRealm;
}
@Bean
public WebSecurityManager securityManager() {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(shiroRealm());
return securityManager;
}
@Bean
public ShiroFilterFactoryBean shiroFilter(WebSecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager);
return shiroFilterFactoryBean;
}
}
重写Token
先写一个枚举,这个枚举