11package org .lowcoder .domain .authentication ;
22
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 ;
104import org .lowcoder .domain .organization .service .OrganizationService ;
115import org .lowcoder .sdk .auth .AbstractAuthConfig ;
126import org .lowcoder .sdk .config .AuthProperties ;
137import org .lowcoder .sdk .config .CommonConfig ;
148import org .lowcoder .sdk .constants .WorkspaceMode ;
159import org .springframework .beans .factory .annotation .Autowired ;
1610import org .springframework .stereotype .Service ;
17-
18- import lombok .extern .slf4j .Slf4j ;
1911import reactor .core .publisher .Flux ;
2012import reactor .core .publisher .Mono ;
2113
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+
2221@ Slf4j
2322@ Service
2423public class AuthenticationServiceImpl implements AuthenticationService {
@@ -31,35 +30,35 @@ public class AuthenticationServiceImpl implements AuthenticationService {
3130 private AuthProperties authProperties ;
3231
3332 @ 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 ()));
3635 }
3736
3837 @ Override
3938 @ 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 ()));
4241 }
4342
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 )
4645 .filter (findAuthConfig -> condition .apply (findAuthConfig .authConfig ()))
4746 .next ()
4847 .switchIfEmpty (ofError (LOG_IN_SOURCE_NOT_SUPPORTED , "LOG_IN_SOURCE_NOT_SUPPORTED" ));
4948 }
5049
5150 @ Override
52- public Flux <FindAuthConfig > findAllAuthConfigs (boolean enableOnly ) {
51+ public Flux <FindAuthConfig > findAllAuthConfigs (String orgId , boolean enableOnly ) {
5352 return findAllAuthConfigsByDomain ()
5453 .switchIfEmpty (findAllAuthConfigsForEnterpriseMode ())
55- .switchIfEmpty (findAllAuthConfigsForSaasMode ())
54+ .switchIfEmpty (findAllAuthConfigsForSaasMode (orgId ))
5655 .filter (findAuthConfig -> {
5756 if (enableOnly ) {
5857 return findAuthConfig .authConfig ().isEnable ();
5958 }
6059 return true ;
6160 })
62- .defaultIfEmpty (new FindAuthConfig (DEFAULT_AUTH_CONFIG , null ));
61+ .concatWithValues (new FindAuthConfig (DEFAULT_AUTH_CONFIG , null ));
6362 }
6463
6564 private Flux <FindAuthConfig > findAllAuthConfigsByDomain () {
@@ -85,10 +84,20 @@ protected Flux<FindAuthConfig> findAllAuthConfigsForEnterpriseMode() {
8584 );
8685 }
8786
88- private Flux <FindAuthConfig > findAllAuthConfigsForSaasMode () {
87+ private Flux <FindAuthConfig > findAllAuthConfigsForSaasMode (String orgId ) {
8988 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+
92101 }
93102 return Flux .empty ();
94103 }
0 commit comments