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 47074e944 [Improve] login minor improvement
47074e944 is described below
commit 47074e94456f495aa539706252f55add3452951f
Author: benjobs <[email protected]>
AuthorDate: Sun Aug 4 16:59:21 2024 +0800
[Improve] login minor improvement
---
.../console/system/authentication/JWTUtil.java | 2 +-
.../console/system/controller/PassportController.java | 16 ++++++----------
.../console/system/security/Authenticator.java | 3 ++-
.../console/system/security/impl/AuthenticatorImpl.java | 10 ++++------
4 files changed, 13 insertions(+), 18 deletions(-)
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 9f6d00fb6..046caf6bf 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
@@ -126,7 +126,7 @@ public class JWTUtil {
public static String sign(User user, AuthenticationType authType, Long
expireTime)
throws Exception {
Date date = new Date(expireTime);
- Algorithm algorithm = Algorithm.HMAC256(user.getSalt());
+ Algorithm algorithm = Algorithm.HMAC256(user.getPassword());
JWTCreator.Builder builder =
JWT.create()
diff --git
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/PassportController.java
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/PassportController.java
index 3694b2564..6cec82158 100644
---
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/PassportController.java
+++
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/PassportController.java
@@ -36,8 +36,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import javax.validation.constraints.NotBlank;
-
import java.time.LocalDateTime;
import java.util.Map;
@@ -51,17 +49,15 @@ public class PassportController {
@Autowired private Authenticator authenticator;
@PostMapping("signin")
- public RestResponse signin(
- @NotBlank(message = "{required}") String username,
- @NotBlank(message = "{required}") String password,
- @NotBlank(message = "{required}") String loginType)
- throws Exception {
+ public RestResponse signin(User loginUser) throws Exception {
- if (StringUtils.isEmpty(username)) {
+ if (StringUtils.isEmpty(loginUser.getUsername())) {
return RestResponse.success().put("code", 0);
}
- User user = authenticator.authenticate(username, password, loginType);
+ User user =
+ authenticator.authenticate(
+ loginUser.getUsername(), loginUser.getPassword(),
loginUser.getLoginType());
if (user == null) {
return RestResponse.success().put("code", 0);
@@ -71,7 +67,7 @@ public class PassportController {
return RestResponse.success().put("code", 1);
}
- this.userService.updateLoginTime(username);
+ this.userService.updateLoginTime(user.getUsername());
String token = JWTUtil.sign(user, AuthenticationType.SIGN);
LocalDateTime expireTime =
LocalDateTime.now().plusSeconds(JWTUtil.getTTLOfSecond());
diff --git
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/Authenticator.java
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/Authenticator.java
index 9c1bcce36..ea70bbd12 100644
---
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/Authenticator.java
+++
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/Authenticator.java
@@ -17,6 +17,7 @@
package org.apache.streampark.console.system.security;
+import org.apache.streampark.console.core.enums.LoginType;
import org.apache.streampark.console.system.entity.User;
public interface Authenticator {
@@ -27,5 +28,5 @@ public interface Authenticator {
* @param password user password
* @return result object
*/
- User authenticate(String username, String password, String loginType) throws
Exception;
+ User authenticate(String username, String password, LoginType loginType)
throws Exception;
}
diff --git
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/AuthenticatorImpl.java
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/AuthenticatorImpl.java
index 916f4ae27..f35375cfa 100644
---
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/AuthenticatorImpl.java
+++
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/security/impl/AuthenticatorImpl.java
@@ -38,14 +38,12 @@ public class AuthenticatorImpl implements Authenticator {
@Autowired private LdapService ldapService;
@Override
- public User authenticate(String username, String password, String loginType)
throws Exception {
- LoginType loginTypeEnum = LoginType.of(loginType);
- if (loginTypeEnum == null) {
- throw new ApiAlertException(
- String.format("the login type [%s] is not supported.", loginType));
+ public User authenticate(String username, String password, LoginType
loginType) throws Exception {
+ if (loginType == null) {
+ throw new ApiAlertException(String.format("the login type is null."));
}
- if (loginTypeEnum.equals(LoginType.PASSWORD)) {
+ if (loginType.equals(LoginType.PASSWORD)) {
return passwordAuthenticate(username, password);
} else {
return ldapAuthenticate(username, password);