This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a commit to branch dev-2.1.5
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev-2.1.5 by this push:
new 709f4582d [Improve] openapi minor improvement
709f4582d is described below
commit 709f4582d0365c06e510bfdf5b20bde622aa3910
Author: benjobs <[email protected]>
AuthorDate: Sat Jul 27 15:52:23 2024 +0800
[Improve] openapi minor improvement
---
.../apache/streampark/console/core/enums/AuthenticationType.java | 6 +++++-
.../apache/streampark/console/system/authentication/JWTFilter.java | 5 ++---
.../apache/streampark/console/system/authentication/JWTUtil.java | 6 +++---
.../apache/streampark/console/system/authentication/ShiroRealm.java | 5 +++--
4 files changed, 13 insertions(+), 9 deletions(-)
diff --git
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/AuthenticationType.java
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/AuthenticationType.java
index d1a90c17a..135dc9b84 100644
---
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/AuthenticationType.java
+++
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/AuthenticationType.java
@@ -18,6 +18,7 @@
package org.apache.streampark.console.core.enums;
import java.util.Arrays;
+import java.util.Objects;
public enum AuthenticationType {
SIGN(1),
@@ -35,6 +36,9 @@ public enum AuthenticationType {
}
public static AuthenticationType of(Integer value) {
- return Arrays.stream(values()).filter((x) -> x.value ==
value).findFirst().orElse(null);
+ return Arrays.stream(values())
+ .filter((x) -> Objects.equals(x.value, value))
+ .findFirst()
+ .orElse(null);
}
}
diff --git
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/JWTFilter.java
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/JWTFilter.java
index 9d3b40991..54f9ecac8 100644
---
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/JWTFilter.java
+++
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/JWTFilter.java
@@ -25,7 +25,6 @@ import
org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
-import org.springframework.util.AntPathMatcher;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.ServletRequest;
@@ -38,8 +37,6 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
private static final String TOKEN = "Authorization";
- private final AntPathMatcher pathMatcher = new AntPathMatcher();
-
@Override
protected boolean isAccessAllowed(
ServletRequest request, ServletResponse response, Object mappedValue)
@@ -62,9 +59,11 @@ public class JWTFilter extends BasicHttpAuthenticationFilter
{
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String token = httpServletRequest.getHeader(TOKEN);
AuthenticationType type =
JWTUtil.getAuthType(WebUtils.decryptToken(token));
+
if (type == null) {
return false;
}
+
if (type == AuthenticationType.OPENAPI) {
JWTToken jwtToken = new JWTToken(WebUtils.decryptToken(token));
try {
diff --git
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/JWTUtil.java
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/JWTUtil.java
index 8b033d512..7c6b1302f 100644
---
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/JWTUtil.java
+++
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/JWTUtil.java
@@ -88,7 +88,7 @@ public class JWTUtil {
*/
public static String sign(
Long userId, String userName, String secret, AuthenticationType
authType) {
- Long second = getTTLOfSecond() * 1000;
+ long second = getTTLOfSecond() * 1000;
Long ttl = System.currentTimeMillis() + second;
return sign(userId, userName, secret, authType, ttl);
}
@@ -116,7 +116,7 @@ public class JWTUtil {
public static Long getTTLOfSecond() {
if (ttlOfSecond == null) {
String ttl = System.getProperty("server.session.ttl", "24h").trim();
- String regexp = "^\\d+(s|m|h|d)$";
+ String regexp = "^\\d+([smhd])$";
Pattern pattern = Pattern.compile(regexp);
if (!pattern.matcher(ttl).matches()) {
throw new IllegalArgumentException(
@@ -124,7 +124,7 @@ public class JWTUtil {
}
String unit = ttl.substring(ttl.length() - 1);
String time = ttl.substring(0, ttl.length() - 1);
- Long second = Long.parseLong(time);
+ long second = Long.parseLong(time);
switch (unit) {
case "m":
return ttlOfSecond = second * 60;
diff --git
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroRealm.java
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroRealm.java
index d4bdaae3e..37583ada1 100644
---
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroRealm.java
+++
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroRealm.java
@@ -109,9 +109,10 @@ public class ShiroRealm extends AuthorizingRealm {
if (User.STATUS_LOCK.equals(accessToken.getUserStatus())) {
throw new AuthenticationException(
- "the user [" + username + "] has been locked, please contact the
administrator");
+ "the user ["
+ + user.getUsername()
+ + "] has been locked, please contact the administrator");
}
-
SecurityUtils.getSubject().getSession().setAttribute(AccessToken.IS_API_TOKEN,
true);
}