search(SearchDto searchDto) {
searchDto.setIsHighlighter(true);
searchDto.setSortCol("createTime");
return queryService.strQuery("sys_user", searchDto, SEARCH_LOGIC_DEL_DTO);
diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/ISysRoleService.java b/zlt-business/user-center/src/main/java/com/central/user/service/ISysRoleService.java
index 716a48a5..2d29f858 100644
--- a/zlt-business/user-center/src/main/java/com/central/user/service/ISysRoleService.java
+++ b/zlt-business/user-center/src/main/java/com/central/user/service/ISysRoleService.java
@@ -9,10 +9,13 @@
import com.central.common.service.ISuperService;
/**
-* @author zlt
+ * @author zlt
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
*/
public interface ISysRoleService extends ISuperService {
- void saveRole(SysRole sysRole);
+ void saveRole(SysRole sysRole) throws Exception;
void deleteRole(Long id);
@@ -28,7 +31,7 @@ public interface ISysRoleService extends ISuperService {
* @param sysRole
* @return Result
*/
- Result saveOrUpdateRole(SysRole sysRole);
+ Result saveOrUpdateRole(SysRole sysRole) throws Exception;
/**
* 查询所有角色
diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/ISysUserService.java b/zlt-business/user-center/src/main/java/com/central/user/service/ISysUserService.java
index 26adcb5d..aaf899fd 100644
--- a/zlt-business/user-center/src/main/java/com/central/user/service/ISysUserService.java
+++ b/zlt-business/user-center/src/main/java/com/central/user/service/ISysUserService.java
@@ -13,7 +13,10 @@
import com.central.common.model.SysUser;
/**
-* @author zlt
+ * @author zlt
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
*/
public interface ISysUserService extends ISuperService {
/**
@@ -98,7 +101,7 @@ public interface ISysUserService extends ISuperService {
*/
List findAllUsers(Map params);
- Result saveOrUpdateUser(SysUser sysUser);
+ Result saveOrUpdateUser(SysUser sysUser) throws Exception;
/**
* 删除用户
diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysRoleServiceImpl.java b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysRoleServiceImpl.java
index 4d28373d..8550e08d 100644
--- a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysRoleServiceImpl.java
+++ b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysRoleServiceImpl.java
@@ -29,7 +29,7 @@
@Slf4j
@Service
public class SysRoleServiceImpl extends SuperServiceImpl implements ISysRoleService {
- private final static String LOCK_KEY_ROLECODE = CommonConstant.LOCK_KEY_PREFIX+"rolecode:";
+ private final static String LOCK_KEY_ROLECODE = "rolecode:";
@Resource
private SysUserRoleMapper userRoleMapper;
@@ -42,7 +42,7 @@ public class SysRoleServiceImpl extends SuperServiceImpl
@Transactional(rollbackFor = Exception.class)
@Override
- public void saveRole(SysRole sysRole) {
+ public void saveRole(SysRole sysRole) throws Exception {
String roleCode = sysRole.getCode();
super.saveIdempotency(sysRole, lock
, LOCK_KEY_ROLECODE+roleCode, new QueryWrapper().eq("code", roleCode), "角色code已存在");
@@ -67,7 +67,7 @@ public PageResult findRoles(Map params) {
@Override
@Transactional
- public Result saveOrUpdateRole(SysRole sysRole) {
+ public Result saveOrUpdateRole(SysRole sysRole) throws Exception {
if (sysRole.getId() == null) {
this.saveRole(sysRole);
} else {
diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java
index ce667390..eedada4c 100644
--- a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java
+++ b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java
@@ -37,7 +37,7 @@
@Slf4j
@Service
public class SysUserServiceImpl extends SuperServiceImpl implements ISysUserService {
- private final static String LOCK_KEY_USERNAME = CommonConstant.LOCK_KEY_PREFIX+"username:";
+ private final static String LOCK_KEY_USERNAME = "username:";
@Autowired
private PasswordEncoder passwordEncoder;
@@ -80,10 +80,10 @@ public LoginAppUser getLoginAppUser(SysUser sysUser) {
loginAppUser.setRoles(sysRoles);
if (!CollectionUtils.isEmpty(sysRoles)) {
- Set roleIds = sysRoles.parallelStream().map(SuperEntity::getId).collect(Collectors.toSet());
+ Set roleIds = sysRoles.stream().map(SuperEntity::getId).collect(Collectors.toSet());
List menus = roleMenuMapper.findMenusByRoleIds(roleIds, CommonConstant.PERMISSION);
if (!CollectionUtils.isEmpty(menus)) {
- Set permissions = menus.parallelStream().map(p -> p.getPath())
+ Set permissions = menus.stream().map(p -> p.getPath())
.collect(Collectors.toSet());
// 设置权限集合
loginAppUser.setPermissions(permissions);
@@ -219,7 +219,7 @@ public Result updateEnabled(Map params) {
@Transactional(rollbackFor = Exception.class)
@Override
- public Result saveOrUpdateUser(SysUser sysUser) {
+ public Result saveOrUpdateUser(SysUser sysUser) throws Exception {
if (sysUser.getId() == null) {
if (StringUtils.isBlank(sysUser.getType())) {
sysUser.setType(UserType.BACKEND.name());
diff --git a/zlt-business/user-center/src/main/resources/application.yml b/zlt-business/user-center/src/main/resources/application.yml
index a9c65586..f9a8c71b 100644
--- a/zlt-business/user-center/src/main/resources/application.yml
+++ b/zlt-business/user-center/src/main/resources/application.yml
@@ -34,7 +34,10 @@ zlt:
- sys_role_user
- sys_role_menu
ignoreSqls:
+ # 用户关联角色时,显示所有角色
- com.central.user.mapper.SysRoleMapper.findAll
+ # 用户列表显示用户所关联的所有角色
+ - com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds
#审计日志
# audit-log:
# enabled: true
diff --git a/zlt-commons/pom.xml b/zlt-commons/pom.xml
index 2fbe456a..617efea0 100644
--- a/zlt-commons/pom.xml
+++ b/zlt-commons/pom.xml
@@ -4,7 +4,7 @@
com.zlt
central-platform
- 3.5.0
+ 5.4.0
zlt-commons
通用组件
@@ -16,10 +16,12 @@
zlt-db-spring-boot-starter
zlt-swagger2-spring-boot-starter
zlt-log-spring-boot-starter
- zlt-ribbon-spring-boot-starter
+ zlt-loadbalancer-spring-boot-starter
zlt-auth-client-spring-boot-starter
zlt-sentinel-spring-boot-starter
zlt-common-core
zlt-elasticsearch-spring-boot-starter
+ zlt-oss-spring-boot-starter
+ zlt-zookeeper-spring-boot-starter
\ No newline at end of file
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml b/zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml
index 710df120..f6a3d8a4 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml
@@ -5,7 +5,7 @@
com.zlt
zlt-commons
- 3.5.0
+ 5.4.0
4.0.0
jar
@@ -42,5 +42,10 @@
javax.servlet-api
provided
+
+ org.apache.tomcat.embed
+ tomcat-embed-websocket
+ true
+
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/AuthClientAutoConfiguration.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/AuthClientAutoConfiguration.java
new file mode 100644
index 00000000..17ede133
--- /dev/null
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/AuthClientAutoConfiguration.java
@@ -0,0 +1,21 @@
+package com.central.oauth2.common;
+
+import com.central.oauth2.common.properties.SecurityProperties;
+import com.central.oauth2.common.properties.TokenStoreProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.ComponentScan;
+
+/**
+ * 鉴权自动配置
+ *
+ * @author zlt
+ * @version 1.0
+ * @date 2021/7/24
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@EnableConfigurationProperties({SecurityProperties.class, TokenStoreProperties.class})
+@ComponentScan
+public class AuthClientAutoConfiguration {
+}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultResourceServerConf.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultResourceServerConf.java
index e3c4ccf7..71e6d114 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultResourceServerConf.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultResourceServerConf.java
@@ -9,6 +9,7 @@
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
+import org.springframework.security.oauth2.provider.authentication.TokenExtractor;
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
import org.springframework.security.oauth2.provider.expression.OAuth2WebSecurityExpressionHandler;
import org.springframework.security.oauth2.provider.token.TokenStore;
@@ -36,13 +37,17 @@ public class DefaultResourceServerConf extends ResourceServerConfigurerAdapter {
@Autowired
private SecurityProperties securityProperties;
+ @Resource
+ private TokenExtractor tokenExtractor;
+
@Override
public void configure(ResourceServerSecurityConfigurer resources) {
resources.tokenStore(tokenStore)
.stateless(true)
.authenticationEntryPoint(authenticationEntryPoint)
.expressionHandler(expressionHandler)
- .accessDeniedHandler(oAuth2AccessDeniedHandler);
+ .accessDeniedHandler(oAuth2AccessDeniedHandler)
+ .tokenExtractor(tokenExtractor);
}
@Override
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/SecurityPropertiesConfig.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/SecurityPropertiesConfig.java
deleted file mode 100644
index e85ed2a2..00000000
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/SecurityPropertiesConfig.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.central.oauth2.common.config;
-
-import com.central.oauth2.common.properties.SecurityProperties;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-
-/**
- * @author zlt
- * @date 2019/10/7
- *
- * Blog: https://blog.csdn.net/zlt2000
- * Github: https://github.com/zlt2000
- */
-@EnableConfigurationProperties(SecurityProperties.class)
-public class SecurityPropertiesConfig {
-}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/WcAuthConfigurator.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/WcAuthConfigurator.java
new file mode 100644
index 00000000..26caf368
--- /dev/null
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/WcAuthConfigurator.java
@@ -0,0 +1,34 @@
+package com.central.oauth2.common.config;
+
+import com.central.oauth2.common.util.AuthUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.websocket.server.ServerEndpointConfig;
+
+/**
+ * webSocket鉴权配置
+ *
+ * @author zlt
+ * @version 1.0
+ * @date 2022/5/8
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@Slf4j
+public class WcAuthConfigurator extends ServerEndpointConfig.Configurator {
+ @Override
+ public boolean checkOrigin(String originHeaderValue) {
+ ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ try {
+ //检查token有效性
+ AuthUtils.checkAccessToken(servletRequestAttributes.getRequest());
+ } catch (Exception e) {
+ log.error("WebSocket-auth-error", e);
+ return false;
+ }
+ return super.checkOrigin(originHeaderValue);
+ }
+}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/constants/IdTokenClaimNames.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/constants/IdTokenClaimNames.java
new file mode 100644
index 00000000..23865987
--- /dev/null
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/constants/IdTokenClaimNames.java
@@ -0,0 +1,89 @@
+package com.central.oauth2.common.constants;
+
+/**
+ * id_token属性名常量
+ *
+ * @author zlt
+ * @version 1.0
+ * @date 2021/4/23
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+public class IdTokenClaimNames {
+ /**
+ * {@code iss} - the Issuer identifier
+ */
+ public final static String ISS = "iss";
+
+ /**
+ * {@code sub} - the Subject identifier
+ */
+ public final static String SUB = "sub";
+
+ /**
+ * {@code aud} - the Audience(s) that the ID Token is intended for
+ */
+ public final static String AUD = "aud";
+
+ /**
+ * {@code exp} - the Expiration time on or after which the ID Token MUST NOT be accepted
+ */
+ public final static String EXP = "exp";
+
+ /**
+ * {@code iat} - the time at which the ID Token was issued
+ */
+ public final static String IAT = "iat";
+
+ /**
+ * {@code auth_time} - the time when the End-User authentication occurred
+ */
+ public final static String AUTH_TIME = "auth_time";
+
+ /**
+ * {@code nonce} - a {@code String} value used to associate a Client session with an ID Token,
+ * and to mitigate replay attacks.
+ */
+ public final static String NONCE = "nonce";
+
+ /**
+ * {@code acr} - the Authentication Context Class Reference
+ */
+ public final static String ACR = "acr";
+
+ /**
+ * {@code amr} - the Authentication Methods References
+ */
+ public final static String AMR = "amr";
+
+ /**
+ * {@code azp} - the Authorized party to which the ID Token was issued
+ */
+ public final static String AZP = "azp";
+
+ /**
+ * {@code at_hash} - the Access Token hash value
+ */
+ public final static String AT_HASH = "at_hash";
+
+ /**
+ * {@code c_hash} - the Authorization Code hash value
+ */
+ public final static String C_HASH = "c_hash";
+
+ /**
+ * {@code name} - 用户姓名
+ */
+ public final static String NAME = "name";
+
+ /**
+ * {@code login_name} - 登录名
+ */
+ public final static String L_NAME = "login_name";
+
+ /**
+ * {@code picture} - 头像照片
+ */
+ public final static String PIC = "picture";
+}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/converter/CustomUserAuthenticationConverter.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/converter/CustomUserAuthenticationConverter.java
index 7bf24315..fbc86581 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/converter/CustomUserAuthenticationConverter.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/converter/CustomUserAuthenticationConverter.java
@@ -1,5 +1,6 @@
package com.central.oauth2.common.converter;
+import com.central.common.model.LoginAppUser;
import com.central.common.model.SysUser;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
@@ -68,7 +69,7 @@ public Authentication extractAuthentication(Map map) {
principal = user;
} else {
Integer id = (Integer)map.get("id");
- SysUser user = new SysUser();
+ LoginAppUser user = new LoginAppUser();
user.setUsername((String)principal);
user.setId(Long.valueOf(id));
principal = user;
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/AuthProperties.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/AuthProperties.java
index bdc0048c..c89860b9 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/AuthProperties.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/AuthProperties.java
@@ -28,4 +28,23 @@ public class AuthProperties {
* url权限配置
*/
private UrlPermissionProperties urlPermission = new UrlPermissionProperties();
+
+ /**
+ * 是否开启统一登出
+ * 1. 登出时把同一个用户名下的所有token都注销
+ * 2. 登出信息通知所有单点登录系统
+ */
+ private Boolean unifiedLogout = false;
+
+ /**
+ * 是否同应用同账号登录互踢
+ */
+ private Boolean isSingleLogin = false;
+
+ /**
+ * 是否同应用同账号登录时共用token
+ * true: 多个用户使用同一账号登录时共用一个token
+ * false: 就算使用同一账号登录时都会新建一个token
+ */
+ private Boolean isShareToken = true;
}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/PermitProperties.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/PermitProperties.java
index 16a5b653..e0c3c15f 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/PermitProperties.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/PermitProperties.java
@@ -23,6 +23,7 @@ public class PermitProperties {
"/*/v2/api-docs",
"/swagger/api-docs",
"/swagger-ui.html",
+ "/doc.html",
"/swagger-resources/**",
"/webjars/**",
"/druid/**"
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/TokenStoreProperties.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/TokenStoreProperties.java
new file mode 100644
index 00000000..0f2687fb
--- /dev/null
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/TokenStoreProperties.java
@@ -0,0 +1,27 @@
+package com.central.oauth2.common.properties;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+
+/**
+ * Token配置
+ *
+ * @author zlt
+ * @version 1.0
+ * @date 2021/5/19
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@Setter
+@Getter
+@ConfigurationProperties(prefix = "zlt.oauth2.token.store")
+@RefreshScope
+public class TokenStoreProperties {
+ /**
+ * token存储类型(redis/db/authJwt/resJwt)
+ */
+ private String type = "redis";
+}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/CustomBearerTokenExtractor.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/CustomBearerTokenExtractor.java
new file mode 100644
index 00000000..cc21489d
--- /dev/null
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/CustomBearerTokenExtractor.java
@@ -0,0 +1,44 @@
+package com.central.oauth2.common.service.impl;
+
+import com.central.oauth2.common.properties.SecurityProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor;
+import org.springframework.stereotype.Component;
+import org.springframework.util.AntPathMatcher;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * 自定义 TokenExtractor
+ *
+ * @author zlt
+ * @version 1.0
+ * @date 2022/6/4
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@ConditionalOnClass(HttpServletRequest.class)
+@Component
+public class CustomBearerTokenExtractor extends BearerTokenExtractor {
+ @Resource
+ private SecurityProperties securityProperties;
+
+ private final AntPathMatcher antPathMatcher = new AntPathMatcher();
+
+ /**
+ * 解决只要请求携带access_token,排除鉴权的url依然会被拦截
+ */
+ @Override
+ public Authentication extract(HttpServletRequest request) {
+ //判断当前请求为排除鉴权的url时,直接返回null
+ for (String url : securityProperties.getIgnore().getUrls()) {
+ if (antPathMatcher.match(url, request.getRequestURI())) {
+ return null;
+ }
+ }
+ return super.extract(request);
+ }
+}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/DefaultPermissionServiceImpl.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/DefaultPermissionServiceImpl.java
index 954cf054..c08a178b 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/DefaultPermissionServiceImpl.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/DefaultPermissionServiceImpl.java
@@ -25,6 +25,9 @@
*
* @author zlt
* @date 2018/10/28
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
*/
@Slf4j
public abstract class DefaultPermissionServiceImpl {
@@ -32,7 +35,7 @@ public abstract class DefaultPermissionServiceImpl {
@Autowired
private SecurityProperties securityProperties;
- private AntPathMatcher antPathMatcher = new AntPathMatcher();
+ private final AntPathMatcher antPathMatcher = new AntPathMatcher();
/**
* 查询当前用户拥有的资源权限
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthDbTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthDbTokenStore.java
index d084e549..1d0b1ec9 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthDbTokenStore.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthDbTokenStore.java
@@ -3,6 +3,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
@@ -14,6 +15,7 @@
* @author zlt
* @date 2018/7/24 16:23
*/
+@Configuration
@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "db")
public class AuthDbTokenStore {
@Autowired
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java
index 9b99fb79..2d261222 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java
@@ -5,6 +5,8 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.bootstrap.encrypt.KeyProperties;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.Order;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
@@ -23,16 +25,14 @@
*
* @author zlt
* @date 2018/7/24 16:21
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
*/
+@Configuration
@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "authJwt")
public class AuthJwtTokenStore {
-
- @Bean("keyProp")
- public KeyProperties keyProperties() {
- return new KeyProperties();
- }
-
- @Resource(name = "keyProp")
+ @Resource
private KeyProperties keyProperties;
@Bean
@@ -41,6 +41,7 @@ public TokenStore tokenStore(JwtAccessTokenConverter jwtAccessTokenConverter) {
}
@Bean
+ @Order(2)
public JwtAccessTokenConverter jwtAccessTokenConverter() {
final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
KeyPair keyPair = new KeyStoreKeyFactory
@@ -51,25 +52,4 @@ public JwtAccessTokenConverter jwtAccessTokenConverter() {
tokenConverter.setUserTokenConverter(new CustomUserAuthenticationConverter());
return converter;
}
-
- /**
- * jwt 生成token 定制化处理
- * 添加一些额外的用户信息到token里面
- *
- * @return TokenEnhancer
- */
- @Bean
- public TokenEnhancer tokenEnhancer() {
- return (accessToken, authentication) -> {
- final Map additionalInfo = new HashMap<>(1);
- Object principal = authentication.getPrincipal();
- //增加id参数
- if (principal instanceof SysUser) {
- SysUser user = (SysUser)principal;
- additionalInfo.put("id", user.getId());
- }
- ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
- return accessToken;
- };
- }
}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java
index a8651589..239dc420 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java
@@ -4,7 +4,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.security.oauth2.provider.token.TokenStore;
/**
@@ -13,17 +15,15 @@
*
* @author zlt
* @date 2018/7/25 9:36
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
*/
+@Configuration
@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "redis", matchIfMissing = true)
public class AuthRedisTokenStore {
- @Autowired
- private RedisConnectionFactory connectionFactory;
-
- @Autowired
- private SecurityProperties securityProperties;
-
@Bean
- public TokenStore tokenStore() {
- return new CustomRedisTokenStore(connectionFactory, securityProperties);
+ public TokenStore tokenStore(RedisConnectionFactory connectionFactory, SecurityProperties securityProperties, RedisSerializer