Class AbstractOAuth2SuccessHandler

java.lang.Object
sk.iway.iwcm.system.spring.oauth2.AbstractOAuth2SuccessHandler
All Implemented Interfaces:
org.springframework.security.web.authentication.AuthenticationSuccessHandler
Direct Known Subclasses:
OAuth2AdminSuccessHandler, OAuth2UserSuccessHandler

public abstract class AbstractOAuth2SuccessHandler extends Object implements org.springframework.security.web.authentication.AuthenticationSuccessHandler
Abstract base class for OAuth2 Success Handlers Contains shared functionality for admin and user login
  • Field Details

  • Constructor Details

    • AbstractOAuth2SuccessHandler

      public AbstractOAuth2SuccessHandler()
  • Method Details

    • getUsernameAttribute

      protected String getUsernameAttribute()
      Returns the username attribute name from configuration, or default "preferred_username"
    • onAuthenticationSuccess

      public abstract void onAuthenticationSuccess(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.Authentication authentication) throws IOException
      Specified by:
      onAuthenticationSuccess in interface org.springframework.security.web.authentication.AuthenticationSuccessHandler
      Throws:
      IOException
    • createNewUserFromOAuth2

      protected UserDetails createNewUserFromOAuth2(org.springframework.security.core.Authentication authentication, org.springframework.security.oauth2.core.user.OAuth2User oauth2User, String email)
      Creates a new user from OAuth2 data
    • updateExistingUserFromOAuth2

      protected void updateExistingUserFromOAuth2(org.springframework.security.oauth2.core.user.OAuth2User oauth2User, UserDetails userDetails)
      Updates existing user with new data from OAuth2
    • getProviderId

      protected String getProviderId(org.springframework.security.core.Authentication authentication)
      Gets OAuth2 provider ID from authentication
    • shouldSyncPermissions

      protected boolean shouldSyncPermissions(String providerId)
      Determines if the given provider is configured to synchronize permissions
    • extractGroupsFromOAuth2

      protected List<String> extractGroupsFromOAuth2(org.springframework.security.oauth2.core.user.OAuth2User oauth2User)
      Extracts list of groups from OAuth2 attributes Supports various formats: groups, roles, resource_access.client.roles, etc.
    • extractFromAttribute

      protected List<String> extractFromAttribute(org.springframework.security.oauth2.core.user.OAuth2User oauth2User, String attributeName)
      Extracts list from simple attribute
    • extractFromResourceAccess

      protected List<String> extractFromResourceAccess(org.springframework.security.oauth2.core.user.OAuth2User oauth2User)
      Extracts roles from resource_access
    • extractRolesFromClientResource

      protected List<String> extractRolesFromClientResource(Map.Entry<String,Object> clientEntry)
      Extracts roles from one client resource
    • extractFromRealmAccess

      protected List<String> extractFromRealmAccess(org.springframework.security.oauth2.core.user.OAuth2User oauth2User)
      Extracts roles from realm_access
    • extractRolesFromRolesObject

      protected List<String> extractRolesFromRolesObject(Object rolesObject, String source)
      Helper method for extracting roles from roles object
    • logOAuth2Attributes

      protected void logOAuth2Attributes(org.springframework.security.oauth2.core.user.OAuth2User oauth2User)
      Logs all attributes from OAuth2 token as JSON for diagnostics
    • handleError

      protected void handleError(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String errorCode, String redirectUrl) throws IOException
      Helper method for error handling - sets error to session and performs redirect
      Throws:
      IOException