package com.hewl.shiro.config;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
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.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
@Configuration
public class ShiroConfiguration {
@Bean
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
}
//处理认证匹配处理器:如果自定义需要实现继承HashedCredentialsMatcher
//指定加密方式方式,也可以在这里加入缓存,当用户超过五次登陆错误就锁定该用户禁止不断尝试登陆
// @Bean(name = "hashedCredentialsMatcher")
// public HashedCredentialsMatcher hashedCredentialsMatcher() {
// HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
// credentialsMatcher.setHashAlgorithmName("MD5");
// credentialsMatcher.setHashIterations(2);
// credentialsMatcher.setStoredCredentialsHexEncoded(true);
// return credentialsMatcher;
// }
@Bean(name = "shiroRealm")
@DependsOn("lifecycleBeanPostProcessor")
public ShiroRealm shiroRealm() {
ShiroRealm realm = new ShiroRealm();
// realm.setCredentialsMatcher(hashedCredentialsMatcher());
return realm;
}
@Bean(name = "ehCacheManager")
@DependsOn("lifecycleBeanPostProcessor")
public EhCacheManager ehCacheManager(){
EhCacheManager ehCacheManager = new EhCacheManager();
return ehCacheManager;
}
@Bean(name = "securityManager")
public DefaultWebSecurityManager securityManager(){
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(shiroRealm());
securityManager.setCacheManager(ehCacheManager());//用户授权/认证信息Cache, 采用EhCache 缓存
return securityManager;
}
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager securityManager){
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager);
// Map<String, Filter> filters = new LinkedHashMap<String, Filter>();
// LogoutFilter logoutFilter = new LogoutFilter();
// logoutFilter.setRedirectUrl("/login");
// filters.put("logout", logoutFilter);
// shiroFilterFactoryBean.setFilters(filters);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
Map<String, String> filterChainDefinitionManager = new LinkedHashMap<String, String>();
filterChainDefinitionManager.put("/logout", "logout");
filterChainDefinitionManager.put("/user/**", "authc,roles[user]");
filterChainDefinitionManager.put("/shop/**", "authc,roles[shop]");
filterChainDefinitionManager.put("/admin/**", "authc,roles[admin]");
filterChainDefinitionManager.put("/login", "anon");//anon 可以理解为不拦截
filterChainDefinitionManager.put("/register", "anon");//anon 可以理解为不拦截
filterChainDefinitionManager.put("/ajaxLogin", "anon");//anon 可以理解为不拦截
filterChainDefinitionManager.put("/css/**", "anon");//静态资源不拦截
filterChainDefinitionManager.put("/js/**", "anon");//静态资源不拦截
filterChainDefinitionManager.put("/images/**", "anon");//静态资源不拦截
filterChainDefinitionManager.put("/**", "authc,roles[user]");//其他资源全部拦截
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionManager);
shiroFilterFactoryBean.setLoginUrl("/login");
shiroFilterFactoryBean.setSuccessUrl("/");
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
return shiroFilterFactoryBean;
}
@Bean
@ConditionalOnMissingBean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator();
daap.setProxyTargetClass(true);
return daap;
}
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(DefaultWebSecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor aasa = new AuthorizationAttributeSourceAdvisor();
aasa.setSecurityManager(securityManager);
return aasa;
}
//thymeleaf模板引擎和shiro整合时使用
@Bean
public ShiroDialect shiroDialect(){
return new ShiroDialect();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
整合mybatis-spring-boot-2.0-shiro-thymeleaf
共122个文件
class:25个
java:25个
xml:21个
需积分: 10 23 下载量 97 浏览量
2018-04-10
15:11:50
上传
评论
收藏 741KB ZIP 举报
温馨提示
整合mybatis-spring-boot-2.0-shiro-thymeleaf 简短的小demo,适合初学者
资源推荐
资源详情
资源评论
收起资源包目录
整合mybatis-spring-boot-2.0-shiro-thymeleaf (122个子文件)
ShiroConfiguration.class 4KB
ShiroRealm.class 4KB
User.class 3KB
Query.class 2KB
Constant.class 2KB
City.class 1KB
BaseDao.class 1KB
CityRestController.class 1KB
Permission.class 1KB
Role.class 1KB
AdminController.class 982B
Application.class 890B
CityServiceImpl.class 831B
DruidStatViewServlet.class 809B
RolePermission.class 749B
UserRole.class 731B
UserMapper.class 707B
PermissionMapper.class 692B
DruidStatFilter.class 638B
RoleMapper.class 622B
ApplicationTests.class 606B
RolePermissionMapper.class 442B
UserRoleMapper.class 418B
CityDao.class 306B
CityService.class 208B
.classpath 1KB
mvnw.cmd 5KB
style.css 167KB
style.css 167KB
bootstrap.css 144KB
bootstrap.css 144KB
style.min.css 135KB
style.min.css 135KB
bootstrap.min.css 120KB
bootstrap.min.css 120KB
animate.css 67KB
animate.css 67KB
custom.css 1KB
custom.css 1KB
.gitignore 268B
register.html 2KB
register.html 2KB
login.html 2KB
login.html 2KB
maven-wrapper.jar 46KB
ShiroConfiguration.java 5KB
ShiroRealm.java 5KB
Constant.java 4KB
User.java 2KB
BaseDao.java 2KB
Query.java 2KB
City.java 920B
DruidStatViewServlet.java 889B
PermissionMapper.java 730B
CityRestController.java 682B
RoleMapper.java 660B
Role.java 602B
Permission.java 600B
UserMapper.java 583B
AdminController.java 553B
CityServiceImpl.java 541B
DruidStatFilter.java 525B
Application.java 516B
RolePermissionMapper.java 417B
CityDao.java 397B
RolePermission.java 388B
UserRoleMapper.java 387B
UserRole.java 382B
CityService.java 332B
ApplicationTests.java 325B
jquery-ui-1.10.4.min.js 223KB
jquery-ui-1.10.4.min.js 223KB
jquery-2.1.1.js 82KB
jquery-2.1.1.js 82KB
bootstrap.js 67KB
bootstrap.js 67KB
bootstrap.min.js 36KB
bootstrap.min.js 36KB
jquery-ui.custom.min.js 32KB
jquery-ui.custom.min.js 32KB
icheck.min.js 5KB
icheck.min.js 5KB
bootstrap.css.map 381KB
bootstrap.css.map 381KB
MANIFEST.MF 360B
mvnw 6KB
green@2x.png 8KB
green@2x.png 8KB
green.png 5KB
green.png 5KB
org.eclipse.jdt.core.prefs 243B
org.eclipse.core.resources.prefs 155B
org.eclipse.m2e.core.prefs 97B
.project 1KB
pom.properties 295B
maven-wrapper.properties 110B
.springBeans 463B
pom.xml 5KB
pom.xml 5KB
UserMapper.xml 3KB
共 122 条
- 1
- 2
资源评论
小菜鸟的梦
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功