22
33import static java .util .Optional .ofNullable ;
44import static org .springframework .util .StringUtils .hasLength ;
5- import static org .springframework .util .StringUtils .hasText ;
65
7- import io .openaev .database .model .Tenant ;
86import io .openaev .database .model .User ;
97import io .openaev .database .repository .UserRepository ;
108import io .openaev .service .UserMappingService ;
119import io .openaev .service .UserService ;
12- import io .openaev .service .tenants .TenantService ;
1310import io .openaev .service .user_events .UserEventService ;
14- import jakarta .persistence .EntityNotFoundException ;
1511import jakarta .validation .constraints .NotBlank ;
1612import java .util .ArrayList ;
1713import java .util .List ;
1814import java .util .Optional ;
1915import java .util .UUID ;
2016import lombok .RequiredArgsConstructor ;
21- import lombok .extern .slf4j .Slf4j ;
2217import org .springframework .core .env .Environment ;
2318import org .springframework .stereotype .Service ;
2419
25- @ Slf4j
2620@ Service
2721@ RequiredArgsConstructor
2822public class SecurityService {
@@ -32,15 +26,13 @@ public class SecurityService {
3226 public static final String GROUPS_MANAGEMENT_SUFFIX = ".groups_management" ;
3327 public static final String ALL_ADMIN_PATH_SUFFIX = ".all_admin" ;
3428 public static final String AUDIENCE_PATH = ".audience" ;
35- public static final String TENANT_ID_SUFFIX = ".tenant_id" ;
3629 public static final String REGISTRATION_ID = "registration_id" ;
3730
3831 private final UserRepository userRepository ;
3932 private final UserService userService ;
4033 private final UserMappingService userMappingService ;
4134 private final Environment env ;
4235 private final UserEventService userEventService ;
43- private final TenantService tenantService ;
4436
4537 public User userManagement (
4638 String emailAttribute ,
@@ -68,7 +60,6 @@ public User userManagement(
6860 String .class ,
6961 "" );
7062 userMappingService .mapCurrentUserWithGroup (groupsManagementObject , user , groups );
71- attachTenant (registrationId , user );
7263 return this .userService .saveUser (user );
7364 } else {
7465 // If user exists, update it
@@ -85,7 +76,6 @@ public User userManagement(
8576 String .class ,
8677 "" );
8778 userMappingService .mapCurrentUserWithGroup (groupsManagementObject , currentUser , groups );
88- attachTenant (registrationId , currentUser );
8979 return this .userService .saveUser (currentUser );
9080 }
9181 }
@@ -101,26 +91,6 @@ public String getAudience(@NotBlank final String registrationId) {
10191
10292 // -- PRIVATE --
10393
104- /** Attaches the user to the tenant configured for the given SSO provider registration. */
105- private void attachTenant (String registrationId , User user ) {
106- String tenantId =
107- env .getProperty (
108- OPENAEV_PROVIDER_PATH_PREFIX + registrationId + TENANT_ID_SUFFIX , String .class , "" );
109- if (!hasText (tenantId )) {
110- return ;
111- }
112- boolean alreadyAttached = user .getTenants ().stream ().anyMatch (t -> t .getId ().equals (tenantId ));
113- if (alreadyAttached ) {
114- return ;
115- }
116- try {
117- Tenant tenant = tenantService .findById (tenantId );
118- user .getTenants ().add (tenant );
119- } catch (EntityNotFoundException e ) {
120- log .warn ("SSO tenant ID '{}' configured but not found in database" , tenantId );
121- }
122- }
123-
12494 private List <String > getAdminRoles (@ NotBlank final String registrationId ) {
12595 String rolesAdminConfig =
12696 OPENAEV_PROVIDER_PATH_PREFIX + registrationId + ROLES_ADMIN_PATH_SUFFIX ;
0 commit comments