package com.cms.base.config;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO;
import org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator;
import org.apache.shiro.session.mgt.quartz.QuartzSessionValidationScheduler;
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.CookieRememberMeManager;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.servlet.SimpleCookie;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import com.cms.base.shiro.credentials.RetryLimitHashedCredentialsMatcher;
import com.cms.base.shiro.realm.UserRealm;
import com.cms.base.shiro.spring.SpringCacheManagerWrapper;
import javax.servlet.Filter;
import java.util.LinkedHashMap;
import java.util.Map;
@Configuration
public class ShiroConfig {
@Bean
public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager);
//shiro自定义过滤器
Map<String, Filter> filters = new LinkedHashMap<>();
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
shiroFilterFactoryBean.setFilters(filters);
//配置记住我或认证通过可以访问的地址
// 配置不会被拦截的链接 顺序判断
filterChainDefinitionMap.put("/login","authc");
//配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了
filterChainDefinitionMap.put("/logout", "logout");
//未授权界面;
filterChainDefinitionMap.put("/authenticated", "authc");
//<!-- 过滤链定义,从上向下顺序执行,一般将/**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了;
filterChainDefinitionMap.put("/static/**", "anon");
filterChainDefinitionMap.put("/kaptcha.jpg","anon");
filterChainDefinitionMap.put("/kaptcha","anon");
filterChainDefinitionMap.put("swagger-ui.html", "anon");
filterChainDefinitionMap.put("/webjars/**", "anon");
//<!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
filterChainDefinitionMap.put("/**", "user");
// 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
shiroFilterFactoryBean.setLoginUrl("/login");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
/**
* 安全管理器
* @param userRealm
* @return
*/
@Bean
public DefaultWebSecurityManager securityManager(UserRealm userRealm, DefaultWebSessionManager sessionManager,SpringCacheManagerWrapper cacheManager){
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(userRealm);
securityManager.setSessionManager(sessionManager);
securityManager.setCacheManager(cacheManager);
securityManager.setRememberMeManager(rememberMeManager());
return securityManager;
}
/**
* 会话ID生成器
*
* @return
*/
@Bean
public JavaUuidSessionIdGenerator sessionIdGenerator() {
return new JavaUuidSessionIdGenerator();
}
/**
* 会话Cookie模板
*
* @return
*/
@Bean
public SimpleCookie sessionIdCookie() {
SimpleCookie simpleCookie = new SimpleCookie("sid");
simpleCookie.setHttpOnly(true);
simpleCookie.setMaxAge(-1);
return simpleCookie;
}
/**
* 自动登陆自动登陆cookie
*
* @return
*/
@Bean
public SimpleCookie rememberMeCookie() {
SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
simpleCookie.setHttpOnly(true);
simpleCookie.setMaxAge(2592000);
return simpleCookie;
}
/**
* rememberMe管理器
*
* @return
*/
@Bean
public CookieRememberMeManager rememberMeManager() {
CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
cookieRememberMeManager.setCipherKey(Base64.decode("4AvVhmFLUs0KTA3Kprsdag=="));
cookieRememberMeManager.setCookie(rememberMeCookie());
return cookieRememberMeManager;
}
/**
* 会话DAO
*
* @return
*/
@Bean
public EnterpriseCacheSessionDAO sessionDAO() {
EnterpriseCacheSessionDAO enterpriseCacheSessionDAO = new EnterpriseCacheSessionDAO();
enterpriseCacheSessionDAO.setActiveSessionsCacheName("shiro-activeSessionCache");
enterpriseCacheSessionDAO.setSessionIdGenerator(sessionIdGenerator());
return enterpriseCacheSessionDAO;
}
/**
* 会话管理器
*
* @return
*/
@Bean
public DefaultWebSessionManager sessionManager() {
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
sessionManager.setGlobalSessionTimeout(1800000);
sessionManager.setDeleteInvalidSessions(true);
// sessionManager.setSessionValidationScheduler(sessionValidationScheduler);
sessionManager.setSessionDAO(sessionDAO());
sessionManager.setSessionValidationSchedulerEnabled(true);
sessionManager.setSessionIdCookie(sessionIdCookie());
return sessionManager;
}
/**
* 会话验证调度器
*
* @return
*/
@Bean
public QuartzSessionValidationScheduler sessionValidationScheduler(DefaultWebSessionManager sessionManager) {
QuartzSessionValidationScheduler sessionValidationScheduler = new QuartzSessionValidationScheduler();
sessionValidationScheduler.setSessionValidationInterval(1800000);
sessionValidationScheduler.setSessionManager(sessionManager);
return sessionValidationScheduler;
}
/**
* 缓存管理器
*
* @return
*/
@Bean
public SpringCacheManagerWrapper cacheManager(EhCacheCacheManager springCacheManager) {
SpringCacheManagerWrapper cacheManager = new SpringCacheManagerWrapper();
cacheManager.setCacheManager(springCacheManager);
return cacheManager;
}
/**
* 凭证匹配器
*
* @return
*/
@Bean
public RetryLimitHashedCredentialsMatcher credentialsMatcher(SpringCacheManagerWrapper cacheManager) {
RetryLimitHashedCredentialsMatcher credentialsMatcher = new RetryLimitHashedCredentialsMatcher(cacheManager);
credentialsMatcher.setHashAlgorithmName("md5");
credentialsMatcher.setHashIterations(2);
credentialsMatcher.setStoredCredentialsHexEncoded(true);
return credentialsMatcher;
}
/**
* Realm实现
*
* @return
*/
@Bean
public UserRealm userRealm(RetryLimitHashedCredentialsMatcher credentialsMatcher) {
UserRealm userRealm = new UserRealm();
userRealm.setCredentialsMatcher(credentialsMatcher);
userRealm.setCachingEnabled(false);
return userRealm;
}
/**
* Shiro生命周期处理器
*
* @return
*/
@Bean
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
}
/**
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【作品名称】:基于Java+Bootstrap的课程管理系统【毕业设计】 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】: 基于Java+Bootstrap的课程管理系统【毕业设计】 基于Bootstrap的课程管理系统 数据库表设计 用户表(基本信息) 角色表(管理员,教师,学生) 班级表 【资源声明】:本资源作为“参考资料”而不是“定制需求”,代码只能作为参考,不能完全复制照搬。需要有一定的基础看懂代码,自行调试代码并解决报错,能自行添加功能修改代码。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java+Bootstrap的课程管理系统毕业设计 (571个子文件)
bootstrap.css 138KB
bootstrap.min.css 115KB
AdminLTE.css 109KB
AdminLTE.min.css 89KB
AdminLTE-without-plugins.css 88KB
AdminLTE-without-plugins.min.css 72KB
animate.css 71KB
ionicons.css 56KB
animate.min.css 52KB
ionicons.min.css 50KB
_all-skins.css 47KB
_all-skins.min.css 41KB
font-awesome.css 37KB
font-awesome.min.css 30KB
bootstrap-datepicker3.standalone.css 23KB
bootstrap-datepicker3.css 22KB
_all.css 21KB
bootstrap-datepicker.standalone.css 18KB
select2.css 17KB
bootstrap-datepicker.css 17KB
bootstrap-datepicker.min.css 15KB
AdminLTE-bootstrap-social.css 15KB
_all.css 15KB
select2.min.css 15KB
_all.css 14KB
_all.css 13KB
bootstrap-colorpicker.min.css 13KB
AdminLTE-bootstrap-social.min.css 12KB
daterangepicker.css 8KB
bootstrap-table.css 7KB
metroStyle.css 6KB
login.css 6KB
bootstrap-table.min.css 5KB
bootstrap-colorpicker.css 5KB
skin-black-light.css 5KB
skin-blue-light.css 4KB
skin-yellow-light.css 4KB
skin-purple-light.css 4KB
skin-green-light.css 4KB
skin-red-light.css 4KB
skin-black.css 4KB
skin-black-light.min.css 4KB
skin-blue-light.min.css 4KB
skin-yellow-light.min.css 4KB
skin-purple-light.min.css 4KB
skin-green-light.min.css 4KB
skin-blue.css 4KB
skin-red-light.min.css 4KB
skin-yellow.css 3KB
skin-purple.css 3KB
skin-green.css 3KB
skin-black.min.css 3KB
skin-red.css 3KB
skin-blue.min.css 3KB
skin-purple.min.css 3KB
skin-yellow.min.css 3KB
AdminLTE-select2.css 3KB
bootstrap-timepicker.min.css 3KB
skin-green.min.css 3KB
skin-red.min.css 3KB
bootstrap-timepicker.css 3KB
AdminLTE-select2.min.css 3KB
purple.css 2KB
yellow.css 2KB
orange.css 2KB
green.css 2KB
pink.css 2KB
blue.css 2KB
grey.css 2KB
aero.css 2KB
pace.css 2KB
red.css 2KB
line.css 2KB
pace.min.css 2KB
AdminLTE-fullcalendar.css 2KB
purple.css 2KB
orange.css 2KB
yellow.css 2KB
purple.css 2KB
yellow.css 2KB
orange.css 2KB
green.css 2KB
green.css 2KB
aero.css 2KB
blue.css 2KB
pink.css 2KB
grey.css 2KB
blue.css 2KB
pink.css 2KB
aero.css 2KB
grey.css 2KB
red.css 2KB
red.css 2KB
all.css 2KB
minimal.css 2KB
polaris.css 2KB
square.css 2KB
main.css 1KB
AdminLTE-fullcalendar.min.css 1KB
purple.css 1KB
共 571 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
小英子架构
- 粉丝: 1007
- 资源: 4026
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功