Skip to content

Commit ef8adcd

Browse files
dragonpooludomikula
authored andcommittedApr 16, 2025
Add group mapping for oauth provider
1 parent 873e468 commit ef8adcd

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed
 

‎server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/user/model/AuthUser.java

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class AuthUser {
2525

2626
private String orgId;
2727

28+
// Add groupId for group mapping
29+
private String groupId;
30+
2831
private AuthRequestContext authContext;
2932

3033
/**

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/AuthenticationApiServiceImpl.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import org.lowcoder.domain.authentication.FindAuthConfig;
2424
import org.lowcoder.domain.authentication.context.AuthRequestContext;
2525
import org.lowcoder.domain.authentication.context.FormAuthRequestContext;
26+
import org.lowcoder.domain.group.model.GroupMember;
27+
import org.lowcoder.domain.group.service.GroupMemberService;
28+
import org.lowcoder.domain.organization.model.MemberRole;
2629
import org.lowcoder.domain.organization.model.OrgMember;
2730
import org.lowcoder.domain.organization.model.Organization;
2831
import org.lowcoder.domain.organization.model.OrganizationDomain;
@@ -73,6 +76,7 @@ public class AuthenticationApiServiceImpl implements AuthenticationApiService {
7376
private final JWTUtils jwtUtils;
7477
private final AuthProperties authProperties;
7578
private final CommonConfig commonConfig;
79+
private final GroupMemberService groupMemberService;
7680

7781
@Override
7882
public Mono<AuthUser> authenticateByForm(String loginId, String password, String source, boolean register, String authId, String orgId) {
@@ -143,7 +147,7 @@ public Mono<Void> loginOrRegister(AuthUser authUser, ServerWebExchange exchange,
143147
return Mono.empty();
144148
})
145149
// after login
146-
.delayUntil(user -> onUserLogin(authUser.getOrgId(), user, authUser.getSource()))
150+
.delayUntil(user -> onUserLogin(authUser.getOrgId(), user, authUser.getSource(), authUser.getGroupId()))
147151
// process invite
148152
.delayUntil(__ -> {
149153
if (StringUtils.isBlank(invitationId)) {
@@ -241,7 +245,7 @@ public Mono<Void> onUserRegister(User user, boolean isSuperAdmin) {
241245
return organizationService.createDefault(user, isSuperAdmin).then();
242246
}
243247

244-
protected Mono<Void> onUserLogin(String orgId, User user, String source) {
248+
protected Mono<Void> onUserLogin(String orgId, User user, String source, String groupId) {
245249
Mono<String> orgMono;
246250
if(commonConfig.getWorkspace().getMode() == WorkspaceMode.ENTERPRISE) {
247251
orgMono = organizationService.getOrganizationInEnterpriseMode().map(HasIdAndAuditing::getId);
@@ -251,7 +255,14 @@ protected Mono<Void> onUserLogin(String orgId, User user, String source) {
251255
}
252256
orgMono = Mono.just(orgId);
253257
}
254-
return orgMono.flatMap(orgId2 -> orgApiService.tryAddUserToOrgAndSwitchOrg(orgId2, user.getId())).then();
258+
Mono<GroupMember> groupMember = groupMemberService.getGroupMember(groupId, user.getId()).switchIfEmpty(Mono.defer(() -> {
259+
GroupMember groupMember1 = GroupMember.builder()
260+
.groupId(groupId)
261+
.userId(user.getId())
262+
.build();
263+
return groupMemberService.addMember(orgId, groupId, user.getId(), MemberRole.MEMBER).thenReturn(groupMember1);
264+
}));
265+
return orgMono.flatMap(orgId2 -> orgApiService.tryAddUserToOrgAndSwitchOrg(orgId2, user.getId())).then(groupMember).then();
255266
}
256267

257268
@Override

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/util/AuthenticationUtils.java

+3
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@ public static AuthUser mapToAuthUser(Map<String, Object> map, HashMap<String, St
9393
if(StringUtils.isEmpty(username)) username = email;
9494
if(StringUtils.isEmpty(username)) username = uid;
9595
String avatar = AdvancedMapUtils.getString(map, MapUtils.getString(sourceMappings, "avatar"));
96+
// Add group id mapping
97+
String groupId = AdvancedMapUtils.getString(map, MapUtils.getString(sourceMappings, "group_id"));
9698
return AuthUser.builder()
9799
.uid(uid)
98100
.username(username)
99101
.email(email)
100102
.avatar(avatar)
103+
.groupId(groupId) // Make sure AuthUser has this field and builder method
101104
.rawUserInfo(map)
102105
.build();
103106
}

0 commit comments

Comments
 (0)