Add detailed logging and error handling to OIDC User Service
This commit is contained in:
parent
85644dc2a4
commit
3e2dab01b5
1 changed files with 63 additions and 43 deletions
|
|
@ -262,7 +262,12 @@ public class SecurityConfig {
|
|||
final OidcUserService delegate = new OidcUserService();
|
||||
|
||||
return (userRequest) -> {
|
||||
try {
|
||||
log.info("=== OIDC User Service called ===");
|
||||
|
||||
OidcUser oidcUser = delegate.loadUser(userRequest);
|
||||
log.info("OIDC User loaded successfully");
|
||||
|
||||
Integer userId = null;
|
||||
|
||||
// Debug: Print all claims
|
||||
|
|
@ -282,6 +287,8 @@ public class SecurityConfig {
|
|||
String firstName = oidcUser.getAttribute(firstnameClaim);
|
||||
String lastName = oidcUser.getAttribute(lastNameClaim);
|
||||
|
||||
log.info("Claims extracted - email: {}, workdayId: {}, firstName: {}, lastName: {}",
|
||||
email, workdayId, firstName, lastName);
|
||||
|
||||
if (identifyBy.equals("email") && email != null && !email.isEmpty()) {
|
||||
log.debug("Fetch user by email {}", email);
|
||||
|
|
@ -293,14 +300,17 @@ public class SecurityConfig {
|
|||
|
||||
if (user != null) {
|
||||
userId = user.getId();
|
||||
log.info("User found with ID: {}", userId);
|
||||
} else {
|
||||
if (email != null && firstName != null && lastName != null && (ignoreWorkdayClaim || workdayId != null)) {
|
||||
log.info("Creating new user");
|
||||
var isFirstUser = userRepository.count() == 0;
|
||||
user = LccOidcUser.createDatabaseUser(email, firstName, lastName, ignoreWorkdayClaim ? generateRandomWorkdayId() : workdayId, isFirstUser);
|
||||
userId = userRepository.update(user);
|
||||
|
||||
log.info("New user created with ID: {}", userId);
|
||||
} else {
|
||||
log.debug("Unable to create user {} / {}", email, workdayId);
|
||||
log.warn("Unable to create user - email: {}, firstName: {}, lastName: {}, workdayId: {}",
|
||||
email, firstName, lastName, workdayId);
|
||||
mappedAuthorities.add(new SimpleGrantedAuthority("ROLE_NONE"));
|
||||
}
|
||||
}
|
||||
|
|
@ -310,6 +320,8 @@ public class SecurityConfig {
|
|||
user.getGroups().forEach(group -> mappedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + group.getName().toUpperCase())));
|
||||
}
|
||||
|
||||
log.info("=== OIDC User Service completed successfully ===");
|
||||
|
||||
return new LccOidcUser(
|
||||
mappedAuthorities,
|
||||
oidcUser.getIdToken(),
|
||||
|
|
@ -317,6 +329,14 @@ public class SecurityConfig {
|
|||
"preferred_username",
|
||||
userId
|
||||
);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("=== FATAL ERROR in oidcUserService ===", e);
|
||||
log.error("Exception type: {}", e.getClass().getName());
|
||||
log.error("Exception message: {}", e.getMessage());
|
||||
log.error("Stack trace:", e);
|
||||
throw e; // Re-throw to maintain Spring Security behavior
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue