66
77import io .openaev .database .model .Tenant ;
88import io .openaev .database .model .User ;
9+ import io .openaev .database .repository .TenantRepository ;
910import io .openaev .database .repository .UserRepository ;
1011import io .openaev .service .UserMappingService ;
1112import io .openaev .service .UserService ;
12- import io .openaev .service .tenants .TenantService ;
1313import io .openaev .service .user_events .UserEventService ;
1414import jakarta .persistence .EntityNotFoundException ;
1515import jakarta .validation .constraints .NotBlank ;
1919import java .util .UUID ;
2020import lombok .RequiredArgsConstructor ;
2121import lombok .extern .slf4j .Slf4j ;
22- import org .springframework .context .annotation .Lazy ;
2322import org .springframework .core .env .Environment ;
2423import org .springframework .stereotype .Service ;
2524
@@ -41,7 +40,7 @@ public class SecurityService {
4140 private final UserMappingService userMappingService ;
4241 private final Environment env ;
4342 private final UserEventService userEventService ;
44- private final @ Lazy TenantService tenantService ;
43+ private final TenantRepository tenantRepository ;
4544
4645 public User userManagement (
4746 String emailAttribute ,
@@ -115,7 +114,11 @@ private void attachTenant(String registrationId, User user) {
115114 return ;
116115 }
117116 try {
118- Tenant tenant = tenantService .findById (tenantId );
117+ Tenant tenant =
118+ tenantRepository
119+ .findById (tenantId )
120+ .orElseThrow (() -> new EntityNotFoundException ("Tenant not found: " + tenantId ));
121+ ;
119122 user .getTenants ().add (tenant );
120123 } catch (EntityNotFoundException e ) {
121124 log .warn ("SSO tenant ID '{}' configured but not found in database" , tenantId );
0 commit comments