From e4cc7eff616d082545f98c97584a3b7c19cae5a8 Mon Sep 17 00:00:00 2001 From: ShawHee Date: Fri, 9 Aug 2024 14:03:46 +0800 Subject: [PATCH 1/2] [Improve] default team member improvement (#3953) * set default team member * getTeamId from teamService --------- Co-authored-by: hechao --- .../streampark/console/base/domain/Constant.java | 2 ++ .../console/system/service/RoleService.java | 6 ++++++ .../system/service/impl/RoleServiceImpl.java | 5 +++++ .../system/service/impl/UserServiceImpl.java | 14 ++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java index 03a211c640..2231f7062a 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java @@ -32,4 +32,6 @@ public class Constant { public static final String APP_DETAIL_MENU_ID = "100018"; public static final Long DEFAULT_TEAM_ID = 100000L; + + public static final Long DEFAULT_ROLE_ID = 100001L; } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/RoleService.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/RoleService.java index 0a9e5f3316..1ad8eca0b0 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/RoleService.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/RoleService.java @@ -62,4 +62,10 @@ public interface RoleService extends IService { * @param role Role */ void updateRole(Role role); + + /** + * Get the Default Role + * + */ + Role getSysDefaultRole(); } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java index d4c2af83bd..659777d4cb 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java @@ -123,4 +123,9 @@ private void updateRoleMenus(Role role, String[] menuIds) { } roleMenuService.saveBatch(roleMenus); } + + @Override + public Role getSysDefaultRole() { + return baseMapper.selectOne(new LambdaQueryWrapper().eq(Role::getRoleId, Constant.DEFAULT_ROLE_ID)); + } } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java index 3e03e23d43..471cbbb1c8 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java @@ -31,10 +31,13 @@ import org.apache.streampark.console.core.service.application.ApplicationManageService; import org.apache.streampark.console.system.authentication.JWTToken; import org.apache.streampark.console.system.authentication.JWTUtil; +import org.apache.streampark.console.system.entity.Member; +import org.apache.streampark.console.system.entity.Role; import org.apache.streampark.console.system.entity.User; import org.apache.streampark.console.system.mapper.UserMapper; import org.apache.streampark.console.system.service.MemberService; import org.apache.streampark.console.system.service.MenuService; +import org.apache.streampark.console.system.service.RoleService; import org.apache.streampark.console.system.service.TeamService; import org.apache.streampark.console.system.service.UserService; @@ -85,6 +88,9 @@ public class UserServiceImpl extends ServiceImpl implements Us @Autowired private TeamService teamService; + @Autowired + private RoleService roleService; + @Override public User getByUsername(String username) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(User::getUsername, username); @@ -121,6 +127,14 @@ public void createUser(User user) { user.setPassword(password); } save(user); + // set team member + Member member = new Member(); + member.setUserName(user.getUsername()); + member.setTeamId(teamService.getSysDefaultTeam().getId()); + Role role = roleService.getSysDefaultRole(); + member.setRoleId(role.getRoleId()); + member.setRoleName(role.getRoleName()); + memberService.createMember(member); } @Override From 47ba863328e2917bbbd22e51364ffc2cbba050a0 Mon Sep 17 00:00:00 2001 From: ShawHee Date: Fri, 9 Aug 2024 15:18:31 +0800 Subject: [PATCH 2/2] [Bug] Fix: Set a default password for Ldap user (#3955) * set default password * modify constant name --------- Co-authored-by: hechao --- .../java/org/apache/streampark/console/system/entity/User.java | 2 ++ .../console/system/security/impl/AuthenticatorImpl.java | 1 + 2 files changed, 3 insertions(+) diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/entity/User.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/entity/User.java index c348439356..f1a4a237a6 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/entity/User.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/entity/User.java @@ -52,6 +52,8 @@ public class User extends BaseEntity { public static final Integer DEFAULT_PASSWORD_LENGTH = 8; + public static final String DEFAULT_SECRET = "streampark"; + @TableId(type = IdType.AUTO) private Long userId; 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 b315014adc..8b61003d5a 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 @@ -119,6 +119,7 @@ private User newUserCreate(LoginTypeEnum loginTypeEnum, String username) throws newUser.setUserType(UserTypeEnum.USER); newUser.setStatus(User.STATUS_VALID); newUser.setSex(User.SEX_UNKNOWN); + newUser.setPassword(User.DEFAULT_SECRET); usersService.createUser(newUser); return newUser; }