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 UserOperationInformation
buildUserOperationInformation
(Collection<String> scopes, Set<String> allGrantedAuthorities) Builds aUserOperationInformation
response for the given scopes and granted authorities.findAllByScopeIn
(Collection<String> scopes) Finds all user operations tied to the provided set of scopes.protected AccountAncestorService
getAccountRoleIds
(User user, String accountId) getAllPermissionNamesFromRoleIds
(Set<String> roleIds) getAllUserAuthoritiesForAccount
(String accountId, String clientId) protected PermissionRepository
protected Map<String,
List<PermissionScope>> getPermissionsByScope
(Collection<String> scopes) protected String
getStringValue
(Map<String, Object> source, String key) protected OAuth2UserDetailsService
protected String
getUsernameFromAttributes
(org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication bearerTokenAuthentication) protected String
Read the username attribute from the BearerToken.getUserOperationInformation
(Collection<String> scopes, String clientId) Finds theUserOperationInformation
for the current user and the given scopes.getUserOperationInformation
(Collection<String> scopes, String clientId, String accountId) Finds theUserOperationInformation
for 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 boolean
Determine if the Authentication in the SecurityContext is a BearerToken (access token).protected OAuth2UserDetails
loadUserDetails
(String clientId) This is a flexible method that can load theOAuth2UserDetails
for the currently authenticated user both in the session-token-authentication case and the bearer-token-authentication case.protected UserOperation
mapPermissionScopeToUserOperation
(PermissionScope permissionScope, Set<String> userAuthorities) void
setAccountAncestorService
(AccountAncestorService accountAncestorService) void
setUserDetailsService
(OAuth2UserDetailsService userDetailsService) void
setUserRoleService
(UserRoleService<UserRole> userRoleService) void
setUserService
(UserService<User> userService)
-
Constructor Details
-
DefaultUserOperationService
-
-
Method Details
-
getUserOperationInformation
public UserOperationInformation getUserOperationInformation(@NonNull Collection<String> scopes, @Nullable String clientId) Description copied from interface:UserOperationService
Finds the
UserOperationInformation
for 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:
getUserOperationInformation
in 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 theOAuth2UserDetails
for 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
OAuth2UserDetails
for the currently authenticated user, elsenull
if 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 aUserOperationInformation
response 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
UserOperationInformation
response 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:UserOperationService
Finds the
UserOperationInformation
for 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:
getUserOperationInformation
in 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:UserOperationService
Finds all user operations tied to the provided set of scopes.- Specified by:
findAllByScopeIn
in 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
-