package com.wayn.framework.config;
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
import com.caucho.hessian.client.HessianProxyFactory;
import com.wayn.common.service.DeptService;
import com.wayn.framework.redis.RedisOpts;
import com.wayn.framework.shiro.cache.RedisCacheManager;
import com.wayn.framework.shiro.credentials.MyCredentialsMatcher;
import com.wayn.framework.shiro.filter.OnlineSessionFilter;
import com.wayn.framework.shiro.filter.SsoTokenValidateFilter;
import com.wayn.framework.shiro.filter.TokenLoginFilter;
import com.wayn.framework.shiro.realm.SsoRealm;
import com.wayn.framework.shiro.session.OnlineSessionFactory;
import com.wayn.framework.shiro.session.RedisSessionDAO;
import com.wayn.ssocore.service.AuthcationRpcService;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.mgt.SessionFactory;
import org.apache.shiro.session.mgt.eis.SessionDAO;
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.filter.authc.LogoutFilter;
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.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.transaction.TransactionAwareCacheDecorator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.data.redis.cache.RedisCache;
import javax.servlet.Filter;
import java.net.MalformedURLException;
import java.util.LinkedHashMap;
import java.util.Map;
@Configuration
public class ShiroConfig {
@Value("${shiro.session-timeout}")
private int sessionTimeout;
@Value("${shiro.retryCount}")
private int retryCount;
@Value("${shiro.algorithmName}")
private String algorithmName;
@Value("${shiro.iterations}")
private int iterations;
@Value("${shiro.loginUrl}")
private String loginUrl;
@Value("${shiro.successUrl}")
private String successUrl;
@Value("${shiro.unauthorizedUrl}")
private String unauthorizedUrl;
@Value("${wayn.ssoServerUrl}")
private String ssoServerUrl;
@Value("${wayn.currentServerUrl}")
private String currentServerUrl;
@Autowired
private RedisOpts opts;
@Autowired
private CacheManager cacheManager;
@Autowired
private DeptService deptService;
@Bean
public static LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
}
@Bean
ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager);
shiroFilterFactoryBean.setLoginUrl(loginUrl);
shiroFilterFactoryBean.setSuccessUrl(successUrl);
shiroFilterFactoryBean.setUnauthorizedUrl(unauthorizedUrl);
// 定义自己的过滤器
Map<String, Filter> filters = new LinkedHashMap<>();
filters.put("tokenLogin", tokenLoginFilter());
filters.put("logout", logoutFilter());
filters.put("tokenValidate", ssoTokenValidateFilter());
filters.put("onlineSession", onlineSessionFilter());
shiroFilterFactoryBean.setFilters(filters);
// 定义过滤器链
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
filterChainDefinitionMap.put("/favicon.ico", "anon");
filterChainDefinitionMap.put("/upload/**", "anon");
filterChainDefinitionMap.put("/plugin/**", "anon");
filterChainDefinitionMap.put("/css/**", "anon");
filterChainDefinitionMap.put("/fonts/**", "anon");
filterChainDefinitionMap.put("/img/**", "anon");
filterChainDefinitionMap.put("/js/**", "anon");
filterChainDefinitionMap.put("/login", "tokenLogin");
filterChainDefinitionMap.put("/rpc/**", "anon");
filterChainDefinitionMap.put("/logout", "logout");
filterChainDefinitionMap.put("/**", "authc,tokenValidate,onlineSession");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
public OnlineSessionFilter onlineSessionFilter() {
OnlineSessionFilter onlineSessionFilter = new OnlineSessionFilter();
onlineSessionFilter.setForceLogoutUrl(loginUrl);
onlineSessionFilter.setSessionDAO(sessionDAO());
onlineSessionFilter.setDeptService(deptService);
return onlineSessionFilter;
}
public LogoutFilter logoutFilter() {
LogoutFilter logoutFilter = new LogoutFilter();
logoutFilter.setRedirectUrl(ssoServerUrl + "/logout?backUrl=" + currentServerUrl);
return logoutFilter;
}
public TokenLoginFilter tokenLoginFilter() {
TokenLoginFilter tokenValidateFilter = new TokenLoginFilter();
tokenValidateFilter.setFailureUrl(loginUrl);
tokenValidateFilter.setSuccessUrl(successUrl);
return tokenValidateFilter;
}
public SsoTokenValidateFilter ssoTokenValidateFilter() {
SsoTokenValidateFilter tokenValidateFilter = new SsoTokenValidateFilter();
try {
AuthcationRpcService authcationRpcService = (AuthcationRpcService) new HessianProxyFactory().create(AuthcationRpcService.class,
ssoServerUrl + "/rpc/authcationRpcService");
tokenValidateFilter.setAuthcationRpcService(authcationRpcService);
} catch (MalformedURLException e) {
e.printStackTrace();
throw new RuntimeException("SsoTokenValidateFilter:authcationRpcService初始化失败!");
}
return tokenValidateFilter;
}
@Bean
public SecurityManager securityManager() {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
// 设置realm
securityManager.setRealm(ssoRealm());
// 自定义缓存实现 使用redis
securityManager.setCacheManager(rediscacheManager());
securityManager.setSessionManager(sessionManager());
return securityManager;
}
@Bean
SsoRealm ssoRealm() {
SsoRealm ssoRealm = new SsoRealm();
ssoRealm.setSsoServerUrl(ssoServerUrl);
// 定义自己的的密码验证服务
MyCredentialsMatcher credentialsMatcher = new MyCredentialsMatcher();
Cache passwordRetryCache = cacheManager.getCache("passwordRetryCache");
RedisCache targetCache = (RedisCache) ((TransactionAwareCacheDecorator) passwordRetryCache).getTargetCache();
credentialsMatcher.setPasswordRetryCache(targetCache);
credentialsMatcher.setRetryCount(retryCount);
credentialsMatcher.setHashAlgorithmName(algorithmName);
credentialsMatcher.setHashIterations(iterations);
ssoRealm.setCredentialsMatcher(credentialsMatcher);
return ssoRealm;
}
/**
* 启动shiro注解
*/
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
// 强制使用cglib,防止重复代理和可能引起代理出错的问题
// https://zhuanlan.zhihu.com/p/29161098
defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
return defaultAdvisorAutoProxyCreator;
}
@Bean
pub
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot,Shiro,Redis,Mybatis的多模块系统, 通用后台管理,mall商城
共986个文件
js:401个
java:141个
css:106个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 124 浏览量
2024-05-15
13:46:57
上传
评论
收藏 22.42MB ZIP 举报
温馨提示
该项目利用了基于springboot + vue + mysql的开发模式框架实现的课设系统,包括了项目的源码资源、sql文件、相关指引文档等等。 【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【技术】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot,Shiro,Redis,Mybatis的多模块系统, 通用后台管理,mall商城 (986个子文件)
bootstrap.min.css.bak 118KB
bootstrap.min.css.bak 118KB
bootstrap.min.css.bak 118KB
bootstrap.css 143KB
bootstrap.css 143KB
bootstrap.css 143KB
style.css 136KB
style.css 136KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
animate.css 65KB
animate.css 65KB
animate.css 65KB
font-awesome.css 37KB
font-awesome.css 37KB
font-awesome.css 37KB
style.css 32KB
font-awesome.min.css 30KB
font-awesome.min.css 30KB
font-awesome.min.css 30KB
style.css 29KB
summernote-lite.css 28KB
style.min.css 27KB
bootstrap-theme.css 26KB
bootstrap-theme.css 26KB
bootstrap-theme.css 26KB
style.min.css 25KB
bootstrap-table-group-by.min.css 24KB
bootstrap-table-group-by.css 24KB
bootstrap-switch.css 23KB
bootstrap-theme.min.css 23KB
bootstrap-theme.min.css 23KB
bootstrap-theme.min.css 23KB
bootstrap-switch.min.css 19KB
summernote.css 18KB
summernote-bs4.css 18KB
select2.css 17KB
select2-bootstrap.min.css 16KB
layer.css 15KB
layer.css 15KB
layer.css 15KB
select2.min.css 15KB
layer.css 11KB
layer.css 11KB
layer.css 11KB
layim.css 11KB
layim.css 11KB
layim.css 11KB
bootstrap-table-semantic.css 10KB
bootstrap-table-bulma.css 10KB
bootstrap-table-foundation.css 10KB
bootstrap-table-materialize.css 10KB
bootstrap-table-semantic.min.css 9KB
bootstrap-table-bulma.min.css 9KB
bootstrap-table-foundation.min.css 9KB
bootstrap-table.css 9KB
bootstrap-table-materialize.min.css 9KB
bootstrap-table.min.css 8KB
laydate.css 8KB
jquery.contextMenu.css 7KB
layout-default-latest.css 6KB
toastr.min.css 6KB
bootstrap-switch.css 6KB
laydate.css 6KB
laydate.css 6KB
laydate.css 6KB
jquery.contextMenu.min.css 6KB
jquery.contextMenu.min.css 6KB
bootstrap-switch.min.css 5KB
layer.css 5KB
layer.css 5KB
layer.css 5KB
select2-flat-theme.min.css 5KB
style.css 4KB
style.css 4KB
style.css 4KB
style.css 4KB
style.css 4KB
style.css 4KB
laydate.css 3KB
laydate.css 3KB
laydate.css 3KB
jquery.layout-latest.css 3KB
layer.ext.css 3KB
layer.ext.css 3KB
layer.ext.css 3KB
login.css 3KB
login.css 3KB
cropbox.css 2KB
custom.css 1KB
jquery.jsonview.css 1KB
jquery.treegrid.css 1KB
bootstrap-table-reorder-rows.min.css 1KB
bootstrap-table-tree-column.min.css 904B
bootstrap-table-reorder-rows.css 819B
bootstrap-table-fixed-columns.min.css 805B
bootstrap-table-multiple-selection-row.min.css 591B
bootstrap-table-tree-column.css 582B
bootstrap-table-fixed-columns.css 547B
共 986 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
枫蜜柚子茶
- 粉丝: 6863
- 资源: 5108
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功