Skip to content

Commit

Permalink
CAUSEWAY-3778: check if principal is OidcUser
Browse files Browse the repository at this point in the history
rather than DefaultOidcUser
  • Loading branch information
danhaywood committed Jun 14, 2024
1 parent e057c3c commit 16957e5
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.lang.Nullable;
import org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent;
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.stereotype.Service;

import org.apache.causeway.applib.services.factory.FactoryService;
Expand Down Expand Up @@ -67,13 +68,14 @@ public void onApplicationEvent(final InteractiveAuthenticationSuccessEvent event

val authentication = event.getAuthentication();
val principal = authentication.getPrincipal();
if (!(principal instanceof DefaultOidcUser)) {
if (!(principal instanceof OidcUser)) {
return;
}

val oidcUser = (DefaultOidcUser) principal;
val username = oidcUser.getIdToken().getPreferredUsername();
val email = oidcUser.getIdToken().getEmail();
val oidcUser = (OidcUser) principal;
val username = oidcUser.getPreferredUsername();
val email = oidcUser.getEmail();

interactionService.runAnonymous(() -> {
Optional<ApplicationUser> userIfAny = applicationUserRepository.findByUsername(username);
if (userIfAny.isEmpty()) {
Expand Down

0 comments on commit 16957e5

Please sign in to comment.