diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PermitAllUrlResolver.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PermitAllUrlResolver.java index d1d9a084e..d69bd0886 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PermitAllUrlResolver.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PermitAllUrlResolver.java @@ -102,25 +102,28 @@ public class PermitAllUrlResolver implements InitializingBean { /** * 过滤 Inner 设置 * - *

1. 路径转换: 如果为restful(/xx/{xx}) --> /xx/* ant 表达式

- *

2. 构建表达式:允许暴露的接口|允许暴露的方法类型,允许暴露的方法类型 URL|GET,POST,DELETE,PUT

- * + *

+ * 1. 路径转换: 如果为restful(/xx/{xx}) --> /xx/* ant 表达式 + *

+ *

+ * 2. 构建表达式:允许暴露的接口|允许暴露的方法类型,允许暴露的方法类型 URL|GET,POST,DELETE,PUT + *

* @param url mapping路径 - * @param rq 请求犯法 + * @param rq 请求犯法 */ private void filterPath(String url, RequestMapping rq) { List methodList = Arrays.stream(rq.method()).map(RequestMethod::name).collect(Collectors.toList()); String resultUrl = ReUtil.replaceAll(url, PATTERN, "*"); if (CollUtil.isEmpty(methodList)) { ignoreUrls.add(resultUrl); - } else { + } + else { ignoreUrls.add(String.format("%s|%s", resultUrl, CollUtil.join(methodList, StrUtil.COMMA))); } } /** * 获取对外暴露的URL,注册到 spring security - * * @param registry spring security context */ public void registry(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry) { @@ -136,7 +139,7 @@ public class PermitAllUrlResolver implements InitializingBean { // 当配置对外的URL|GET,POST 这种形式,则获取方法列表 并注册到 spring security if (strings.length == 2) { for (String method : StrUtil.split(strings[1], StrUtil.COMMA)) { - registry.antMatchers(HttpMethod.valueOf(method), strings[0]); + registry.antMatchers(HttpMethod.valueOf(method), strings[0]).permitAll(); } continue; } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxRedisTokenStore.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxRedisTokenStore.java index a15f36213..ce42a655b 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxRedisTokenStore.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxRedisTokenStore.java @@ -125,14 +125,10 @@ public class PigxRedisTokenStore implements TokenStore { public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) { String key = authenticationKeyGenerator.extractKey(authentication); byte[] serializedKey = serializeKey(AUTH_TO_ACCESS + key); - byte[] bytes = null; - RedisConnection conn = getConnection(); - try { + byte[] bytes; + try (RedisConnection conn = getConnection()) { bytes = conn.get(serializedKey); } - finally { - conn.close(); - } OAuth2AccessToken accessToken = deserializeAccessToken(bytes); if (accessToken != null) { OAuth2Authentication storedAuthentication = readAuthentication(accessToken.getValue()); @@ -156,15 +152,10 @@ public class PigxRedisTokenStore implements TokenStore { @Override public OAuth2Authentication readAuthentication(String token) { byte[] bytes; - RedisConnection conn = getConnection(); - try { + try (RedisConnection conn = getConnection()) { bytes = conn.get(serializeKey(AUTH + token)); } - finally { - conn.close(); - } - OAuth2Authentication auth = deserializeAuthentication(bytes); - return auth; + return deserializeAuthentication(bytes); } @Override @@ -173,14 +164,9 @@ public class PigxRedisTokenStore implements TokenStore { } public OAuth2Authentication readAuthenticationForRefreshToken(String token) { - RedisConnection conn = getConnection(); - try { + try (RedisConnection conn = getConnection()) { byte[] bytes = conn.get(serializeKey(REFRESH_AUTH + token)); - OAuth2Authentication auth = deserializeAuthentication(bytes); - return auth; - } - finally { - conn.close(); + return deserializeAuthentication(bytes); } } @@ -194,8 +180,7 @@ public class PigxRedisTokenStore implements TokenStore { byte[] approvalKey = serializeKey(UNAME_TO_ACCESS + getApprovalKey(authentication)); byte[] clientId = serializeKey(CLIENT_ID_TO_ACCESS + authentication.getOAuth2Request().getClientId()); - RedisConnection conn = getConnection(); - try { + try (RedisConnection conn = getConnection()) { conn.openPipeline(); if (springDataRedis_2_0) { try { @@ -236,7 +221,6 @@ public class PigxRedisTokenStore implements TokenStore { } OAuth2RefreshToken refreshToken = token.getRefreshToken(); if (refreshToken != null && refreshToken.getValue() != null) { - byte[] refresh = serialize(token.getRefreshToken().getValue()); byte[] auth = serialize(token.getValue()); byte[] refreshToAccessKey = serializeKey(REFRESH_TO_ACCESS + token.getRefreshToken().getValue()); if (springDataRedis_2_0) { @@ -262,9 +246,6 @@ public class PigxRedisTokenStore implements TokenStore { } conn.closePipeline(); } - finally { - conn.close(); - } } private static String getApprovalKey(OAuth2Authentication authentication) { @@ -285,23 +266,17 @@ public class PigxRedisTokenStore implements TokenStore { @Override public OAuth2AccessToken readAccessToken(String tokenValue) { byte[] key = serializeKey(ACCESS + tokenValue); - byte[] bytes = null; - RedisConnection conn = getConnection(); - try { + byte[] bytes; + try (RedisConnection conn = getConnection()) { bytes = conn.get(key); } - finally { - conn.close(); - } - OAuth2AccessToken accessToken = deserializeAccessToken(bytes); - return accessToken; + return deserializeAccessToken(bytes); } public void removeAccessToken(String tokenValue) { byte[] accessKey = serializeKey(ACCESS + tokenValue); byte[] authKey = serializeKey(AUTH + tokenValue); - RedisConnection conn = getConnection(); - try { + try (RedisConnection conn = getConnection()) { conn.openPipeline(); conn.get(accessKey); conn.get(authKey); @@ -326,9 +301,6 @@ public class PigxRedisTokenStore implements TokenStore { conn.closePipeline(); } } - finally { - conn.close(); - } } @Override @@ -336,8 +308,7 @@ public class PigxRedisTokenStore implements TokenStore { byte[] refreshKey = serializeKey(REFRESH + refreshToken.getValue()); byte[] refreshAuthKey = serializeKey(REFRESH_AUTH + refreshToken.getValue()); byte[] serializedRefreshToken = serialize(refreshToken); - RedisConnection conn = getConnection(); - try { + try (RedisConnection conn = getConnection()) { conn.openPipeline(); if (springDataRedis_2_0) { try { @@ -363,24 +334,16 @@ public class PigxRedisTokenStore implements TokenStore { } conn.closePipeline(); } - finally { - conn.close(); - } } @Override public OAuth2RefreshToken readRefreshToken(String tokenValue) { byte[] key = serializeKey(REFRESH + tokenValue); - byte[] bytes = null; - RedisConnection conn = getConnection(); - try { + byte[] bytes; + try (RedisConnection conn = getConnection()) { bytes = conn.get(key); } - finally { - conn.close(); - } - OAuth2RefreshToken refreshToken = deserializeRefreshToken(bytes); - return refreshToken; + return deserializeRefreshToken(bytes); } @Override @@ -392,17 +355,13 @@ public class PigxRedisTokenStore implements TokenStore { byte[] refreshKey = serializeKey(REFRESH + tokenValue); byte[] refreshAuthKey = serializeKey(REFRESH_AUTH + tokenValue); byte[] refresh2AccessKey = serializeKey(REFRESH_TO_ACCESS + tokenValue); - RedisConnection conn = getConnection(); - try { + try (RedisConnection conn = getConnection()) { conn.openPipeline(); conn.del(refreshKey); conn.del(refreshAuthKey); conn.del(refresh2AccessKey); conn.closePipeline(); } - finally { - conn.close(); - } } @Override @@ -412,17 +371,13 @@ public class PigxRedisTokenStore implements TokenStore { private void removeAccessTokenUsingRefreshToken(String refreshToken) { byte[] key = serializeKey(REFRESH_TO_ACCESS + refreshToken); - List results = null; - RedisConnection conn = getConnection(); - try { + List results; + try (RedisConnection conn = getConnection()) { conn.openPipeline(); conn.get(key); conn.del(key); results = conn.closePipeline(); } - finally { - conn.close(); - } byte[] bytes = (byte[]) results.get(0); String accessToken = deserializeString(bytes); if (accessToken != null) { @@ -437,6 +392,7 @@ public class PigxRedisTokenStore implements TokenStore { List byteList; Long size = conn.zCard(key); + assert size != null; byteList = new ArrayList<>(size.intValue()); Cursor cursor = conn.zScan(key, ScanOptions.NONE); @@ -466,8 +422,7 @@ public class PigxRedisTokenStore implements TokenStore { */ public long doMaintenance() { long removed = 0; - RedisConnection conn = getConnection(); - try { + try (RedisConnection conn = getConnection()) { // client_id_to_acccess maintenance Cursor clientToAccessKeys = conn.scan(ScanOptions.scanOptions() .match(keyStrResolver.extract(prefix + CLIENT_ID_TO_ACCESS + "*", StrUtil.COLON)).build()); @@ -486,9 +441,6 @@ public class PigxRedisTokenStore implements TokenStore { removed += conn.zRemRangeByScore(unameToAccessKey, 0, System.currentTimeMillis()); } } - finally { - conn.close(); - } return removed; } @@ -496,13 +448,9 @@ public class PigxRedisTokenStore implements TokenStore { public Collection findTokensByClientIdAndUserName(String clientId, String userName) { byte[] approvalKey = serializeKey(UNAME_TO_ACCESS + getApprovalKey(clientId, userName)); List byteList; - RedisConnection conn = getConnection(); - try { + try (RedisConnection conn = getConnection()) { byteList = getZByteLists(approvalKey, conn); } - finally { - conn.close(); - } if (byteList.size() == 0) { return Collections.emptySet(); } @@ -517,14 +465,10 @@ public class PigxRedisTokenStore implements TokenStore { @Override public Collection findTokensByClientId(String clientId) { byte[] key = serializeKey(CLIENT_ID_TO_ACCESS + clientId); - List byteList = null; - RedisConnection conn = getConnection(); - try { + List byteList; + try (RedisConnection conn = getConnection()) { byteList = getZByteLists(key, conn); } - finally { - conn.close(); - } if (byteList.size() == 0) { return Collections.emptySet(); } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerTokenRelayAutoConfiguration.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerTokenRelayAutoConfiguration.java index f6c5a7c6e..b952e310b 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerTokenRelayAutoConfiguration.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerTokenRelayAutoConfiguration.java @@ -1,3 +1,4 @@ + /* * Copyright (c) 2018-2025, lengleng All rights reserved. * diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationToken.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationToken.java index 5a870888c..bb10ffc91 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationToken.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationToken.java @@ -17,6 +17,8 @@ package com.pig4cloud.pigx.common.security.mobile; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.SneakyThrows; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.core.GrantedAuthority; @@ -40,7 +42,9 @@ public class MobileAuthenticationToken extends AbstractAuthenticationToken { setAuthenticated(false); } - public MobileAuthenticationToken(Object principal, Collection authorities) { + @JsonCreator + public MobileAuthenticationToken(@JsonProperty("principal") Object principal, + @JsonProperty("authorities") Collection authorities) { super(authorities); this.principal = principal; super.setAuthenticated(true); diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/AccessTokenJackson2Deserializer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/AccessTokenJackson2Deserializer.java new file mode 100644 index 000000000..e6d1ce338 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/AccessTokenJackson2Deserializer.java @@ -0,0 +1,117 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import com.pig4cloud.pigx.common.security.service.PigxUser; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; +import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.security.oauth2.common.util.OAuth2Utils; + +import java.io.IOException; +import java.util.*; + +/** + * 反序列化 + * + * @author dream.lu + */ +public final class AccessTokenJackson2Deserializer extends StdDeserializer { + + public AccessTokenJackson2Deserializer() { + super(OAuth2AccessToken.class); + } + + @Override + public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) + throws IOException { + return myDeserializeWithType(p); + } + + private OAuth2AccessToken myDeserializeWithType(JsonParser jp) throws IOException { + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + JsonNode jsonNode = mapper.readTree(jp); + String tokenValue = jsonNode.get(OAuth2AccessToken.ACCESS_TOKEN).asText(); + String tokenType = jsonNode.get(OAuth2AccessToken.TOKEN_TYPE).asText(); + String refreshToken = jsonNode.get(OAuth2AccessToken.REFRESH_TOKEN).asText(); + long expiresIn = jsonNode.get(OAuth2AccessToken.EXPIRES_IN).asLong(); + DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(tokenValue); + accessToken.setTokenType(tokenType); + accessToken.setExpiration(new Date(System.currentTimeMillis() + expiresIn * 1000)); + if (refreshToken != null) { + accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken)); + } + // scope + JsonNode scopeNode = jsonNode.get(OAuth2AccessToken.SCOPE); + accessToken.setScope(parseScope(scopeNode)); + // 扩展字段 + accessToken.setAdditionalInformation(parseAdditionalInformation(mapper, jsonNode)); + return accessToken; + } + + @Override + public OAuth2AccessToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { + return myDeserializeWithType(jp); + } + + /** + * 解析 scope + * @param scopeNode scope json + * @return String Set + */ + private static Set parseScope(JsonNode scopeNode) { + // 空处理 + if (scopeNode == null || scopeNode.isNull()) { + return Collections.emptySet(); + } + // 字符串 x xx xxx 格式 + if (scopeNode.isTextual()) { + return OAuth2Utils.parseParameterList(scopeNode.asText()); + } + // 集合模型 + Set scope = new TreeSet<>(); + Iterator elements = scopeNode.elements(); + while (elements.hasNext()) { + JsonNode next = elements.next(); + scope.add(next.asText()); + } + return scope; + } + + /** + * 解析扩展字段 + * @param mapper jackson 工具 + * @param jsonNode json String + * @return map + * @see com.pig4cloud.pigx.common.security.component.PigxTokenEnhancer + */ + private Map parseAdditionalInformation(ObjectMapper mapper, JsonNode jsonNode) { + LinkedHashMap additionalInformation = new LinkedHashMap<>(); + + // 处理 user_info + JsonNode userNode = jsonNode.get(SecurityConstants.DETAILS_USER); + User user = mapper.convertValue(userNode, User.class); + int deptId = userNode.get(SecurityConstants.DETAILS_DEPT_ID).asInt(); + int tenantId = userNode.get(SecurityConstants.DETAILS_TENANT_ID).asInt(); + int userId = userNode.get(SecurityConstants.DETAILS_USER_ID).asInt(); + String phone = userNode.get(SecurityConstants.DETAILS_PHONE).asText(); + String avatar = userNode.get(SecurityConstants.DETAILS_AVATAR).asText(); + PigxUser pigxUser = new PigxUser(userId, deptId, phone, avatar, tenantId, user.getUsername(), "N/A", + user.isEnabled(), user.isAccountNonExpired(), user.isCredentialsNonExpired(), user.isAccountNonLocked(), + user.getAuthorities()); + additionalInformation.put(SecurityConstants.DETAILS_USER, pigxUser); + + // 处理 license 等扩展字段 【去掉OAuth2AccessToken 字段避免重复】 + additionalInformation.put(SecurityConstants.DETAILS_LICENSE, + jsonNode.get(SecurityConstants.DETAILS_LICENSE).asText()); + additionalInformation.put(SecurityConstants.ACTIVE, jsonNode.get(SecurityConstants.ACTIVE).asBoolean()); + return additionalInformation; + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/AccessTokenJackson2Serializer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/AccessTokenJackson2Serializer.java new file mode 100644 index 000000000..9e4336210 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/AccessTokenJackson2Serializer.java @@ -0,0 +1,75 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.security.oauth2.common.OAuth2RefreshToken; +import org.springframework.util.Assert; + +import java.io.IOException; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + +/** + * 序列化 + * + * @author dream.lu + */ +public final class AccessTokenJackson2Serializer extends StdSerializer { + + public AccessTokenJackson2Serializer() { + super(OAuth2AccessToken.class); + } + + @Override + public void serializeWithType(OAuth2AccessToken value, JsonGenerator gen, SerializerProvider serializers, + TypeSerializer typeSer) throws IOException { + mySerializeWithType(value, gen, serializers, typeSer); + } + + private void mySerializeWithType(OAuth2AccessToken token, JsonGenerator gen, SerializerProvider serializers, + TypeSerializer typeSer) throws IOException { + gen.writeStartObject(); + if (typeSer != null) { + gen.writeStringField(typeSer.getPropertyName(), token.getClass().getName()); + } + Map tokenMap = new LinkedHashMap<>(); + tokenMap.put(OAuth2AccessToken.ACCESS_TOKEN, token.getValue()); + tokenMap.put(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType()); + OAuth2RefreshToken refreshToken = token.getRefreshToken(); + if (refreshToken != null) { + tokenMap.put(OAuth2AccessToken.REFRESH_TOKEN, refreshToken.getValue()); + } + Date expiration = token.getExpiration(); + if (expiration != null) { + long now = System.currentTimeMillis(); + tokenMap.put(OAuth2AccessToken.EXPIRES_IN, (expiration.getTime() - now) / 1000); + } + Set scope = token.getScope(); + if (scope != null && !scope.isEmpty()) { + StringBuilder scopes = new StringBuilder(); + for (String s : scope) { + Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope); + scopes.append(s); + scopes.append(" "); + } + tokenMap.put(OAuth2AccessToken.SCOPE, scopes.substring(0, scopes.length() - 1)); + } + Map additionalInformation = token.getAdditionalInformation(); + tokenMap.putAll(additionalInformation); + for (String key : tokenMap.keySet()) { + gen.writeObjectField(key, tokenMap.get(key)); + } + gen.writeEndObject(); + } + + @Override + public void serialize(OAuth2AccessToken token, JsonGenerator gen, SerializerProvider provider) throws IOException { + mySerializeWithType(token, gen, provider, null); + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/AccessTokenMixIn.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/AccessTokenMixIn.java new file mode 100755 index 000000000..202b62a2f --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/AccessTokenMixIn.java @@ -0,0 +1,17 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +/** + * AccessTokenMixIn + * + * @author dream.lu + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@class") +@JsonSerialize(using = AccessTokenJackson2Serializer.class) +@JsonDeserialize(using = AccessTokenJackson2Deserializer.class) +public class AccessTokenMixIn { + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/JacksonRedisTokenStoreSerializationStrategy.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/JacksonRedisTokenStoreSerializationStrategy.java new file mode 100755 index 000000000..80dc95f37 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/JacksonRedisTokenStoreSerializationStrategy.java @@ -0,0 +1,72 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; +import com.pig4cloud.pigx.common.security.mobile.MobileAuthenticationToken; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.jackson2.CoreJackson2Module; +import org.springframework.security.jackson2.SimpleGrantedAuthorityMixin; +import org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.security.oauth2.provider.OAuth2Authentication; +import org.springframework.security.oauth2.provider.token.store.redis.BaseRedisTokenStoreSerializationStrategy; +import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +/** + * jackson 序列化 + * + * @author dream.lu + */ +public class JacksonRedisTokenStoreSerializationStrategy extends BaseRedisTokenStoreSerializationStrategy { + + private final ObjectMapper mapper; + + public JacksonRedisTokenStoreSerializationStrategy() { + this.mapper = new ObjectMapper(); + this.mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, + JsonTypeInfo.As.PROPERTY); + this.mapper.addMixIn(OAuth2AccessToken.class, AccessTokenMixIn.class); + this.mapper.addMixIn(OAuth2Authentication.class, OAuth2AuthenticationMixin.class); + this.mapper.addMixIn(PreAuthenticatedAuthenticationToken.class, PreAuthenticatedAuthenticationTokenMixin.class); + this.mapper.addMixIn(MobileAuthenticationToken.class, MobileAuthenticationTokenMixin.class); + this.mapper.addMixIn(SimpleGrantedAuthority.class, SimpleGrantedAuthorityMixin.class); + this.mapper.registerModule(new CoreJackson2Module()); + this.mapper.addMixIn(DefaultExpiringOAuth2RefreshToken.class, OAuth2RefreshTokenMixin.class); + } + + @Override + protected T deserializeInternal(byte[] bytes, Class clazz) { + try { + return mapper.readValue(bytes, clazz); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + protected String deserializeStringInternal(byte[] bytes) { + return new String(bytes, StandardCharsets.UTF_8); + } + + @Override + protected byte[] serializeInternal(Object object) { + try { + return mapper.writeValueAsBytes(object); + } + catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + @Override + protected byte[] serializeInternal(String data) { + return data.getBytes(StandardCharsets.UTF_8); + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/MobileAuthenticationTokenDeserializer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/MobileAuthenticationTokenDeserializer.java new file mode 100644 index 000000000..b6e825035 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/MobileAuthenticationTokenDeserializer.java @@ -0,0 +1,54 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.pig4cloud.pigx.common.security.mobile.MobileAuthenticationToken; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.User; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +/** + * @author lengleng + * @date 2020/10/21 + *

+ * MobileAuthenticationToken 反序列化处理 + */ +public class MobileAuthenticationTokenDeserializer extends StdDeserializer { + + protected MobileAuthenticationTokenDeserializer() { + super(MobileAuthenticationToken.class); + } + + @Override + public MobileAuthenticationToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { + + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + JsonNode jsonNode = mapper.readTree(jp); + + Set authorities = getAuthorities(mapper, jsonNode); + + User principal = mapper.convertValue(jsonNode.get("principal"), User.class); + + return new MobileAuthenticationToken(principal, authorities); + } + + private Set getAuthorities(ObjectMapper mapper, JsonNode parentNode) { + JsonNode authoritiesNode = parentNode.get("authorities"); + Set authorities = new HashSet<>(authoritiesNode.size()); + for (Iterator authoritiesIt = authoritiesNode.get(1).elements(); authoritiesIt.hasNext();) { + JsonNode authorityNode = authoritiesIt.next(); + SimpleGrantedAuthority authority = mapper.convertValue(authorityNode, SimpleGrantedAuthority.class); + authorities.add(authority); + } + return authorities; + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/MobileAuthenticationTokenMixin.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/MobileAuthenticationTokenMixin.java new file mode 100644 index 000000000..169db7b00 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/MobileAuthenticationTokenMixin.java @@ -0,0 +1,17 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * @author lengleng + * @date 2020/10/21 + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@class") +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, + isGetterVisibility = JsonAutoDetect.Visibility.NONE) +@JsonDeserialize(using = MobileAuthenticationTokenDeserializer.class) +public class MobileAuthenticationTokenMixin { + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2AuthenticationDeserializer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2AuthenticationDeserializer.java new file mode 100644 index 000000000..41f5de7fc --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2AuthenticationDeserializer.java @@ -0,0 +1,93 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.type.CollectionType; +import com.fasterxml.jackson.databind.type.MapType; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.oauth2.provider.OAuth2Authentication; +import org.springframework.security.oauth2.provider.OAuth2Request; + +import java.io.IOException; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * OAuth2Authentication 反序列化 + * + * @author dream.lu + */ +public class OAuth2AuthenticationDeserializer extends StdDeserializer { + + protected OAuth2AuthenticationDeserializer() { + super(OAuth2Authentication.class); + } + + @Override + public OAuth2Authentication deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + JsonNode jsonNode = mapper.readTree(jp); + Set authorities = getAuthorities(mapper, jsonNode); + JsonNode requestNode = jsonNode.get("storedRequest"); + Map requestParameters = getMap(mapper, requestNode.get("requestParameters")); + String clientId = requestNode.get("clientId").asText(); + boolean approved = requestNode.get("approved").asBoolean(); + Set scope = getSet(mapper, requestNode.get("scope")); + Set resourceIds = getSet(mapper, requestNode.get("resourceIds")); + String redirectUri = requestNode.get("redirectUri").asText(null); + Set responseTypes = getSet(mapper, requestNode.get("responseTypes")); + Map extensionProperties = getMap(mapper, jsonNode.get("extensions"), Serializable.class); + // 构造 OAuth2Request + OAuth2Request request = new OAuth2Request(requestParameters, clientId, authorities, approved, scope, + resourceIds, redirectUri, responseTypes, extensionProperties); + JsonNode userAuthenticationNode = jsonNode.get("userAuthentication"); + // UsernamePasswordAuthenticationToken 反序列化 + Authentication authentication = null; + if (userAuthenticationNode != null && !userAuthenticationNode.isMissingNode()) { + authentication = (Authentication) mapper.convertValue(userAuthenticationNode, Object.class); + } + + OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(request, authentication); + oAuth2Authentication.setAuthenticated(true); + return oAuth2Authentication; + + } + + private static Set getSet(ObjectMapper mapper, JsonNode jsonNode) { + return getSet(mapper, jsonNode, String.class); + } + + private static Set getSet(ObjectMapper mapper, JsonNode jsonNode, Class valueClass) { + CollectionType collectionType = mapper.getTypeFactory().constructCollectionType(Set.class, valueClass); + return mapper.convertValue(jsonNode, collectionType); + } + + private static Map getMap(ObjectMapper mapper, JsonNode jsonNode) { + return getMap(mapper, jsonNode, String.class); + } + + private static Map getMap(ObjectMapper mapper, JsonNode jsonNode, Class valueClass) { + MapType mapType = mapper.getTypeFactory().constructMapType(Map.class, String.class, valueClass); + return mapper.convertValue(jsonNode, mapType); + } + + private Set getAuthorities(ObjectMapper mapper, JsonNode parentNode) { + JsonNode authoritiesNode = parentNode.get("authorities"); + Set authorities = new HashSet<>(authoritiesNode.size()); + for (Iterator authoritiesIt = authoritiesNode.get(1).elements(); authoritiesIt.hasNext();) { + JsonNode authorityNode = authoritiesIt.next(); + SimpleGrantedAuthority authority = mapper.convertValue(authorityNode, SimpleGrantedAuthority.class); + authorities.add(authority); + } + return authorities; + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2AuthenticationMixin.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2AuthenticationMixin.java new file mode 100755 index 000000000..cf99420f7 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2AuthenticationMixin.java @@ -0,0 +1,13 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@class") +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, + isGetterVisibility = JsonAutoDetect.Visibility.NONE) +@JsonDeserialize(using = OAuth2AuthenticationDeserializer.class) +public class OAuth2AuthenticationMixin { + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2RefreshTokenDeserializer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2RefreshTokenDeserializer.java new file mode 100644 index 000000000..cd2989250 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2RefreshTokenDeserializer.java @@ -0,0 +1,37 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken; + +import java.io.IOException; +import java.util.Date; + +/** + * DefaultExpiringOAuth2RefreshToken 反序列化 + * + * @author dream.lu + */ +public class OAuth2RefreshTokenDeserializer extends StdDeserializer { + + protected OAuth2RefreshTokenDeserializer() { + super(DefaultExpiringOAuth2RefreshToken.class); + } + + @Override + public DefaultExpiringOAuth2RefreshToken deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + // {"@class":"org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken","value":"a94d2f04-d9be-49f9-9d9c-2bc7b34c8618","expiration":["java.util.Date",1605237988760]} + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + JsonNode jsonNode = mapper.readTree(jp); + String value = jsonNode.get("value").asText(); + JsonNode expirationNode = jsonNode.get("expiration"); + Date date = mapper.convertValue(expirationNode, Date.class); + return new DefaultExpiringOAuth2RefreshToken(value, date); + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2RefreshTokenMixin.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2RefreshTokenMixin.java new file mode 100644 index 000000000..6732826f5 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/OAuth2RefreshTokenMixin.java @@ -0,0 +1,10 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@class") +@JsonDeserialize(using = OAuth2RefreshTokenDeserializer.class) +public class OAuth2RefreshTokenMixin { + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxTokenStoreAutoConfiguration.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/PigxTokenStoreAutoConfiguration.java similarity index 87% rename from pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxTokenStoreAutoConfiguration.java rename to pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/PigxTokenStoreAutoConfiguration.java index 926b29324..b2881ae5b 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxTokenStoreAutoConfiguration.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/PigxTokenStoreAutoConfiguration.java @@ -1,8 +1,9 @@ -package com.pig4cloud.pigx.common.security.component; +package com.pig4cloud.pigx.common.security.serializer; import cn.hutool.core.util.StrUtil; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; import com.pig4cloud.pigx.common.core.util.KeyStrResolver; +import com.pig4cloud.pigx.common.security.component.PigxRedisTokenStore; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -28,8 +29,8 @@ public class PigxTokenStoreAutoConfiguration { @Bean public TokenStore tokenStore() { PigxRedisTokenStore tokenStore = new PigxRedisTokenStore(connectionFactory, resolver); + tokenStore.setSerializationStrategy(new JacksonRedisTokenStoreSerializationStrategy()); tokenStore.setPrefix(SecurityConstants.PIGX_PREFIX + SecurityConstants.OAUTH_PREFIX); - tokenStore.setAuthenticationKeyGenerator(new DefaultAuthenticationKeyGenerator() { @Override public String extractKey(OAuth2Authentication authentication) { diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/PreAuthenticatedAuthenticationTokenDeserializer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/PreAuthenticatedAuthenticationTokenDeserializer.java new file mode 100644 index 000000000..9bd1a15fc --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/PreAuthenticatedAuthenticationTokenDeserializer.java @@ -0,0 +1,57 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +/** + * @author lengleng + * @date 2020/10/21 + *

+ * PreAuthenticatedAuthenticationToken 反序列化处理 + */ +public class PreAuthenticatedAuthenticationTokenDeserializer + extends StdDeserializer { + + protected PreAuthenticatedAuthenticationTokenDeserializer() { + super(PreAuthenticatedAuthenticationToken.class); + } + + @Override + public PreAuthenticatedAuthenticationToken deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + JsonNode jsonNode = mapper.readTree(jp); + + Set authorities = getAuthorities(mapper, jsonNode); + + User principal = mapper.convertValue(jsonNode.get("principal"), User.class); + + return new PreAuthenticatedAuthenticationToken(principal, "N/A", authorities); + } + + private Set getAuthorities(ObjectMapper mapper, JsonNode parentNode) { + JsonNode authoritiesNode = parentNode.get("authorities"); + Set authorities = new HashSet<>(authoritiesNode.size()); + for (Iterator authoritiesIt = authoritiesNode.get(1).elements(); authoritiesIt.hasNext();) { + JsonNode authorityNode = authoritiesIt.next(); + SimpleGrantedAuthority authority = mapper.convertValue(authorityNode, SimpleGrantedAuthority.class); + authorities.add(authority); + } + return authorities; + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/PreAuthenticatedAuthenticationTokenMixin.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/PreAuthenticatedAuthenticationTokenMixin.java new file mode 100644 index 000000000..8ad0f0d16 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/serializer/PreAuthenticatedAuthenticationTokenMixin.java @@ -0,0 +1,17 @@ +package com.pig4cloud.pigx.common.security.serializer; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * @author lengleng + * @date 2020/10/21 + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@class") +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, + isGetterVisibility = JsonAutoDetect.Visibility.NONE) +@JsonDeserialize(using = PreAuthenticatedAuthenticationTokenDeserializer.class) +public class PreAuthenticatedAuthenticationTokenMixin { + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java index efbfd3ae7..50928bd0b 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java @@ -17,6 +17,8 @@ package com.pig4cloud.pigx.common.security.service; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.core.GrantedAuthority; @@ -83,9 +85,15 @@ public class PigxUser extends User { * @throws IllegalArgumentException if a null value was passed either as * a parameter or as an element in the GrantedAuthority collection */ - public PigxUser(Integer id, Integer deptId, String phone, String avatar, Integer tenantId, String username, - String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, - boolean accountNonLocked, Collection authorities) { + @JsonCreator + public PigxUser(@JsonProperty("id") Integer id, @JsonProperty("deptId") Integer deptId, + @JsonProperty("phone") String phone, @JsonProperty("avatar") String avatar, + @JsonProperty("tenantId") Integer tenantId, @JsonProperty("username") String username, + @JsonProperty("password") String password, @JsonProperty("enabled") boolean enabled, + @JsonProperty("accountNonExpired") boolean accountNonExpired, + @JsonProperty("credentialsNonExpired") boolean credentialsNonExpired, + @JsonProperty("accountNonLocked") boolean accountNonLocked, + @JsonProperty("authorities") Collection authorities) { super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); this.id = id; this.deptId = deptId; diff --git a/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories index 21f3f2fc7..5d80ab746 100644 --- a/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories +++ b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories @@ -1,7 +1,7 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.pig4cloud.pigx.common.security.component.PigxTokenEnhancer,\ com.pig4cloud.pigx.common.security.component.PigxSecurityInnerAspect,\ - com.pig4cloud.pigx.common.security.component.PigxTokenStoreAutoConfiguration,\ + com.pig4cloud.pigx.common.security.serializer.PigxTokenStoreAutoConfiguration,\ com.pig4cloud.pigx.common.security.listener.AuthenticationFailureEventListener,\ com.pig4cloud.pigx.common.security.listener.AuthenticationSuccessEventListener diff --git a/pigx-upms/pigx-upms-biz/logs/pigx-upms-biz/2020-08/debug.2020-08-21.0.log.gz b/pigx-upms/pigx-upms-biz/logs/pigx-upms-biz/2020-08/debug.2020-08-21.0.log.gz deleted file mode 100644 index 707a73ae9..000000000 Binary files a/pigx-upms/pigx-upms-biz/logs/pigx-upms-biz/2020-08/debug.2020-08-21.0.log.gz and /dev/null differ diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DemoController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DemoController.java new file mode 100644 index 000000000..f3fd67af8 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DemoController.java @@ -0,0 +1,27 @@ +package com.pig4cloud.pigx.admin.controller; + +import com.pig4cloud.pigx.common.security.annotation.Inner; +import org.springframework.web.bind.annotation.*; + +/** + * @author lengleng + * @date 2020/10/13 + */ +@Inner +@RequestMapping(value = "/demo", method = RequestMethod.POST) +@RestController +public class DemoController { + + @Inner(false) + @GetMapping("/test") + public String demo() { + return "ssucess"; + } + + @Inner(false) + @GetMapping("/test/{id}") + public String demo2(@PathVariable String id) { + return "ssucess"; + } + +}