package com.shirodemo.demo.Realm;
import org.apache.shiro.cache.MemoryConstrainedCacheManager;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.LinkedHashMap;
/**
*
* @author Administrator
* @create 2017/12/2
* @since 1.0.0
*/
//启动时,先运行configuration注解的类
@Configuration
public class ShiroConfiguration {
@Bean("shiroFilter")
public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager") SecurityManager manager){
System.out.println("shiroFilter");
ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
bean.setSecurityManager(manager);
bean.setLoginUrl("/login");
bean.setSuccessUrl("/index");
bean.setUnauthorizedUrl("/unauthorized");
//请求拦截 key-访问请路径 value-使用的拦截方式
LinkedHashMap<String, String> filterChainDefinittionMap = new LinkedHashMap<>();
filterChainDefinittionMap.put("/index","authc");//需要通过验证
filterChainDefinittionMap.put("/login","anon");//不需要验证
filterChainDefinittionMap.put("/loginUser","anon");//不需要验证
filterChainDefinittionMap.put("/admin","roles[admin]");//只允许admin用户
filterChainDefinittionMap.put("/add","perms[add]");//只允许权限又add的用户
filterChainDefinittionMap.put("/druid/**", "anon");// 数据库监控
filterChainDefinittionMap.put("/**","user");//需要验证--已经登录的用户
bean.setFilterChainDefinitionMap(filterChainDefinittionMap);
return bean;
}
@Bean("securityManager")
public SecurityManager securityManager(@Qualifier("authRealm") AuthRealm authRealm){
System.out.println("securityManager");
DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
manager.setRealm(authRealm);
return manager;
}
@Bean("authRealm")
public AuthRealm authRealm(@Qualifier("credentialMatcher") CredentialMatcher matcher){
System.out.println("authRealm");
AuthRealm authRealm = new AuthRealm();
authRealm.setCacheManager(new MemoryConstrainedCacheManager());//启用缓存
authRealm.setCredentialsMatcher(matcher);
return authRealm;
}
@Bean("credentialMatcher")
public CredentialMatcher credentialMatcher(){
System.out.println("Credentialmatcher");
return new CredentialMatcher();
}
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(@Qualifier("securityManager") SecurityManager securityManager){
System.out.println("authorizationAttributeSourceAdvisor");
AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
advisor.setSecurityManager(securityManager);
return advisor;
}
@Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator(){
System.out.println("defaultAdvisorAutoProxyCreator");
DefaultAdvisorAutoProxyCreator creater = new DefaultAdvisorAutoProxyCreator();
creater.setProxyTargetClass(true);
return creater;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
IDEA+SpringBoot+Mybatis+shiro:整个shiro的实现过程,可应用于线上产品
共129个文件
xml:79个
class:25个
java:13个
5星 · 超过95%的资源 需积分: 24 100 下载量 100 浏览量
2017-12-10
14:41:15
上传
评论
收藏 138KB ZIP 举报
温馨提示
IDEA+SpringBoot+shiro:整个shiro的实现过程,可应用于线上产品
资源推荐
资源详情
资源评论
收起资源包目录
IDEA+SpringBoot+Mybatis+shiro:整个shiro的实现过程,可应用于线上产品 (129个子文件)
ShiroConfiguration.class 4KB
AuthRealm.class 4KB
DruidConfiguration.class 4KB
ShiroConfiguration.class 4KB
AuthRealm.class 3KB
TestController.class 3KB
Role.class 2KB
TestController.class 2KB
User.class 2KB
Role.class 2KB
CredentialMatcher.class 2KB
User.class 1KB
CredentialMatcher.class 1KB
UserServiceIpml.class 1012B
Permission.class 984B
Permission.class 976B
UserServiceImpl.class 942B
DemoApplicationTests.class 924B
DemoApplicationTests.class 904B
DemoApplication.class 869B
DemoApplication.class 857B
UserMapper.class 397B
UserMapper.class 312B
UserService.class 209B
UserService.class 201B
mvnw.cmd 5KB
.gitignore 249B
shirodemo.iml 9KB
maven-wrapper.jar 46KB
ShiroConfiguration.java 4KB
DruidConfiguration.java 3KB
AuthRealm.java 3KB
TestController.java 2KB
Role.java 2KB
User.java 1KB
UserServiceImpl.java 1KB
CredentialMatcher.java 974B
Permission.java 949B
DemoApplicationTests.java 534B
DemoApplication.java 519B
UserMapper.java 331B
UserService.java 237B
login.jsp 380B
unauthorized.jsp 220B
index.jsp 213B
mvnw 6KB
.name 4B
application.properties 524B
application.properties 524B
maven-wrapper.properties 110B
workspace.xml 77KB
uiDesigner.xml 9KB
pom.xml 3KB
UserMapper.xml 1KB
UserMapper.xml 1KB
Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_9_RELEASE.xml 769B
Maven__org_springframework_boot_spring_boot_starter_logging_1_5_9_RELEASE.xml 748B
Maven__org_springframework_boot_spring_boot_starter_tomcat_1_5_9_RELEASE.xml 741B
Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_9_RELEASE.xml 734B
Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_1_3_1.xml 730B
Maven__org_springframework_boot_spring_boot_starter_jdbc_1_5_9_RELEASE.xml 727B
Maven__org_springframework_boot_spring_boot_starter_test_1_5_9_RELEASE.xml 727B
Maven__org_springframework_boot_spring_boot_starter_web_1_5_9_RELEASE.xml 720B
compiler.xml 705B
Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml 700B
Maven__org_springframework_spring_context_support_4_2_3_RELEASE.xml 693B
Maven__org_springframework_boot_spring_boot_starter_1_5_9_RELEASE.xml 692B
Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_1_3_1.xml 688B
Maven__org_springframework_boot_spring_boot_test_1_5_9_RELEASE.xml 671B
Maven__org_springframework_spring_expression_4_3_13_RELEASE.xml 665B
Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_23.xml 660B
Maven__org_springframework_spring_context_4_3_13_RELEASE.xml 644B
Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml 644B
Maven__org_apache_tomcat_embed_tomcat_embed_jasper_8_5_23.xml 639B
Maven__org_springframework_spring_webmvc_4_3_13_RELEASE.xml 637B
Maven__org_springframework_boot_spring_boot_1_5_9_RELEASE.xml 636B
Maven__org_apache_tomcat_tomcat_annotations_api_8_5_23.xml 636B
Maven__org_hibernate_hibernate_validator_5_3_6_Final.xml 634B
Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml 630B
Maven__org_springframework_spring_beans_4_3_13_RELEASE.xml 630B
Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_23.xml 625B
Maven__org_springframework_spring_jdbc_4_3_13_RELEASE.xml 623B
Maven__org_springframework_spring_core_4_3_13_RELEASE.xml 623B
Maven__org_springframework_spring_test_4_3_13_RELEASE.xml 623B
Maven__org_springframework_spring_aop_4_3_13_RELEASE.xml 616B
Maven__org_springframework_spring_web_4_3_13_RELEASE.xml 616B
Maven__commons_collections_commons_collections_3_2_2.xml 616B
Maven__javax_validation_validation_api_1_1_0_Final.xml 611B
Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_23.xml 611B
Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml 609B
Maven__org_jboss_logging_jboss_logging_3_3_1_Final.xml 608B
Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml 602B
Maven__commons_beanutils_commons_beanutils_1_9_3.xml 594B
Maven__javax_servlet_javax_servlet_api_3_1_0.xml 578B
Maven__ch_qos_logback_logback_classic_1_1_11.xml 575B
Maven__mysql_mysql_connector_java_5_1_44.xml 574B
Maven__org_slf4j_log4j_over_slf4j_1_7_25.xml 562B
Maven__org_apache_tomcat_tomcat_juli_8_5_23.xml 559B
Maven__org_apache_tomcat_tomcat_jdbc_8_5_23.xml 559B
Maven__org_apache_commons_commons_lang3_3_4.xml 556B
共 129 条
- 1
- 2
资源评论
- yourwonder2020-06-01感谢分享。
- 才子022019-06-24不错,好用,不错的资源
- asdfg021492020-07-09感谢分享,非常有用
灰客_ck
- 粉丝: 2
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功