1
1
package org .lowcoder .domain .authentication ;
2
2
3
- import static org .lowcoder .sdk .exception .BizError .LOG_IN_SOURCE_NOT_SUPPORTED ;
4
- import static org .lowcoder .sdk .util .ExceptionUtils .ofError ;
5
-
6
- import java .util .Objects ;
7
- import java .util .function .Function ;
8
- import java .util .stream .Collectors ;
9
-
3
+ import lombok .extern .slf4j .Slf4j ;
10
4
import org .lowcoder .domain .organization .service .OrganizationService ;
11
5
import org .lowcoder .sdk .auth .AbstractAuthConfig ;
12
6
import org .lowcoder .sdk .config .AuthProperties ;
13
7
import org .lowcoder .sdk .config .CommonConfig ;
14
8
import org .lowcoder .sdk .constants .WorkspaceMode ;
15
9
import org .springframework .beans .factory .annotation .Autowired ;
16
10
import org .springframework .stereotype .Service ;
17
-
18
- import lombok .extern .slf4j .Slf4j ;
19
11
import reactor .core .publisher .Flux ;
20
12
import reactor .core .publisher .Mono ;
21
13
14
+ import java .util .Objects ;
15
+ import java .util .function .Function ;
16
+ import java .util .stream .Collectors ;
17
+
18
+ import static org .lowcoder .sdk .exception .BizError .LOG_IN_SOURCE_NOT_SUPPORTED ;
19
+ import static org .lowcoder .sdk .util .ExceptionUtils .ofError ;
20
+
22
21
@ Slf4j
23
22
@ Service
24
23
public class AuthenticationServiceImpl implements AuthenticationService {
@@ -31,35 +30,35 @@ public class AuthenticationServiceImpl implements AuthenticationService {
31
30
private AuthProperties authProperties ;
32
31
33
32
@ Override
34
- public Mono <FindAuthConfig > findAuthConfigByAuthId (String authId ) {
35
- return findAuthConfig (abstractAuthConfig -> Objects .equals (authId , abstractAuthConfig .getId ()));
33
+ public Mono <FindAuthConfig > findAuthConfigByAuthId (String orgId , String authId ) {
34
+ return findAuthConfig (orgId , abstractAuthConfig -> Objects .equals (authId , abstractAuthConfig .getId ()));
36
35
}
37
36
38
37
@ Override
39
38
@ Deprecated
40
- public Mono <FindAuthConfig > findAuthConfigBySource (String source ) {
41
- return findAuthConfig (abstractAuthConfig -> Objects .equals (source , abstractAuthConfig .getSource ()));
39
+ public Mono <FindAuthConfig > findAuthConfigBySource (String orgId , String source ) {
40
+ return findAuthConfig (orgId , abstractAuthConfig -> Objects .equals (source , abstractAuthConfig .getSource ()));
42
41
}
43
42
44
- private Mono <FindAuthConfig > findAuthConfig (Function <AbstractAuthConfig , Boolean > condition ) {
45
- return findAllAuthConfigs (true )
43
+ private Mono <FindAuthConfig > findAuthConfig (String orgId , Function <AbstractAuthConfig , Boolean > condition ) {
44
+ return findAllAuthConfigs (orgId , true )
46
45
.filter (findAuthConfig -> condition .apply (findAuthConfig .authConfig ()))
47
46
.next ()
48
47
.switchIfEmpty (ofError (LOG_IN_SOURCE_NOT_SUPPORTED , "LOG_IN_SOURCE_NOT_SUPPORTED" ));
49
48
}
50
49
51
50
@ Override
52
- public Flux <FindAuthConfig > findAllAuthConfigs (boolean enableOnly ) {
51
+ public Flux <FindAuthConfig > findAllAuthConfigs (String orgId , boolean enableOnly ) {
53
52
return findAllAuthConfigsByDomain ()
54
53
.switchIfEmpty (findAllAuthConfigsForEnterpriseMode ())
55
- .switchIfEmpty (findAllAuthConfigsForSaasMode ())
54
+ .switchIfEmpty (findAllAuthConfigsForSaasMode (orgId ))
56
55
.filter (findAuthConfig -> {
57
56
if (enableOnly ) {
58
57
return findAuthConfig .authConfig ().isEnable ();
59
58
}
60
59
return true ;
61
60
})
62
- .defaultIfEmpty (new FindAuthConfig (DEFAULT_AUTH_CONFIG , null ));
61
+ .concatWithValues (new FindAuthConfig (DEFAULT_AUTH_CONFIG , null ));
63
62
}
64
63
65
64
private Flux <FindAuthConfig > findAllAuthConfigsByDomain () {
@@ -85,10 +84,20 @@ protected Flux<FindAuthConfig> findAllAuthConfigsForEnterpriseMode() {
85
84
);
86
85
}
87
86
88
- private Flux <FindAuthConfig > findAllAuthConfigsForSaasMode () {
87
+ private Flux <FindAuthConfig > findAllAuthConfigsForSaasMode (String orgId ) {
89
88
if (commonConfig .getWorkspace ().getMode () == WorkspaceMode .SAAS ) {
90
- return Flux .fromIterable (authProperties .getAuthConfigs ())
91
- .map (abstractAuthConfig -> new FindAuthConfig (abstractAuthConfig , null ));
89
+
90
+ // Get the auth configs for the current org
91
+ if (orgId != null ) {
92
+ return organizationService .getById (orgId )
93
+ .flatMapIterable (organization ->
94
+ organization .getAuthConfigs ()
95
+ .stream ()
96
+ .map (abstractAuthConfig -> new FindAuthConfig (abstractAuthConfig , organization ))
97
+ .collect (Collectors .toList ())
98
+ );
99
+ }
100
+
92
101
}
93
102
return Flux .empty ();
94
103
}
0 commit comments