已添加1个文件
已删除1个文件
已修改13个文件
已重命名11个文件
| | |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | private LoginUserInfo getLoginUser () { |
| | | return (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | try { |
| | | return (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | }catch (Exception e){ |
| | | |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | |
| | | package doumeemes.config.shiro; |
| | | |
| | | import doumeemes.core.model.ApiResponse; |
| | | import com.alibaba.fastjson.JSON; |
| | | import doumeemes.core.model.ApiResponse; |
| | | import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.ServletRequest; |
| | | import javax.servlet.ServletResponse; |
| | |
| | | /** |
| | | * Shiro认è¯è¿æ»¤å¨ï¼å¤çæªè®¤è¯æ
åµçååº |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2023/04/17 12:11 |
| | | */ |
| | | public class ShiroAuthFilter extends FormAuthenticationFilter { |
| | | |
| | |
| | | package doumeemes.config.shiro; |
| | | |
| | | import doumeemes.service.proxy.CacheProxy; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.shiro.cache.Cache; |
| | | import org.apache.shiro.cache.CacheException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.apache.shiro.subject.PrincipalCollection; |
| | | import org.apache.shiro.util.CollectionUtils; |
| | | import org.springframework.context.annotation.Scope; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.serializer.SerializationException; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.lang.reflect.Method; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.Set; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * Shiroç¼å |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2023/04/17 12:11 |
| | | */ |
| | | //@Scope(value = "prototype") |
| | | @Scope(value = "prototype") |
| | | @Slf4j |
| | | //@Component |
| | | @Component |
| | | public class ShiroCache implements Cache<Object, Serializable> { |
| | | |
| | | private String keyPrefix = ""; |
| | | |
| | | @Autowired |
| | | private CacheProxy<Object, Serializable> cacheProxy; |
| | | @Resource(name="sessionRedisTemplate") |
| | | private RedisTemplate<Object, Serializable> redisTemplate; |
| | | |
| | | public ShiroCache () { |
| | | log.debug("ShiroCache: new, keyPrefix = [" + keyPrefix + "]"); |
| | |
| | | if (key == null) { |
| | | return null; |
| | | } |
| | | return cacheProxy.get(getKey(key)); |
| | | return redisTemplate.opsForValue().get(getKey(key)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (key == null) { |
| | | return null; |
| | | } |
| | | cacheProxy.put(getKey(key), value); |
| | | redisTemplate.opsForValue().set(getKey(key), value); |
| | | return value; |
| | | } |
| | | |
| | |
| | | if (key == null) { |
| | | return null; |
| | | } |
| | | cacheProxy.put(getKey(key), value, timeout); |
| | | redisTemplate.opsForValue().set(getKey(key), value, timeout, TimeUnit.SECONDS); |
| | | return value; |
| | | } |
| | | |
| | | @Override |
| | | public void clear() throws CacheException { |
| | | Set<Object> keys = this.keys(); |
| | | cacheProxy.remove(keys); |
| | | redisTemplate.delete(keys); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public Set<Object> keys() { |
| | | Set<Object> keys = cacheProxy.keys(keyPrefix + "*"); |
| | | Set<Object> keys = redisTemplate.keys(keyPrefix + "*"); |
| | | if (CollectionUtils.isEmpty(keys)) { |
| | | return Collections.emptySet(); |
| | | } |
| | |
| | | return values; |
| | | } |
| | | for (Object k : keys) { |
| | | values.add(cacheProxy.get(k)); |
| | | values.add(redisTemplate.opsForValue().get(k)); |
| | | } |
| | | return values; |
| | | } |
| | |
| | | return null; |
| | | } |
| | | Serializable value = this.get(getKey(key)); |
| | | cacheProxy.remove(getKey(key)); |
| | | redisTemplate.delete(getKey(key)); |
| | | return value; |
| | | } |
| | | |
| | | private Object getKey (Object key) { |
| | | if (key instanceof PrincipalCollection) { |
| | | return this.keyPrefix + getRedisKeyFromPrincipalIdField((PrincipalCollection)key); |
| | | } |
| | | return (key instanceof String ? (this.keyPrefix + key) : key); |
| | | } |
| | | |
| | | /** |
| | | * è·åredis cache key |
| | | */ |
| | | private String getRedisKeyFromPrincipalIdField(PrincipalCollection key) { |
| | | Object principalObject = key.getPrimaryPrincipal(); |
| | | if (principalObject instanceof String) { |
| | | return principalObject.toString(); |
| | | } else { |
| | | Method pincipalIdGetter = this.getPrincipalIdGetter(principalObject); |
| | | return this.getIdObj(principalObject, pincipalIdGetter); |
| | | } |
| | | } |
| | | |
| | | private Method getPrincipalIdGetter(Object principalObject) { |
| | | Method pincipalIdGetter; |
| | | String principalIdMethodName = this.getPrincipalIdMethodName(); |
| | | |
| | | try { |
| | | pincipalIdGetter = principalObject.getClass().getMethod(principalIdMethodName); |
| | | return pincipalIdGetter; |
| | | } catch (NoSuchMethodException e) { |
| | | throw new SerializationException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | private String getIdObj(Object principalObject, Method pincipalIdGetter) { |
| | | try { |
| | | Object idObj = pincipalIdGetter.invoke(principalObject); |
| | | String redisKey = idObj.toString(); |
| | | return redisKey; |
| | | } catch (Exception e) { |
| | | throw new SerializationException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | private String getPrincipalIdMethodName() { |
| | | return "getId"; |
| | | } |
| | | } |
| | |
| | | /** |
| | | * èªå®ä¹Shiro CacheManager |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2023/04/17 12:11 |
| | | */ |
| | | @Slf4j |
| | | //@Component |
| | | @Component |
| | | public class ShiroCacheManager implements CacheManager { |
| | | |
| | | private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap(); |
| | |
| | | package doumeemes.config.shiro; |
| | | |
| | | import doumeemes.task.ScheduleTool; |
| | | import org.apache.shiro.mgt.SecurityManager; |
| | | import org.apache.shiro.session.mgt.SessionManager; |
| | | import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; |
| | | import org.apache.shiro.spring.web.ShiroFilterFactoryBean; |
| | | import org.apache.shiro.util.ThreadContext; |
| | | import org.apache.shiro.web.mgt.DefaultWebSecurityManager; |
| | | import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| | | |
| | | import javax.servlet.Filter; |
| | | import java.util.HashMap; |
| | | import java.io.Serializable; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Shiroé
ç½® |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2023/04/17 12:11 |
| | | */ |
| | | //@Configuration |
| | | @Configuration |
| | | public class ShiroConfig { |
| | | |
| | | @Value("${cache.session.expire}") |
| | |
| | | |
| | | @Autowired |
| | | private ShiroRealm shiroRealm; |
| | | |
| | | @Bean("sessionRedisTemplate") |
| | | public RedisTemplate<Object, Serializable> sessionRedisTemplate(RedisConnectionFactory redisConnectionFactory) { |
| | | RedisTemplate<Object, Serializable> redisTemplate = new RedisTemplate<>(); |
| | | redisTemplate.setConnectionFactory(redisConnectionFactory); |
| | | // é»è®¤åºååæ¹å¼ |
| | | redisTemplate.setDefaultSerializer(new StringRedisSerializer()); |
| | | // å¼åºååæ¹å¼ |
| | | ShiroSessionSerializer serializer = new ShiroSessionSerializer(); |
| | | redisTemplate.setValueSerializer(serializer); |
| | | redisTemplate.setHashValueSerializer(serializer); |
| | | redisTemplate.afterPropertiesSet(); |
| | | return redisTemplate; |
| | | } |
| | | |
| | | @Bean |
| | | public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { |
| | |
| | | securityManager.setRealm(shiroRealm); |
| | | securityManager.setSessionManager(this.sessionManager()); |
| | | securityManager.setCacheManager(shiroCacheManager); |
| | | ThreadContext.bind(securityManager); |
| | | return securityManager; |
| | | } |
| | | |
| | |
| | | shiroFilterFactoryBean.setSecurityManager(securityManager); |
| | | Map<String, String> map = new LinkedHashMap<>(); |
| | | // è·¯å¾æ¦æªé
ç½® |
| | | map.put("/web/user/login", "anon"); |
| | | map.put("/public/uploadRichText", "anon"); |
| | | map.put("/system/login", "anon"); |
| | | map.put("/system/wxLogin", "anon"); |
| | | map.put("/system/wxProgramLogin", "anon"); |
| | | map.put("/system/wxAccountLogin", "anon"); |
| | | map.put("/system/initCompany", "anon"); |
| | | map.put("/system/logout", "anon"); |
| | | map.put("/common/captcha", "anon"); |
| | | map.put("/statistics/**", "anon"); |
| | | map.put("/dingding/push", "anon"); |
| | | // map.put("/ext/workorderExt/freshStatistics", "anon"); |
| | | map.put("/dingding/jsapiTicket", "anon"); |
| | | map.put("/dingding/ddLogin", "anon"); |
| | | map.put("/dingding/getDingdingCorpId", "anon"); |
| | | map.put("/lingyang/login", "anon"); |
| | | map.put("/lingyang/loginDemo", "anon"); |
| | | map.put("/edgp/**", "anon"); |
| | | //æ¾è¡ scratch æ¥å£ |
| | | map.put("/web/scratch/**", "anon"); |
| | | |
| | | // - æ¾è¡swagger |
| | | map.put("/doc.html", "anon"); |
| | | map.put("/webjars/**", "anon"); |
| | | map.put("/template/**", "anon"); |
| | | map.put("/swagger-resources/**", "anon"); |
| | | map.put("/v2/api-docs/**", "anon"); |
| | | // - å
¶ä»æ¥å£ç»ä¸æ¦æª |
| | |
| | | package doumeemes.config.shiro; |
| | | |
| | | import doumeemes.config.shiro.ShiroToken; |
| | | import doumeemes.core.utils.Utils; |
| | | import doumeemes.dao.system.model.SystemUser; |
| | | import doumeemes.service.system.SystemUserService; |
| | |
| | | /** |
| | | * Shiroå¯ç æ¯å¯¹å¤ç |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2023/04/17 12:11 |
| | | */ |
| | | //@Component |
| | | @Component |
| | | public class ShiroCredentialsMatcher extends HashedCredentialsMatcher { |
| | | |
| | | @Lazy |
| | | @Autowired |
| | | private SystemUserService systemUserService; |
| | |
| | | import doumeemes.core.exception.BusinessException; |
| | | import doumeemes.core.model.LoginUserInfo; |
| | | import doumeemes.core.utils.Constants; |
| | | import doumeemes.dao.business.model.Company; |
| | | import doumeemes.dao.business.model.CompanyUser; |
| | | import doumeemes.dao.business.model.Department; |
| | | import doumeemes.dao.ext.dto.QueryCompanyUserExtDTO; |
| | | import doumeemes.dao.ext.vo.CompanyExtListVO; |
| | | import doumeemes.dao.ext.vo.CompanyUserExtListVO; |
| | |
| | | import doumeemes.dao.system.model.SystemPermission; |
| | | import doumeemes.dao.system.model.SystemRole; |
| | | import doumeemes.dao.system.model.SystemUser; |
| | | import doumeemes.service.business.CompanyUserService; |
| | | import doumeemes.service.ext.CompanyExtService; |
| | | import doumeemes.service.ext.CompanyUserExtService; |
| | | import doumeemes.service.ext.DepartmentExtService; |
| | |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * èªå®ä¹Realmï¼å¤ç认è¯åæé |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2022/03/15 09:54 |
| | | */ |
| | | //@Component |
| | | @Component |
| | | public class ShiroRealm extends AuthorizingRealm { |
| | | |
| | | @Lazy |
| | |
| | | private DepartmentExtService departmentExtService; |
| | | @Lazy |
| | | @Autowired |
| | | private SystemDataPermissionService systemDataPermissionService; |
| | | private SystemDataPermissionService systemDataPermissionService; |
| | | @Lazy |
| | | @Autowired |
| | | private CompanyExtService companyExtService; |
| | |
| | | @Lazy |
| | | @Autowired |
| | | private SystemPermissionService systemPermissionService; |
| | | /** |
| | | * éåsupportsæ¹æ³ï¼ä½¿ Shiro è½å¤è¯å«èªå®ä¹ç Token |
| | | * @param token |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean supports(AuthenticationToken token) { |
| | | return token instanceof ShiroToken; |
| | | } |
| | | |
| | | /** |
| | | * æéå¤ç |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2022/03/15 09:54 |
| | | */ |
| | | @Override |
| | | protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { |
| | |
| | | /** |
| | | * 认è¯å¤ç |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2022/03/15 09:54 |
| | | */ |
| | | @Override |
| | | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException,BusinessException { |
| | | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { |
| | | // è·åç¨æ·å |
| | | ShiroToken authenticationToken =(ShiroToken) token; |
| | | String username = authenticationToken.getPrincipal().toString(); |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroRedisSessionDAO.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiro; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.SerializationUtils; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.*; |
| | | import java.util.Collection; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * èªå®ä¹Shiro SessionDAOï¼å°ä¼è¯ä¿¡æ¯åå
¥ç¼åä¸ |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2023/04/17 12:11 |
| | | */ |
| | | //@Data |
| | | @Data |
| | | @Slf4j |
| | | //@Component |
| | | @Component |
| | | public class ShiroSessionDAO implements SessionDAO { |
| | | |
| | | private static final String KEY_PREFIX = "shiro:session:"; |
| | |
| | | @Autowired |
| | | private ShiroCache shiroCache; |
| | | |
| | | private int expireTime = 1800; |
| | | private int expireTime = 60 * 60 * 24; |
| | | |
| | | @Autowired |
| | | private ShiroTokenManager shiroTokenManager; |
| | |
| | | /** |
| | | * èªå®ä¹ä¼è¯ç®¡çå¨ |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2023/04/17 12:11 |
| | | */ |
| | | @Slf4j |
| | | public class ShiroSessionManager extends DefaultSessionManager implements WebSessionManager { |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroSessionSerializer.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiro; |
| | | |
| | | import org.apache.commons.lang3.SerializationUtils; |
| | | import org.apache.shiro.codec.Base64; |
| | |
| | | package doumeemes.config.shiro; |
| | | |
| | | import doumeemes.core.model.LoginUserInfo; |
| | | import doumeemes.core.utils.Constants; |
| | | import doumeemes.dao.business.model.Department; |
| | | import doumeemes.dao.ext.dto.QueryCompanyUserExtDTO; |
| | | import doumeemes.dao.ext.vo.CompanyUserExtListVO; |
| | | import doumeemes.dao.system.model.SystemPermission; |
| | | import doumeemes.dao.system.model.SystemRole; |
| | | import doumeemes.dao.system.model.SystemUser; |
| | | import doumeemes.service.ext.CompanyUserExtService; |
| | | import doumeemes.service.system.SystemPermissionService; |
| | | import doumeemes.service.system.SystemRoleService; |
| | | import doumeemes.service.system.SystemUserService; |
| | | import org.apache.shiro.authc.*; |
| | | import org.apache.shiro.authz.AuthorizationInfo; |
| | | import org.apache.shiro.authz.SimpleAuthorizationInfo; |
| | | import org.apache.shiro.realm.AuthorizingRealm; |
| | | import org.apache.shiro.subject.PrincipalCollection; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * èªå®ä¹Token ï¼å¤ç认è¯åæé |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | //@Component |
| | | @Component |
| | | public class ShiroToken extends UsernamePasswordToken { |
| | | |
| | | /** |
| | |
| | | |
| | | public ShiroToken() { |
| | | } |
| | | public ShiroToken(Integer companyId,String username, String password,boolean isDdLogin,boolean isWxLogin) { |
| | | public ShiroToken(Integer companyId, String username, String password, boolean isDdLogin, boolean isWxLogin) { |
| | | super(username, password, false, (String)null); |
| | | this.companyId = companyId; |
| | | this.isDdLogin = isDdLogin; |
| | |
| | | /** |
| | | * é»è®¤Token管çå¨ |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | * @date 2023/04/17 12:11 |
| | | */ |
| | | //@Component |
| | | @Component |
| | | public class ShiroTokenManager { |
| | | |
| | | String build() { |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroAuthFilter.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import doumeemes.core.model.ApiResponse; |
| | | import com.alibaba.fastjson.JSON; |
| | | import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; |
| | | import org.springframework.http.HttpStatus; |
| | | |
| | |
| | | /** |
| | | * Shiro认è¯è¿æ»¤å¨ï¼å¤çæªè®¤è¯æ
åµçååº |
| | | * @author Eva.Caesar Liu |
| | | * @date 2023/04/17 12:11 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | public class ShiroAuthFilter extends FormAuthenticationFilter { |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import doumeemes.service.proxy.CacheProxy; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.shiro.cache.Cache; |
| | | import org.apache.shiro.cache.CacheException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * Shiroç¼å |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | //@Scope(value = "prototype") |
| | | @Slf4j |
| | | //@Component |
| | | public class ShiroCache implements Cache<Object, Serializable> { |
| | | |
| | | private String keyPrefix = ""; |
| | | |
| | | @Autowired |
| | | private CacheProxy<Object, Serializable> cacheProxy; |
| | | |
| | | public ShiroCache () { |
| | | log.debug("ShiroCache: new, keyPrefix = [" + keyPrefix + "]"); |
| | | } |
| | | |
| | | public ShiroCache(String keyPrefix) { |
| | | log.debug("ShiroCache: new, keyPrefix = [" + keyPrefix + "]"); |
| | | this.keyPrefix = keyPrefix; |
| | | } |
| | | |
| | | @Override |
| | | public Serializable get(Object key) throws CacheException { |
| | | if (key == null) { |
| | | return null; |
| | | } |
| | | return cacheProxy.get(getKey(key)); |
| | | } |
| | | |
| | | @Override |
| | | public Serializable put(Object key, Serializable value) throws CacheException { |
| | | if (key == null) { |
| | | return null; |
| | | } |
| | | cacheProxy.put(getKey(key), value); |
| | | return value; |
| | | } |
| | | |
| | | public Serializable put(Object key, Serializable value, int timeout) throws CacheException { |
| | | if (key == null) { |
| | | return null; |
| | | } |
| | | cacheProxy.put(getKey(key), value, timeout); |
| | | return value; |
| | | } |
| | | |
| | | @Override |
| | | public void clear() throws CacheException { |
| | | Set<Object> keys = this.keys(); |
| | | cacheProxy.remove(keys); |
| | | } |
| | | |
| | | @Override |
| | | public int size() { |
| | | return this.keys().size(); |
| | | } |
| | | |
| | | @Override |
| | | public Set<Object> keys() { |
| | | Set<Object> keys = cacheProxy.keys(keyPrefix + "*"); |
| | | if (CollectionUtils.isEmpty(keys)) { |
| | | return Collections.emptySet(); |
| | | } |
| | | return keys; |
| | | } |
| | | |
| | | @Override |
| | | public Collection<Serializable> values() { |
| | | Collection<Serializable> values = new ArrayList<>(); |
| | | Set<Object> keys = this.keys(); |
| | | if (CollectionUtils.isEmpty(keys)) { |
| | | return values; |
| | | } |
| | | for (Object k : keys) { |
| | | values.add(cacheProxy.get(k)); |
| | | } |
| | | return values; |
| | | } |
| | | |
| | | @Override |
| | | public Serializable remove(Object key) throws CacheException { |
| | | if (key == null) { |
| | | return null; |
| | | } |
| | | Serializable value = this.get(getKey(key)); |
| | | cacheProxy.remove(getKey(key)); |
| | | return value; |
| | | } |
| | | |
| | | private Object getKey (Object key) { |
| | | return (key instanceof String ? (this.keyPrefix + key) : key); |
| | | } |
| | | } |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroCacheManager.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.shiro.cache.Cache; |
| | |
| | | import org.apache.shiro.cache.CacheManager; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.ConcurrentMap; |
| | |
| | | /** |
| | | * èªå®ä¹Shiro CacheManager |
| | | * @author Eva.Caesar Liu |
| | | * @date 2023/04/17 12:11 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | //@Component |
| | | public class ShiroCacheManager implements CacheManager { |
| | | |
| | | private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap(); |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroConfig.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import org.apache.shiro.mgt.SecurityManager; |
| | | import org.apache.shiro.session.mgt.SessionManager; |
| | | import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; |
| | | import org.apache.shiro.spring.web.ShiroFilterFactoryBean; |
| | | import org.apache.shiro.util.ThreadContext; |
| | | import org.apache.shiro.web.mgt.DefaultWebSecurityManager; |
| | | import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| | | |
| | | import javax.servlet.Filter; |
| | | import java.io.Serializable; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Shiroé
ç½® |
| | | * @author Eva.Caesar Liu |
| | | * @date 2023/04/17 12:11 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Configuration |
| | | //@Configuration |
| | | public class ShiroConfig { |
| | | |
| | | @Value("${cache.session.expire}") |
| | |
| | | |
| | | @Autowired |
| | | private ShiroRealm shiroRealm; |
| | | |
| | | @Bean("sessionRedisTemplate") |
| | | public RedisTemplate<Object, Serializable> sessionRedisTemplate(RedisConnectionFactory redisConnectionFactory) { |
| | | RedisTemplate<Object, Serializable> redisTemplate = new RedisTemplate<>(); |
| | | redisTemplate.setConnectionFactory(redisConnectionFactory); |
| | | // é»è®¤åºååæ¹å¼ |
| | | redisTemplate.setDefaultSerializer(new StringRedisSerializer()); |
| | | // å¼åºååæ¹å¼ |
| | | ShiroSessionSerializer serializer = new ShiroSessionSerializer(); |
| | | redisTemplate.setValueSerializer(serializer); |
| | | redisTemplate.setHashValueSerializer(serializer); |
| | | redisTemplate.afterPropertiesSet(); |
| | | return redisTemplate; |
| | | } |
| | | |
| | | @Bean |
| | | public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { |
| | |
| | | securityManager.setRealm(shiroRealm); |
| | | securityManager.setSessionManager(this.sessionManager()); |
| | | securityManager.setCacheManager(shiroCacheManager); |
| | | ThreadContext.bind(securityManager); |
| | | return securityManager; |
| | | } |
| | | |
| | |
| | | shiroFilterFactoryBean.setSecurityManager(securityManager); |
| | | Map<String, String> map = new LinkedHashMap<>(); |
| | | // è·¯å¾æ¦æªé
ç½® |
| | | map.put("/web/user/login", "anon"); |
| | | map.put("/public/uploadRichText", "anon"); |
| | | map.put("/system/login", "anon"); |
| | | map.put("/system/wxLogin", "anon"); |
| | | map.put("/system/wxProgramLogin", "anon"); |
| | | map.put("/system/wxAccountLogin", "anon"); |
| | | map.put("/system/initCompany", "anon"); |
| | | map.put("/system/logout", "anon"); |
| | | map.put("/common/captcha", "anon"); |
| | | //æ¾è¡ scratch æ¥å£ |
| | | map.put("/web/scratch/**", "anon"); |
| | | |
| | | map.put("/statistics/**", "anon"); |
| | | map.put("/dingding/push", "anon"); |
| | | // map.put("/ext/workorderExt/freshStatistics", "anon"); |
| | | map.put("/dingding/jsapiTicket", "anon"); |
| | | map.put("/dingding/ddLogin", "anon"); |
| | | map.put("/dingding/getDingdingCorpId", "anon"); |
| | | map.put("/lingyang/login", "anon"); |
| | | map.put("/lingyang/loginDemo", "anon"); |
| | | map.put("/edgp/**", "anon"); |
| | | // - æ¾è¡swagger |
| | | map.put("/doc.html", "anon"); |
| | | map.put("/webjars/**", "anon"); |
| | | map.put("/template/**", "anon"); |
| | | map.put("/swagger-resources/**", "anon"); |
| | | map.put("/v2/api-docs/**", "anon"); |
| | | // - å
¶ä»æ¥å£ç»ä¸æ¦æª |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroCredentialsMatcher.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import doumeemes.config.shiro.ShiroToken; |
| | | import doumeemes.core.utils.Utils; |
| | | import doumeemes.dao.system.model.SystemUser; |
| | | import doumeemes.service.system.SystemUserService; |
| | | import org.apache.shiro.authc.AuthenticationInfo; |
| | | import org.apache.shiro.authc.AuthenticationToken; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.authc.credential.HashedCredentialsMatcher; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * Shiroå¯ç æ¯å¯¹å¤ç |
| | | * @author Eva.Caesar Liu |
| | | * @date 2023/04/17 12:11 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Component |
| | | //@Component |
| | | public class ShiroCredentialsMatcher extends HashedCredentialsMatcher { |
| | | |
| | | @Lazy |
| | | @Autowired |
| | | private SystemUserService systemUserService; |
| | | |
| | | @Override |
| | | public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { |
| | | doumeemes.config.shiro.ShiroToken usernamePasswordToken = (ShiroToken) token; |
| | | ShiroToken usernamePasswordToken = (ShiroToken) token; |
| | | SystemUser queryUserDto = new SystemUser(); |
| | | queryUserDto.setUsername(usernamePasswordToken.getUsername()); |
| | | queryUserDto.setDeleted(Boolean.FALSE); |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroRealm.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import doumeemes.core.constants.ResponseStatus; |
| | | import doumeemes.core.exception.BusinessException; |
| | |
| | | import doumeemes.service.system.SystemPermissionService; |
| | | import doumeemes.service.system.SystemRoleService; |
| | | import doumeemes.service.system.SystemUserService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.authc.AuthenticationException; |
| | | import org.apache.shiro.authc.AuthenticationInfo; |
| | | import org.apache.shiro.authc.AuthenticationToken; |
| | |
| | | import org.apache.shiro.subject.PrincipalCollection; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | /** |
| | | * èªå®ä¹Realmï¼å¤ç认è¯åæé |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/03/15 09:54 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Component |
| | | //@Component |
| | | public class ShiroRealm extends AuthorizingRealm { |
| | | |
| | | @Lazy |
| | |
| | | private DepartmentExtService departmentExtService; |
| | | @Lazy |
| | | @Autowired |
| | | private SystemDataPermissionService systemDataPermissionService; |
| | | private SystemDataPermissionService systemDataPermissionService; |
| | | @Lazy |
| | | @Autowired |
| | | private CompanyExtService companyExtService; |
| | |
| | | @Lazy |
| | | @Autowired |
| | | private SystemPermissionService systemPermissionService; |
| | | |
| | | /** |
| | | * éåsupportsæ¹æ³ï¼ä½¿ Shiro è½å¤è¯å«èªå®ä¹ç Token |
| | | * @param token |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean supports(AuthenticationToken token) { |
| | | return token instanceof ShiroToken; |
| | | } |
| | | /** |
| | | * æéå¤ç |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/03/15 09:54 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Override |
| | | protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { |
| | |
| | | /** |
| | | * 认è¯å¤ç |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/03/15 09:54 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Override |
| | | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { |
| | | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException,BusinessException { |
| | | // è·åç¨æ·å |
| | | ShiroToken authenticationToken =(ShiroToken) token; |
| | | String username = authenticationToken.getPrincipal().toString(); |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroSessionDAO.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.shiro.session.Session; |
| | | import org.apache.shiro.session.UnknownSessionException; |
| | | import org.apache.shiro.session.mgt.SimpleSession; |
| | | import org.apache.shiro.session.mgt.eis.SessionDAO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Collection; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * èªå®ä¹Shiro SessionDAOï¼å°ä¼è¯ä¿¡æ¯åå
¥ç¼åä¸ |
| | | * @author Eva.Caesar Liu |
| | | * @date 2023/04/17 12:11 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Data |
| | | //@Data |
| | | @Slf4j |
| | | @Component |
| | | //@Component |
| | | public class ShiroSessionDAO implements SessionDAO { |
| | | |
| | | private static final String KEY_PREFIX = "shiro:session:"; |
| | |
| | | @Autowired |
| | | private ShiroCache shiroCache; |
| | | |
| | | private int expireTime = 60 * 60 * 24; |
| | | private int expireTime = 1800; |
| | | |
| | | @Autowired |
| | | private ShiroTokenManager shiroTokenManager; |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroSessionManager.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.shiro.session.Session; |
| | |
| | | /** |
| | | * èªå®ä¹ä¼è¯ç®¡çå¨ |
| | | * @author Eva.Caesar Liu |
| | | * @date 2023/04/17 12:11 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Slf4j |
| | | public class ShiroSessionManager extends DefaultSessionManager implements WebSessionManager { |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroToken.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.springframework.stereotype.Component; |
| | | import org.apache.shiro.authc.*; |
| | | |
| | | /** |
| | | * èªå®ä¹Token ï¼å¤ç认è¯åæé |
| | | * @author Eva.Caesar Liu |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Component |
| | | //@Component |
| | | public class ShiroToken extends UsernamePasswordToken { |
| | | |
| | | /** |
ÎļþÃû´Ó server/src/main/java/doumeemes/config/shiroRedis/ShiroTokenManager.java ÐÞ¸Ä |
| | |
| | | package doumeemes.config.shiroRedis; |
| | | package doumeemes.config.shiroMemory; |
| | | |
| | | import doumeemes.core.exception.UnSafeSessionException; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * é»è®¤Token管çå¨ |
| | | * @author Eva.Caesar Liu |
| | | * @date 2023/04/17 12:11 |
| | | * @date 2022/04/18 18:12 |
| | | */ |
| | | @Component |
| | | //@Component |
| | | public class ShiroTokenManager { |
| | | |
| | | String build() { |
| | |
| | | package doumeemes.service.system.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.iflytek.antelope.other.client.dto.resp.UserDTO; |
| | | import doumeemes.biz.system.SystemDictDataBiz; |
| | | import doumeemes.config.shiro.ShiroToken; |
| | |
| | | import doumeemes.core.utils.dingding.DingDingUtil; |
| | | import doumeemes.core.utils.dingding.LingyangUtil; |
| | | import doumeemes.core.utils.edpg.EdgpServerUtil; |
| | | import doumeemes.core.utils.edpg.EdgpUtil; |
| | | import doumeemes.core.utils.edpg.bean.AppUserInfoModel; |
| | | import doumeemes.dao.business.dto.CompanyInitDataDTO; |
| | | import doumeemes.dao.business.model.Company; |
| | | import doumeemes.dao.business.model.CompanyUser; |
| | | import doumeemes.dao.ext.CompanyExtMapper; |
| | |
| | | import doumeemes.dao.ext.CompanyExtMapper; |
| | | import doumeemes.dao.ext.CompanyUserExtMapper; |
| | | import doumeemes.dao.ext.DepartmentExtMapper; |
| | | import doumeemes.dao.ext.dto.QueryCompanyUserExtDTO; |
| | | import doumeemes.dao.ext.dto.WxLoginDTO; |
| | | import doumeemes.dao.ext.dto.WxLoginOutDTO; |
| | | import doumeemes.dao.ext.vo.CompanyUserExtListVO; |
| | | import doumeemes.dao.ext.vo.WxLoginVO; |
| | | import doumeemes.dao.system.SystemUserMapper; |
| | | import doumeemes.dao.system.dto.LoginDTO; |
| | | import doumeemes.dao.system.model.SystemLoginLog; |
| | | import doumeemes.dao.system.model.SystemUser; |
| | | import doumeemes.service.common.CaptchaService; |
| | | import doumeemes.service.ext.CompanyExtService; |
| | | import doumeemes.service.ext.CompanyUserExtService; |
| | | import doumeemes.service.system.SystemLoginLogService; |
| | | import doumeemes.service.system.WxLoginService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |