ShiroWeb 基础框架搭建
程序员文章站
2022-06-28 23:06:22
MyRealm.javapackage com.dym.shiroweb.config;import org.apache.shiro.authc.AuthenticationException;import org.apache.shiro.authc.AuthenticationInfo;import org.apache.shiro.authc.AuthenticationToken;import org.apache.shiro.authz.AuthorizationInfo;im...
MyRealm.java
package com.dym.shiroweb.config;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyRealm extends AuthorizingRealm {
private Logger logger= LoggerFactory.getLogger(MyRealm.class);
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
logger.info("------entered MyRealm doGetAuthorizationInfo method");
return null;
}
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
logger.info("+++++++entered MyRealm doGetAuthenticationInfo method");
return null;
}
}
ShiroConfig.java
package com.dym.shiroweb.config;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.servlet.ShiroFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ShiroConfig {
// 1 Realm 代表系统资源
@Bean
public Realm myRealm(){
return new MyRealm();
}
// 2 SecurityManager 流程控制
@Bean
public DefaultWebSecurityManager mySecurityManager(Realm myRealm){
DefaultWebSecurityManager securityManager=new DefaultWebSecurityManager();
securityManager.setRealm(myRealm);
return securityManager;
}
// 3 ShiroFilterFactoryBean 请求过滤器
@Bean
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager mySecurityManager){
ShiroFilterFactoryBean factoryBean=new ShiroFilterFactoryBean();
factoryBean.setSecurityManager(mySecurityManager);
return factoryBean;
}
}
本文地址:https://blog.csdn.net/qq_39368007/article/details/112001046
推荐阅读
-
(Mac) IDEA上搭建TestNG框架
-
零基础写python爬虫之爬虫框架Scrapy安装配置
-
零基础写python爬虫之使用Scrapy框架编写爬虫
-
在Mac OS上搭建PHP的Yii框架及相关测试环境
-
搭建ssh框架的基本步骤(ssh框架整合实战教程)
-
maven搭建ssm框架步骤(用eclipse搭建ssm框架)
-
Laravel框架基础语法与知识点整理【模板变量、输出、include引入子视图等】
-
Laravel5.1 框架控制器基础用法实例分析
-
EpiiAdmin 开源的php交互性管理后台框架, 让复杂的交互变得更简单!Phper快速搭建交互性平台的开发框架,基于Thinkphp5.1+Adminlte3.0+Require.js。
-
python自动化框架搭建过程(分享python接口自动化框架有哪些)