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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected UserDetailscreateNewUserFromOAuth2(org.springframework.security.core.Authentication authentication, org.springframework.security.oauth2.core.user.OAuth2User oauth2User, String email) Creates a new user from OAuth2 dataextractFromAttribute(org.springframework.security.oauth2.core.user.OAuth2User oauth2User, String attributeName) Extracts list from simple attributeextractFromRealmAccess(org.springframework.security.oauth2.core.user.OAuth2User oauth2User) Extracts roles from realm_accessextractFromResourceAccess(org.springframework.security.oauth2.core.user.OAuth2User oauth2User) Extracts roles from resource_accessextractGroupsFromOAuth2(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.extractRolesFromClientResource(Map.Entry<String, Object> clientEntry) Extracts roles from one client resourceextractRolesFromRolesObject(Object rolesObject, String source) Helper method for extracting roles from roles objectprotected StringgetProviderId(org.springframework.security.core.Authentication authentication) Gets OAuth2 provider ID from authenticationprotected StringReturns the username attribute name from configuration, or default "preferred_username"protected voidhandleError(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String errorCode, String redirectUrl) Helper method for error handling - sets error to session and performs redirectprotected voidlogOAuth2Attributes(org.springframework.security.oauth2.core.user.OAuth2User oauth2User) Logs all attributes from OAuth2 token as JSON for diagnosticsabstract voidonAuthenticationSuccess(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.Authentication authentication) protected booleanshouldSyncPermissions(String providerId) Determines if the given provider is configured to synchronize permissionsprotected voidupdateExistingUserFromOAuth2(org.springframework.security.oauth2.core.user.OAuth2User oauth2User, UserDetails userDetails) Updates existing user with new data from OAuth2Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.security.web.authentication.AuthenticationSuccessHandler
onAuthenticationSuccess
-
Field Details
-
ROLES_ATTRIBUTE
- See Also:
-
GROUPS_ATTRIBUTE
- See Also:
-
GROUP_MEMBERSHIP_ATTRIBUTE
- See Also:
-
RESOURCE_ACCESS_ATTRIBUTE
- See Also:
-
REALM_ACCESS_ATTRIBUTE
- See Also:
-
EMAIL_ATTRIBUTE
- See Also:
-
GIVEN_NAME_ATTRIBUTE
- See Also:
-
FAMILY_NAME_ATTRIBUTE
- See Also:
-
USERNAME_ATTRIBUTE_DEFAULT
- See Also:
-
ROLE_PREFIX
- See Also:
-
PICTURE_ATTRIBUTE
- See Also:
-
-
Constructor Details
-
AbstractOAuth2SuccessHandler
public AbstractOAuth2SuccessHandler()
-
-
Method Details
-
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:
onAuthenticationSuccessin interfaceorg.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
Gets OAuth2 provider ID from authentication -
shouldSyncPermissions
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
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
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
-