From 9a2b1251fc48874b76d3b02dbfc306698325dfeb Mon Sep 17 00:00:00 2001 From: whycxzp <glperry@163.com> Date: 星期三, 10 一月 2024 10:53:38 +0800 Subject: [PATCH] 更新 --- src/main/java/com/whyc/pojo/RoleMenu.java | 2 src/main/java/com/whyc/config/RedisSessionDao.java | 10 +- src/main/java/com/whyc/pojo/Role.java | 2 src/main/java/com/whyc/pojo/Menu.java | 2 src/main/java/com/whyc/properties/PropertiesUtil.java | 3 src/main/java/com/whyc/config/StaticResourceConfig.java | 6 src/main/java/com/whyc/pojo/Permission.java | 2 src/main/java/com/whyc/pojo/UserRole.java | 2 /dev/null | 27 ------ src/main/java/com/whyc/config/ShiroConfig.java | 30 +------ src/main/java/com/whyc/pojo/RolePermission.java | 2 src/main/java/com/whyc/pojo/User.java | 2 src/main/java/com/whyc/service/UserService.java | 2 src/main/java/com/whyc/controller/RoleController.java | 5 - src/main/resources/config/application.yml | 17 ++- src/main/java/com/whyc/config/RedisConfig.java | 27 ++++++ src/main/java/com/whyc/filter/CrossDomainFilter.java | 2 src/main/java/com/whyc/service/UserBridgeService.java | 22 +---- src/main/resources/config/authentication.properties.bak | 27 ++++++ src/main/java/com/whyc/Application.java | 6 - 20 files changed, 90 insertions(+), 108 deletions(-) diff --git a/src/main/java/com/whyc/Application.java b/src/main/java/com/whyc/Application.java index 46d331c..1b3802e 100644 --- a/src/main/java/com/whyc/Application.java +++ b/src/main/java/com/whyc/Application.java @@ -3,14 +3,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; -import org.springframework.cache.annotation.EnableCaching; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; -import org.springframework.web.servlet.view.InternalResourceViewResolver; /** * @Description : 鍚姩绫� @@ -19,7 +14,6 @@ @SpringBootApplication @EnableWebMvc @ServletComponentScan(basePackages = {"com.whyc.filter","com.whyc.servlet"}) -@EnableCaching public class Application extends WebMvcConfigurerAdapter implements WebMvcConfigurer { public static void main(String[] args) { diff --git a/src/main/java/com/whyc/config/RedisConfig.java b/src/main/java/com/whyc/config/RedisConfig.java index 2061cc9..4437092 100644 --- a/src/main/java/com/whyc/config/RedisConfig.java +++ b/src/main/java/com/whyc/config/RedisConfig.java @@ -31,7 +31,7 @@ @ConditionalOnProperty(name = "redis.model", havingValue = "single") @Order(1) RedissonClient redissonClientSingle() { - log.error("redis鍗曟満鐗坈lient鍒濆鍖栦簡"); + log.error("redis single client鍒濆鍖栦簡"); Config config = new Config(); String node = redisProperties.getSingle().getAddress(); SingleServerConfig serverConfig = config.useSingleServer() @@ -53,7 +53,7 @@ @Bean("redisClient") @ConditionalOnProperty(name = "redis.model", havingValue = "sentinel") RedissonClient redissonClientSentinel() { - log.error("redis鍗曟満鐗坈lient鍒濆鍖栦簡"); + log.error("redis sentinel client鍒濆鍖栦簡"); Config config = new Config(); String[] nodes = redisProperties.getSentinel().getNodes().split(","); @@ -79,7 +79,7 @@ @Bean("redisClient") @ConditionalOnProperty(name = "redis.model", havingValue = "cluster") RedissonClient redissonClientCluster() { - log.error("redis鍗曟満鐗坈lient鍒濆鍖栦簡"); + log.error("redis cluster client鍒濆鍖栦簡"); Config config = new Config(); RedisClusterProperties cluster = redisProperties.getCluster(); RedisPoolProperties pool = redisProperties.getPool(); @@ -102,4 +102,25 @@ return Redisson.create(config); } + /** + * + */ + @Bean("redisClient") + @ConditionalOnProperty(name = "redis.model", havingValue = "master-slave") + RedissonClient redissonClientMasterSlave() { + log.error("redis master-slave client鍒濆鍖栦簡"); + Config config = new Config(); + RedisClusterProperties cluster = redisProperties.getCluster(); + RedisPoolProperties pool = redisProperties.getPool(); + String[] nodes = cluster.getNodes().split(","); + MasterSlaveServersConfig serversConfig = config.useMasterSlaveServers() + .setMasterAddress(nodes[0]) + .addSlaveAddress(nodes[1]); + + if (!StringUtils.isEmpty(redisProperties.getPassword())) { + serversConfig.setPassword(redisProperties.getPassword()); + } + return Redisson.create(config); + } + } diff --git a/src/main/java/com/whyc/config/RedisSessionDao.java b/src/main/java/com/whyc/config/RedisSessionDao.java index e59ef6b..99c5c0e 100644 --- a/src/main/java/com/whyc/config/RedisSessionDao.java +++ b/src/main/java/com/whyc/config/RedisSessionDao.java @@ -7,11 +7,15 @@ import org.apache.shiro.session.Session; import org.apache.shiro.session.UnknownSessionException; import org.apache.shiro.session.mgt.eis.AbstractSessionDAO; +import org.redisson.Redisson; import org.redisson.api.RBucket; import org.redisson.api.RedissonClient; +import org.redisson.config.Config; +import org.redisson.config.SingleServerConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.context.annotation.DependsOn; +import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.io.Serializable; @@ -24,9 +28,6 @@ */ @Slf4j public class RedisSessionDao extends AbstractSessionDAO { - - /*@Resource(name = "redissonClient4Shiro") - RedissonClient redissonClient;*/ @Autowired RedissonClient redissonClient; @@ -45,7 +46,8 @@ //灏哠ession瀛樺叆redis RBucket<String> sessionIdBucket = redissonClient.getBucket(SuperConstant.GROUP_CAS + sessionId.toString()); - sessionIdBucket.trySet(ShiroRedissionSerialize.serialize(session),globalSessionTimeout, TimeUnit.SECONDS); + sessionIdBucket.trySet(ShiroRedissionSerialize.serialize(session),globalSessionTimeout, TimeUnit.MILLISECONDS); + log.info("session鍒涘缓:SessionId:{}",session.getId().toString()); return sessionId; } diff --git a/src/main/java/com/whyc/config/ShiroConfig.java b/src/main/java/com/whyc/config/ShiroConfig.java index 8c8b1be..ec88027 100644 --- a/src/main/java/com/whyc/config/ShiroConfig.java +++ b/src/main/java/com/whyc/config/ShiroConfig.java @@ -1,42 +1,29 @@ package com.whyc.config; -import com.whyc.filter.KickedOutFilter; -import com.whyc.filter.RolesOrAuthorizationFilter; import com.whyc.properties.PropertiesUtil; import com.whyc.properties.RedisProperties; -import com.whyc.properties.ShiroRedisProperties; import com.whyc.realm.CustomRealm; -import lombok.extern.log4j.Log4j; -import lombok.extern.log4j.Log4j2; import lombok.extern.slf4j.Slf4j; -import org.apache.shiro.session.mgt.SessionManager; 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.authz.RolesAuthorizationFilter; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.apache.shiro.web.servlet.SimpleCookie; import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; -import org.redisson.Redisson; -import org.redisson.api.RedissonClient; -import org.redisson.config.Config; import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; -import javax.servlet.Filter; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /** - * 鏆傛椂鎻愪緵鏉冮檺绠$悊,浼氳瘽绠$悊鍚庣画鏇存柊 TODO + * 鏆傛椂鎻愪緵鏉冮檺绠$悊,浼氳瘽绠$悊鍚庣画鏇存柊 */ @Configuration @Slf4j @@ -96,8 +83,9 @@ sessionManager.setSessionDAO(redisSessionDao()); sessionManager.setSessionValidationSchedulerEnabled(false); sessionManager.setSessionIdCookieEnabled(true); + sessionManager.setSessionIdUrlRewritingEnabled(false); - SimpleCookie simpleCookie = new SimpleCookie("ShiroSession"); + SimpleCookie simpleCookie = new SimpleCookie("CT"); sessionManager.setSessionIdCookie(simpleCookie); sessionManager.setGlobalSessionTimeout(redisProperties.getGlobalSessionTimeout()); return sessionManager; @@ -153,23 +141,15 @@ return map; } - /**鑷畾涔夎繃婊ゅ櫒*/ - private Map<String, Filter> filters(){ - HashMap<String, Filter> map = new HashMap<>(); - map.put("rolesOr",new RolesOrAuthorizationFilter()); - return map; - } - /**杩囨护鍣�*/ -// @Bean("shiroFilter") @Bean public ShiroFilterFactoryBean shiroFilterFactoryBean(){ ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean(); //娉ㄥ叆鏂板畾涔夌殑杩囨护鍣� - shiroFilter.setFilters(filters()); + //shiroFilter shiroFilter.setSecurityManager(defaultWebSecurityManager()); shiroFilter.setFilterChainDefinitionMap(filterChainDefinition()); - shiroFilter.setLoginUrl("/login.html"); + shiroFilter.setLoginUrl("/index.html"); //shiroFilter.setLoginUrl("/index.html#login"); shiroFilter.setUnauthorizedUrl("/login/unauthorized"); return shiroFilter; diff --git a/src/main/java/com/whyc/config/StaticResourceConfig.java b/src/main/java/com/whyc/config/StaticResourceConfig.java index 0e1ef55..afb2c5e 100644 --- a/src/main/java/com/whyc/config/StaticResourceConfig.java +++ b/src/main/java/com/whyc/config/StaticResourceConfig.java @@ -13,15 +13,15 @@ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - - //杩欎釜鏄彲琛岀殑,瑙f瀽鐨勬椂鍊檖ath涓�*.html,鏍¢獙璺緞admin涓嬫槸鍚﹀瓨鍦� + registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/"); + /*//杩欎釜鏄彲琛岀殑,瑙f瀽鐨勬椂鍊檖ath涓�*.html,鏍¢獙璺緞admin涓嬫槸鍚﹀瓨鍦� //registry.addResourceHandler("admin/*.html").addResourceLocations("classpath:/META-INF/resources/admin/"); registry.addResourceHandler("/map/*").addResourceLocations("classpath:/META-INF/resources/map/"); //registry.addResourceHandler("/login.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("*.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); - registry.addResourceHandler("/service-worker.js").addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("/service-worker.js").addResourceLocations("classpath:/META-INF/resources/");*/ //registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/META-INF/resources/"); super.addResourceHandlers(registry); //registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); diff --git a/src/main/java/com/whyc/controller/RoleController.java b/src/main/java/com/whyc/controller/RoleController.java index 034794d..2a3fdd5 100644 --- a/src/main/java/com/whyc/controller/RoleController.java +++ b/src/main/java/com/whyc/controller/RoleController.java @@ -10,7 +10,6 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CacheEvict; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; @@ -75,14 +74,12 @@ @PostMapping("bindingUserWithRole") @ApiOperation(value = "缁戝畾鐢ㄦ埛鍜岃鑹�") - @CacheEvict(cacheNames = {"userBridge"},key="'getAuthorizationInfo'+#p0") //娓呴櫎 public boolean bindingUserWithRole(@RequestParam int userId,int roleId){ return userRoleService.bindingUserWithRole(userId,roleId); } @PostMapping("bindingUserWithRoleBatch") @ApiOperation(value = "鎵归噺缁戝畾鐢ㄦ埛鍜岃鑹�",notes = "浼犲叆userId鍜宺oleId鐨勬暟缁�") - @CacheEvict(cacheNames = {"userBridge"},allEntries = true) //鍏ㄩ儴娓呴櫎 public boolean bindingUserWithRoleBatch(@RequestBody List<UserRole> userRoles){ return userRoleService.bindingUserWithRoleBatch(userRoles); } @@ -91,14 +88,12 @@ @PostMapping("bindingRoleWithPermission") @ApiOperation(value = "缁戝畾瑙掕壊-鏉冮檺") - @CacheEvict(cacheNames = {"userBridge"},allEntries = true) //鍏ㄩ儴娓呴櫎 public boolean bindingRoleWithPermission(@RequestParam int roleId,int permissionId){ return rolePermissionService.bindingUserWithRole(roleId,permissionId); } @PostMapping("bindingRoleWithPermissionBatch") @ApiOperation(value = "鎵归噺缁戝畾瑙掕壊-鏉冮檺",notes = "浼犲叆roleId鍜宲rivilegeId鐨勬暟缁�") - @CacheEvict(cacheNames = {"userBridge"},allEntries = true) //鍏ㄩ儴娓呴櫎 public boolean bindingRoleWithPermissionBatch(@RequestBody List<RolePermission> rolePermissions){ return rolePermissionService.bindingUserWithRoleBatch(rolePermissions); } diff --git a/src/main/java/com/whyc/filter/CrossDomainFilter.java b/src/main/java/com/whyc/filter/CrossDomainFilter.java index 2c63849..277a780 100644 --- a/src/main/java/com/whyc/filter/CrossDomainFilter.java +++ b/src/main/java/com/whyc/filter/CrossDomainFilter.java @@ -29,7 +29,7 @@ // String origin = "http://localhost:8080"; resp.setHeader("Access-Control-Allow-Origin", origin); resp.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type,token"); - resp.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH"); + resp.setHeader("Access-Control-Allow-Methods", "GET, POST,TRACE, OPTIONS, PATCH"); resp.setHeader("Access-Control-Allow-Credentials", "true"); chain.doFilter(request, resp); diff --git a/src/main/java/com/whyc/filter/LoginFilter.java b/src/main/java/com/whyc/filter/LoginFilter.java deleted file mode 100644 index 9f51187..0000000 --- a/src/main/java/com/whyc/filter/LoginFilter.java +++ /dev/null @@ -1,58 +0,0 @@ -//package com.whyc.filter; -// -//import com.whyc.pojo.User; -//import lombok.extern.slf4j.Slf4j; -// -//import javax.servlet.*; -//import javax.servlet.annotation.WebFilter; -//import javax.servlet.annotation.WebInitParam; -//import javax.servlet.http.HttpServletRequest; -//import java.io.IOException; -//import java.io.PrintWriter; -// -//@Slf4j -///*@WebFilter(filterName = "loginFilter",urlPatterns = "/*",initParams = { -// @WebInitParam(name = "exclusions",value = "*.css,*.js") -//})*/ -////@WebInitParam(name = "exclusions",value = "*.css,*.js") -//public class LoginFilter implements Filter { -// -// private String exclusions = ""; -// -// public void destroy() { -// } -// -// public void doFilter(ServletRequest req, ServletResponse resp, -// FilterChain chain) throws IOException, ServletException { -// HttpServletRequest request=(HttpServletRequest)req; -// -// String URL=request.getRequestURI(); -// String[] uri=request.getRequestURI().split("/"); -// String source=""; -// if(uri.length>0) { -// source = uri[uri.length - 1]; -// } -// String suffix = source.substring(source.indexOf(".")+1); -// User user=(User)request.getSession().getAttribute("user"); -// -// //涓嶆嫤鎴猻wagger鐨勮祫婧愯姹�,浠ュ強鐧诲綍璇锋眰 -// if(URL.indexOf("swagger-resources")>-1 ||URL.indexOf("swagger-ui")>-1 ||URL.indexOf("v2/api-docs")>-1||URL.indexOf("login")>-1){ -// chain.doFilter(req,resp); -// } -// //涓嶆嫤鎴潤鎬佽祫婧恈ss/js -// else if(exclusions.indexOf(suffix)>-1){ -// chain.doFilter(req,resp); -// } -// else if(user!=null){ -// chain.doFilter(req, resp); -// }else{ -// PrintWriter out=resp.getWriter(); -// out.print("<script charset='UTF-8'>window.location.href='index.html'</script>"); -// } -// } -// -// public void init(FilterConfig config) throws ServletException { -// exclusions =config.getInitParameter("exclusions"); -// } -// -//} diff --git a/src/main/java/com/whyc/filter/RolesOrAuthorizationFilter.java b/src/main/java/com/whyc/filter/RolesOrAuthorizationFilter.java deleted file mode 100644 index 9986794..0000000 --- a/src/main/java/com/whyc/filter/RolesOrAuthorizationFilter.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.whyc.filter; - -import com.whyc.pojo.User; -import org.apache.shiro.subject.Subject; -import org.apache.shiro.util.CollectionUtils; -import org.apache.shiro.web.filter.authz.AuthorizationFilter; - -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import java.util.Set; - -/** - * 鑷畾涔夎繃婊よ鍒�,鍙渶瑕佸寘鍚煇涓鑹�,灏辨巿鏉� - */ -public class RolesOrAuthorizationFilter extends AuthorizationFilter { - @Override - protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { - Subject subject = getSubject(request, response); - String[] rolesArray = (String[]) mappedValue; - - if (rolesArray == null || rolesArray.length == 0) { - return true; - } - - Set<String> roles = CollectionUtils.asSet(rolesArray); - - //鍒ゆ柇涓簅r - User user = (User) subject.getPrincipals().getPrimaryPrincipal(); - for (String role :roles){ - if (subject.hasRole(role)){ - return true; - } - } - return false; - } -} diff --git a/src/main/java/com/whyc/pojo/Menu.java b/src/main/java/com/whyc/pojo/Menu.java index d79b537..11d8868 100644 --- a/src/main/java/com/whyc/pojo/Menu.java +++ b/src/main/java/com/whyc/pojo/Menu.java @@ -7,7 +7,7 @@ * 鐢ㄦ埛鑿滃崟 */ @Alias("Menu") -@TableName( schema = "`db_3.5mw_web`",value = "`tb_menu`") +@TableName( schema = "`db_cluster_test`",value = "`tb_menu`") public class Menu { private Integer id; private String name; diff --git a/src/main/java/com/whyc/pojo/Permission.java b/src/main/java/com/whyc/pojo/Permission.java index c232041..909ab23 100644 --- a/src/main/java/com/whyc/pojo/Permission.java +++ b/src/main/java/com/whyc/pojo/Permission.java @@ -7,7 +7,7 @@ * 鏉冮檺 */ @Alias("Permission") -@TableName( schema = "`db_3.5mw_web`",value = "tb_permission") +@TableName( schema = "`db_cluster_test`",value = "tb_permission") public class Permission { private Integer id; diff --git a/src/main/java/com/whyc/pojo/Role.java b/src/main/java/com/whyc/pojo/Role.java index 8ebdf5c..0afc67c 100644 --- a/src/main/java/com/whyc/pojo/Role.java +++ b/src/main/java/com/whyc/pojo/Role.java @@ -8,7 +8,7 @@ * 瑙掕壊 */ @Alias("Role") -@TableName( schema = "`db_3.5mw_web`",value = "tb_role") +@TableName( schema = "`db_cluster_test`",value = "tb_role") public class Role { private Integer id; @TableField("name") diff --git a/src/main/java/com/whyc/pojo/RoleMenu.java b/src/main/java/com/whyc/pojo/RoleMenu.java index c41aa8a..3f178e4 100644 --- a/src/main/java/com/whyc/pojo/RoleMenu.java +++ b/src/main/java/com/whyc/pojo/RoleMenu.java @@ -7,7 +7,7 @@ * 瑙掕壊鑿滃崟 */ @Alias("RoleMenu") -@TableName( schema = "`db_3.5mw_web`",value = "tb_role_menu") +@TableName( schema = "`db_cluster_test`",value = "tb_role_menu") public class RoleMenu { private Integer id; private Integer roleId; diff --git a/src/main/java/com/whyc/pojo/RolePermission.java b/src/main/java/com/whyc/pojo/RolePermission.java index 2e866f9..d074ab7 100644 --- a/src/main/java/com/whyc/pojo/RolePermission.java +++ b/src/main/java/com/whyc/pojo/RolePermission.java @@ -7,7 +7,7 @@ * 瑙掕壊瀵瑰簲鏉冮檺 */ @Alias("RolePrivilege") -@TableName( schema = "`db_3.5mw_web`",value = "tb_role_privilege") +@TableName( schema = "`db_cluster_test`",value = "tb_role_privilege") public class RolePermission { private Integer id; diff --git a/src/main/java/com/whyc/pojo/User.java b/src/main/java/com/whyc/pojo/User.java index 39d5e02..9b9105f 100644 --- a/src/main/java/com/whyc/pojo/User.java +++ b/src/main/java/com/whyc/pojo/User.java @@ -7,7 +7,7 @@ import java.io.Serializable; import java.util.Date; @Alias("User") -@TableName( schema = "`db_3.5mw_web`",value = "tb_user") +@TableName( schema = "`db_cluster_test`",value = "tb_user") public class User implements Serializable { private Integer id; private String name; diff --git a/src/main/java/com/whyc/pojo/UserRole.java b/src/main/java/com/whyc/pojo/UserRole.java index af37952..882aaee 100644 --- a/src/main/java/com/whyc/pojo/UserRole.java +++ b/src/main/java/com/whyc/pojo/UserRole.java @@ -8,7 +8,7 @@ * 鐢ㄦ埛瑙掕壊琛� */ @Alias("UserRole") -@TableName( schema = "`db_3.5mw_web`",value = "tb_user_role") +@TableName( schema = "`db_cluster_test`",value = "tb_user_role") public class UserRole { private Integer id; diff --git a/src/main/java/com/whyc/properties/PropertiesUtil.java b/src/main/java/com/whyc/properties/PropertiesUtil.java index 7f96a88..b9b8aef 100644 --- a/src/main/java/com/whyc/properties/PropertiesUtil.java +++ b/src/main/java/com/whyc/properties/PropertiesUtil.java @@ -1,7 +1,6 @@ package com.whyc.properties; import lombok.extern.log4j.Log4j2; -import org.springframework.util.StringUtils; /** * @Description 璇诲彇Properties鐨勫伐鍏风被 @@ -23,7 +22,7 @@ }*/ try { propertiesShiro.load(PropertiesUtil.class.getClassLoader() - .getResourceAsStream("config/authentication.properties")); + .getResourceAsStream("config/authentication.properties.bak")); } catch (Exception e) { log.warn("璧勬簮璺緞涓笉瀛樺湪authentication.properties鏉冮檺鏂囦欢锛屽拷鐣ヨ鍙栵紒"); } diff --git a/src/main/java/com/whyc/service/UserBridgeService.java b/src/main/java/com/whyc/service/UserBridgeService.java index 666c4d7..d996607 100644 --- a/src/main/java/com/whyc/service/UserBridgeService.java +++ b/src/main/java/com/whyc/service/UserBridgeService.java @@ -2,26 +2,21 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.whyc.mapper.*; -import com.whyc.pojo.Permission; +import com.whyc.mapper.RolePermissionMapper; +import com.whyc.mapper.UserMapper; +import com.whyc.mapper.UserRoleMapper; import com.whyc.pojo.User; import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.authz.SimpleAuthorizationInfo; -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.LinkedList; import java.util.List; /** * 澶勭悊 shiro璁よ瘉,鎺堟潈,鍜屾暟鎹簱浜や簰 */ @Service -//Unified Naming -@CacheConfig(cacheNames ={"userBridge"}) public class UserBridgeService { @Resource @@ -36,15 +31,10 @@ public User findPasswordAndSlatByUserName(String userName) { QueryWrapper<User> queryWrapper = Wrappers.query(); queryWrapper.select("id","name","password","salt").eq("name",userName); - try{ - return userMapper.selectOne(queryWrapper); - }catch (Exception e){ - e.printStackTrace(); - return new User(0,"鐢ㄦ埛涓嶅瓨鍦�"); - } + return userMapper.selectOne(queryWrapper); + } - @Cacheable(key = "#root.methodName+#p0.id") public AuthorizationInfo getAuthorizationInfo(User user) { System.out.println("=========鎵ц浜哢serBridgeService.getAuthorization鏂规硶=========="); SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); @@ -57,13 +47,11 @@ return authorizationInfo; } - //@Cacheable(key = "#root.methodName+#userId") private List<String> findPermissionsByUserId(int userId) { List<String> perms = rolePermissionMapper.findPermissionsByUserId(userId); return perms; } - //@Cacheable(key="#root.methodName+#userId") private List<String> findRolesByUserId(int userId) { List<String> roles =userRoleMapper.findRolesByUserId(userId); //roles.add("dev"); diff --git a/src/main/java/com/whyc/service/UserService.java b/src/main/java/com/whyc/service/UserService.java index fbc0857..055b193 100644 --- a/src/main/java/com/whyc/service/UserService.java +++ b/src/main/java/com/whyc/service/UserService.java @@ -32,7 +32,7 @@ public Response add(User user) { try { User userFound = userBridgeService.findPasswordAndSlatByUserName(user.getName()); - if (userFound.getId() != 0) { + if (userFound != null) { return new Response<>().set(1, false, "鐢ㄦ埛宸插瓨鍦�"); } user.setCreateTime(new Date()); diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 062492b..aca204b 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -1,15 +1,15 @@ #鏈嶅姟绔彛鍙� server: port: 8090 -# servlet: -# context-path: /motor + servlet: + context-path: /ct #鏁版嵁搴� spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3360/db_3.5mw_web?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true + url: jdbc:mysql://localhost:3360/db_cluster_test?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&useSSL=false # url: jdbc:mysql://192.168.10.221:3360/db_3.5mw_web?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true # url: jdbc:mysql://192.168.10.221:3360?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true # url: jdbc:mysql://192.168.10.222:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true @@ -58,12 +58,11 @@ # base-package: com.whyc.controller knife: enable: true -# enable: fase redis: - #妯″紡 single/sentinel/cluster + #妯″紡 single/sentinel/cluster/master-slave model: single timeout: 3000 - global-session-timeout: 360000 + global-session-timeout: 3000 password: #杩炴帴姹犻厤缃� pool: @@ -86,11 +85,15 @@ #闆嗙兢閰嶇疆 cluster: scan-interval: 1000 - nodes: redis://localhost:6379 + nodes: redis://localhost:6379,redis://localhost:6380 read-mode: SLAVE retry-attempts: 3 failed-attempts: 3 slave-connection-pool-size: 64 master-connection-pool-size: 64 retry-interval: 1500 + #闆嗙兢閰嶇疆 + master-slave: + scan-interval: 1000 + nodes: redis://localhost:6379,redis://localhost:6380 diff --git a/src/main/resources/config/authentication.properties b/src/main/resources/config/authentication.properties deleted file mode 100644 index 32ba9e6..0000000 --- a/src/main/resources/config/authentication.properties +++ /dev/null @@ -1,27 +0,0 @@ -#dev鎺ュ彛璋冭瘯鏃朵娇鐢� -#/**=anon - -#闈欐�佽祫婧愪笉鎷︽埅 -/static/**=anon -#鐧诲綍閾炬帴涓嶆嫤鎴� -/login.html=anon -/login/**=anon -/index.html=anon -#鎺ュ彛鏂囨。鐩稿叧涓嶆嫤鎴� -/doc.html=anon -/webjars/**=anon -/swagger-resources=anon -/swagger-resources/**=anon -/v2/api-docs-ext=anon -/v2/api-docs=anon - -#璁块棶/resource/**闇�瑕佹湁admin鐨勮鑹� -#/resource/**=roles-or[dev,SuperAdmin] - -#璁剧疆闇�瑕乸ermission鐨勬嫤鎴� -#/WaterComm/**=perms["water:all"] -#璁剧疆RolesOr鎷︽埅 -#/WaterComm/**=rolesOr["admin","dev"] - -#鍏朵粬閾炬帴鏄渶瑕佺櫥褰曠殑 -/**=authc diff --git a/src/main/resources/config/authentication.properties.bak b/src/main/resources/config/authentication.properties.bak new file mode 100644 index 0000000..3597393 --- /dev/null +++ b/src/main/resources/config/authentication.properties.bak @@ -0,0 +1,27 @@ +#dev鎺ュ彛璋冭瘯鏃朵娇鐢� +/**=anon + +#闈欐�佽祫婧愪笉鎷︽埅 +#/static/**=anon +##鐧诲綍閾炬帴涓嶆嫤鎴� +#/login.html=anon +#/login/**=anon +#/index.html=anon +##鎺ュ彛鏂囨。鐩稿叧涓嶆嫤鎴� +#/doc.html=anon +#/webjars/**=anon +#/swagger-resources=anon +#/swagger-resources/**=anon +#/v2/api-docs-ext=anon +#/v2/api-docs=anon + +#璁块棶/resource/**闇�瑕佹湁admin鐨勮鑹� +#/resource/**=roles-or[dev,SuperAdmin] + +#璁剧疆闇�瑕乸ermission鐨勬嫤鎴� +#/WaterComm/**=perms["water:all"] +#璁剧疆RolesOr鎷︽埅 +#/WaterComm/**=rolesOr["admin","dev"] + +#鍏朵粬閾炬帴鏄渶瑕佺櫥褰曠殑 +#/**=authc -- Gitblit v1.9.1