diff --git a/src/main/java/neatlogic/framework/asynchronization/threadlocal/UserContext.java b/src/main/java/neatlogic/framework/asynchronization/threadlocal/UserContext.java index b104140acc86a79ae19ff054a0de7ce57f6b9928..4829f25bbe617745a67880771835a4909c11e3d3 100644 --- a/src/main/java/neatlogic/framework/asynchronization/threadlocal/UserContext.java +++ b/src/main/java/neatlogic/framework/asynchronization/threadlocal/UserContext.java @@ -50,6 +50,10 @@ public class UserContext implements Serializable { //是否超级管理员 private Boolean isSuperAdmin = false; + private String tokenHash; + + private String env = null; + public static UserContext init(UserContext _userContext) { UserContext context = new UserContext(); if (_userContext != null) { @@ -102,6 +106,10 @@ public class UserContext implements Serializable { context.setResponse(response); context.setTimezone(timezone); context.setAuthenticationInfoVo(authenticationInfoVo); + if (userVo.getJwtVo() != null) { + context.setTokenHash(userVo.getJwtVo().getTokenHash()); + context.setEnv(userVo.getJwtVo().getEnv()); + } instance.set(context); return context; } @@ -259,8 +267,24 @@ public class UserContext implements Serializable { } public void setIsSuperAdmin(Boolean isSuperAdmin) { - if(isSuperAdmin != null) { + if (isSuperAdmin != null) { this.isSuperAdmin = isSuperAdmin; } } + + public String getTokenHash() { + return tokenHash; + } + + public void setTokenHash(String tokenHash) { + this.tokenHash = tokenHash; + } + + public String getEnv() { + return env; + } + + public void setEnv(String env) { + this.env = env; + } } diff --git a/src/main/java/neatlogic/framework/dao/cache/UserSessionCache.java b/src/main/java/neatlogic/framework/dao/cache/UserSessionCache.java index 00411f4f3ddca2da21265305513f44b028cefa56..10461fd1858ec38db08bda1adc172489a1528551 100644 --- a/src/main/java/neatlogic/framework/dao/cache/UserSessionCache.java +++ b/src/main/java/neatlogic/framework/dao/cache/UserSessionCache.java @@ -7,39 +7,39 @@ import net.sf.ehcache.config.CacheConfiguration; import net.sf.ehcache.config.Configuration; public class UserSessionCache { - private static CacheManager CACHE_MANAGER; + private static CacheManager CACHE_MANAGER; - private synchronized static Ehcache getCache() { - if (CACHE_MANAGER == null) { - CacheConfiguration cacheConfiguration = new CacheConfiguration(); - cacheConfiguration.setName("UserSessionCache"); - cacheConfiguration.setMemoryStoreEvictionPolicy("LRU"); - cacheConfiguration.setMaxEntriesLocalHeap(1000); - cacheConfiguration.internalSetTimeToIdle(300); - cacheConfiguration.internalSetTimeToLive(600); - Configuration config = new Configuration(); - config.addCache(cacheConfiguration); - CACHE_MANAGER = CacheManager.newInstance(config); - } - if (!CACHE_MANAGER.cacheExists("UserSessionCache")) { - CACHE_MANAGER.addCache("UserSessionCache"); - } - return CACHE_MANAGER.getEhcache("UserSessionCache"); - } + private synchronized static Ehcache getCache() { + if (CACHE_MANAGER == null) { + CacheConfiguration cacheConfiguration = new CacheConfiguration(); + cacheConfiguration.setName("UserSessionCache"); + cacheConfiguration.setMemoryStoreEvictionPolicy("LRU"); + cacheConfiguration.setMaxEntriesLocalHeap(1000); + cacheConfiguration.internalSetTimeToIdle(300); + cacheConfiguration.internalSetTimeToLive(600); + Configuration config = new Configuration(); + config.addCache(cacheConfiguration); + CACHE_MANAGER = CacheManager.newInstance(config); + } + if (!CACHE_MANAGER.cacheExists("UserSessionCache")) { + CACHE_MANAGER.addCache("UserSessionCache"); + } + return CACHE_MANAGER.getEhcache("UserSessionCache"); + } - public static void addItem(String tenant, String userUuid, Object item) { - getCache().put(new Element(tenant + ":" + userUuid, item)); - } + public static void addItem(String key, Object item) { + getCache().put(new Element(key, item)); + } - public static Object getItem(String tenant, String userUuid) { - Element cachedElement = getCache().get(tenant + ":" + userUuid); - if (cachedElement == null) { - return null; - } - return cachedElement.getObjectValue(); - } + public static Object getItem(String key) { + Element cachedElement = getCache().get(key); + if (cachedElement == null) { + return null; + } + return cachedElement.getObjectValue(); + } - public static boolean removeItem(String tenant, String userUuid){ - return getCache().remove(tenant + ":" + userUuid); - } + public static void removeItem(String key) { + getCache().remove(key); + } } diff --git a/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.java b/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.java index d694615b646ca3d9efcd2cf895783d87f149aa3b..a6d67d9522c42829eeaee5ab51d0f20e87b20e02 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.java +++ b/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.java @@ -35,6 +35,8 @@ public interface RoleMapper { List getRoleUuidListByUserUuid(String userUuid); + List getRoleUuidListByUserUuidAndEnv(@Param("userUuid") String userUuid, @Param("env") String env); + List searchRoleForSelect(RoleVo roleVo); List searchRoleAuthByRoleUuid(String roleUuid); @@ -69,9 +71,11 @@ public interface RoleMapper { List getRoleTeamListByRoleUuidList(@Param("list") List roleList); - List getRoleUserListByRoleUuidList(@Param("list")List roleList); + List getRoleUserListByRoleUuidList(@Param("list") List roleList); + + List getRoleUuidListByTeamUuidListAndEnv(@Param("teamUuidList") List teamUuidList, @Param("env") String env); - List getRoleUuidListByTeamUuidListAndCheckedChildren(@Param("teamUuidList") List teamUuidList, @Param("checkedChildren") Integer checkedChildren); + List getRoleUuidListByTeamUuidListAndCheckedChildrenAndEnv(@Param("teamUuidList") List teamUuidList, @Param("checkedChildren") Integer checkedChildren, @Param("env") String env); /** * 根据team的uuid获取当前组的roleList diff --git a/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.xml b/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.xml index 7671472bfd147ad26d2efbb4345dcc7df39b818f..9649499cd35b5ece4898bb22c2abafecbfad67e3 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.xml +++ b/src/main/java/neatlogic/framework/dao/mapper/RoleMapper.xml @@ -48,7 +48,7 @@ limitations under the License. a.`description` FROM `role` a LEFT JOIN `role_authority` c ON a.`uuid` = c.`role_uuid` - + AND (name LIKE CONCAT('%',#{keyword}, '%') OR description LIKE CONCAT('%',#{keyword}, '%')) @@ -58,13 +58,13 @@ limitations under the License. AND c.`auth` = #{auth} - - and uuid in - - #{roleUuid} - - - + + and uuid in + + #{roleUuid} + + + GROUP BY a.`uuid` ORDER BY a.`id` DESC @@ -126,7 +126,8 @@ limitations under the License. SELECT `id`, `uuid`, `name`, - `description` + `description`, + `env` FROM `role` WHERE `uuid` = #{value} @@ -216,9 +217,8 @@ limitations under the License. @@ -256,13 +256,32 @@ limitations under the License. - + SELECT tr.`role_uuid` FROM `team_role` tr + + left join `role` r on r.uuid= tr.role_uuid + + WHERE tr.`team_uuid` IN + + #{teamUuid} + + AND tr.`checked_children` = #{checkedChildren} + + and (r.`env` = #{env} or r.`env` is null ) + + + + @@ -278,13 +297,13 @@ limitations under the License. @@ -338,11 +357,22 @@ limitations under the License. #{item} + - INSERT INTO `role` (`id`, `uuid`, `name`, `description`) - VALUES (#{id}, #{uuid}, #{name}, #{description}) + INSERT INTO `role` (`id`, `uuid`, `name`, `description`, `env`) + VALUES (#{id}, #{uuid}, #{name}, #{description}, #{env}) @@ -374,7 +404,8 @@ limitations under the License. UPDATE `role` SET `name` = #{name}, - `description` = #{description} + `description` = #{description}, + `env` = #{env} WHERE `uuid` = #{uuid} diff --git a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.java b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.java index 23a6fd416116203c98d57d908b19f6836ce88a2f..399ee355ab8a25f126901a8d5e8d91d6080d9840 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.java +++ b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.java @@ -55,7 +55,9 @@ public interface UserMapper { UserVo getUserById(Long id); - UserVo getUserByUuid(String uuid); + UserVo getUserByUuidAndEnv(@Param("uuid") String uuid, @Param("env") String env); + + UserVo getUserByUuid(@Param("uuid") String uuid); UserVo getUserSimpleInfoByUuid(String uuid); @@ -73,7 +75,7 @@ public interface UserMapper { List searchUserAuthByUserUuid(String userUuid); - List searchUserAllAuthByUserAuth(UserAuthVo userAuthVo); + List searchUserAllAuthByUserAuth(@Param("authenticationInfoVo") AuthenticationInfoVo authenticationInfoVo, @Param("env") String env); List searchUserAllAuthByUserAuthCache(UserAuthVo userAuthVo); diff --git a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml index e8a7f5efd260b9a728d0682040cc9deaed176228..10b311ffa65a01278ea0120f4b6f094baa191daa 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml +++ b/src/main/java/neatlogic/framework/dao/mapper/UserMapper.xml @@ -166,6 +166,35 @@ limitations under the License. + + - SELECT `auth_group` AS authGroup, `auth` FROM `user_authority` - WHERE `user_uuid` = #{userUuid} - - AND `auth` = #{auth} + WHERE `user_uuid` = #{authenticationInfoVo.userUuid} + + UNION + SELECT + ra.`auth_group` AS authGroup, + ra.`auth` + FROM `role_authority` ra + + JOIN `role` r on ra.role_uuid = r.uuid + + + AND r.`env` = #{env} or r.`env` is null + + WHERE ra.`role_uuid` in + + #{roleUuid} + - UNION - SELECT - c.`auth_group` AS authGroup, - c.`auth` - FROM `user_team` a - JOIN `team_role` b ON b.`team_uuid` = a.`team_uuid` - JOIN `role_authority` c ON c.`role_uuid` = b.`role_uuid` - WHERE a.`user_uuid` = #{userUuid} - - AND `auth` = #{auth} + + UNION + SELECT + `auth_group` AS authGroup, + `auth` + FROM `user_authority` + WHERE `user_uuid` in + + #{userUuid} + diff --git a/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.java b/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.java index 90892ab4a66d79e92a6eaa9153a6a1ceacec4048..732a8d148b7119fec648e6ee70700ca0851999bf 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.java +++ b/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.java @@ -23,7 +23,7 @@ import java.util.Date; import java.util.List; public interface UserSessionMapper { - UserSessionVo getUserSessionByUserUuid(String userUuid); + UserSessionVo getUserSessionByTokenHash(String userUuid); int getAllOnlineUserCount(Date sessionTime); @@ -48,10 +48,12 @@ public interface UserSessionMapper { int getUserSessionCountByDate(String limitDate); - int insertUserSession(@Param("userUuid") String userUuid, @Param("authInfo") String authInfo); + int insertUserSession(@Param("userUuid") String userUuid, @Param("tokenHash") String tokenHash, @Param("tokenCreateTime") Long tokenCreateTime, @Param("authInfo") String authInfo); - int updateUserSession(String userUuid); + int insertUserSessionWithoutTokenCreateTime(@Param("userUuid") String userUuid, @Param("tokenHash") String tokenHash, @Param("tokenCreateTime") Long tokenCreateTime, @Param("authInfo") String authInfo); - int deleteUserSessionByUserUuid(String userUuid); + int updateUserSession(String tokenHash); + + int deleteUserSessionByTokenHash(String tokenHash); } \ No newline at end of file diff --git a/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.xml b/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.xml index ccb8eeea9aa363870f7c580a4ee420e950a2d1d6..1a17f04ce6a37e3e593931e2b192ada3ec1dbdac 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.xml +++ b/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.xml @@ -19,11 +19,11 @@ limitations under the License. -