Class DefaultUserOperationService
java.lang.Object
com.broadleafcommerce.auth.resource.service.DefaultUserOperationService
- All Implemented Interfaces:
UserOperationService
- Author:
- Nick Crum (ncrum)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected UserOperationInformationbuildUserOperationInformation(Collection<String> scopes, Set<String> allGrantedAuthorities) Builds aUserOperationInformationresponse for the given scopes and granted authorities.findAllByScopeIn(Collection<String> scopes) Finds all user operations tied to the provided set of scopes.protected AccountAncestorServicegetAccountRoleIds(User user, String accountId) getAllPermissionNamesFromRoleIds(Set<String> roleIds) getAllUserAuthoritiesForAccount(String accountId, String clientId) protected PermissionRepositoryprotected Map<String,List<PermissionScope>> getPermissionsByScope(Collection<String> scopes) protected StringgetStringValue(Map<String, Object> source, String key) protected OAuth2UserDetailsServiceprotected StringgetUsernameFromAttributes(org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication bearerTokenAuthentication) protected StringRead the username attribute from the BearerToken.getUserOperationInformation(Collection<String> scopes, String clientId) Finds theUserOperationInformationfor the current user and the given scopes.getUserOperationInformation(Collection<String> scopes, String clientId, String accountId) Finds theUserOperationInformationfor the current user and the given scopes by mapping their roles via the current user's account information.protected Collection<UserOperation>getUserOperationsForScope(String scope, List<PermissionScope> permissionScopes, Set<String> userAuthorities) protected UserRoleService<UserRole>protected UserService<User>protected booleanDetermine if the Authentication in the SecurityContext is a BearerToken (access token).protected OAuth2UserDetailsloadUserDetails(String clientId) This is a flexible method that can load theOAuth2UserDetailsfor the currently authenticated user both in the session-token-authentication case and the bearer-token-authentication case.protected UserOperationmapPermissionScopeToUserOperation(PermissionScope permissionScope, Set<String> userAuthorities) voidsetAccountAncestorService(AccountAncestorService accountAncestorService) voidsetUserDetailsService(OAuth2UserDetailsService userDetailsService) voidsetUserRoleService(UserRoleService<UserRole> userRoleService) voidsetUserService(UserService<User> userService)
-
Constructor Details
-
DefaultUserOperationService
-
-
Method Details
-
getUserOperationInformation
public UserOperationInformation getUserOperationInformation(@NonNull Collection<String> scopes, @Nullable String clientId) Description copied from interface:UserOperationServiceFinds the
UserOperationInformationfor the current user and the given scopes.Note that if this is called with a Bearer token authentication, the authorities from the token itself are ignored/unused. The full user will be read from the datastore and _all_ their authorities will be considered.
- Specified by:
getUserOperationInformationin interfaceUserOperationService- Parameters:
scopes- the set of scopes to retrieve operation info forclientId- (optional) if the current user authentication is a Bearer token, then this parameter is required to successfully find the user. This parameter is not required if the current user authentication is a session token.- Returns:
- the operation information on the current user for the given scopes
-
safeGetUserAuthoritiesFromCurrentAuthentication
-
loadUserDetails
This is a flexible method that can load theOAuth2UserDetailsfor the currently authenticated user both in the session-token-authentication case and the bearer-token-authentication case.- Parameters:
clientId- (optional) required only if the current authentication is a bearer token authentication, as bearer token authentication does not contain client ID information- Returns:
- the
OAuth2UserDetailsfor the currently authenticated user, elsenullif not able to load.
-
isBearerTokenAuth
protected boolean isBearerTokenAuth()Determine if the Authentication in the SecurityContext is a BearerToken (access token).- Returns:
- True in the Authentication in the SecurityContext is a BearerToken (access token).
-
getUsernameFromBearerToken
Read the username attribute from the BearerToken.- Returns:
- the username attribute from the BearerToken.
-
getUsernameFromAttributes
@Nullable protected String getUsernameFromAttributes(org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication bearerTokenAuthentication) - Returns:
- the username value from the given access token attributes
-
getStringValue
-
buildUserOperationInformation
protected UserOperationInformation buildUserOperationInformation(Collection<String> scopes, Set<String> allGrantedAuthorities) Builds aUserOperationInformationresponse for the given scopes and granted authorities.- Parameters:
scopes- the requested scopes to evaluate user accessibility forallGrantedAuthorities- the full list of authorities to consider as available to the user. This may be all authorities available to the user directly, or alternatively all authorities granted to the user by a particular account (if checking account scopes).- Returns:
- an
UserOperationInformationresponse containing the filtered operations allowed to the user for each scope
-
getPermissionsByScope
-
getUserOperationsForScope
protected Collection<UserOperation> getUserOperationsForScope(String scope, List<PermissionScope> permissionScopes, Set<String> userAuthorities) -
mapPermissionScopeToUserOperation
protected UserOperation mapPermissionScopeToUserOperation(PermissionScope permissionScope, Set<String> userAuthorities) -
getUserOperationInformation
public UserOperationInformation getUserOperationInformation(@NonNull Collection<String> scopes, @Nullable String clientId, @NonNull String accountId) Description copied from interface:UserOperationServiceFinds the
UserOperationInformationfor the current user and the given scopes by mapping their roles via the current user's account information.Note that if this is called with a Bearer token authentication, the authorities from the token itself are ignored/unused. The full user will be read from the datastore and _all_ their authorities will be considered.
- Specified by:
getUserOperationInformationin interfaceUserOperationService- Parameters:
scopes- the set of scopes to retrieve operation info forclientId- (optional) if the current user authentication is a Bearer token, then this parameter is required to successfully find the user. This parameter is not required if the current user authentication is a session token.accountId- the id to use to check if the current user has permissions for the account- Returns:
- the operation information on the current user for the given scopes
-
getAllUserAuthoritiesForAccount
-
getAccountRoleIds
-
getAllPermissionNamesFromRoleIds
-
findAllByScopeIn
Description copied from interface:UserOperationServiceFinds all user operations tied to the provided set of scopes.- Specified by:
findAllByScopeInin interfaceUserOperationService- Parameters:
scopes- the set of scopes to retrieve operations for- Returns:
- all `UserOperation` matching at least one of the scopes
-
getPermissionRepository
-
getUserRoleService
-
setUserRoleService
-
getUserService
-
setUserService
-
getAccountAncestorService
-
setAccountAncestorService
@Autowired @Lazy public void setAccountAncestorService(AccountAncestorService accountAncestorService) -
getUserDetailsService
-
setUserDetailsService
-