Class DefaultAuthorizedClientService<P extends AuthorizedClient,D extends com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable & com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware>
- java.lang.Object
-
- com.broadleafcommerce.auth.server.service.DefaultAuthorizedClientService<P,D>
-
- All Implemented Interfaces:
AuthorizedClientService<P>
public class DefaultAuthorizedClientService<P extends AuthorizedClient,D extends com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable & com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware> extends Object implements AuthorizedClientService<P>
-
-
Constructor Summary
Constructors Constructor Description DefaultAuthorizedClientService(AuthorizationServerService<AuthorizationServer> serverService, AuthorizedClientRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, TenantUrlResolver tenantUrlResolver)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Pcreate(P authorizedClient)Create a new authorized client.voiddelete(P authorizedClient)Delete an authorized client.voiddeleteById(String id)Delete an authorized client by ID.booleanexistsById(String id)Check if an authorized client exists by its ID.Optional<P>findAdminClient(String tenantId)Finds the authorized client for the admin within the given context.org.springframework.data.domain.Page<P>findAll(org.springframework.data.domain.Pageable pageable)Find all authorized clients.org.springframework.data.domain.Page<P>findAllByServerId(String serverId, org.springframework.data.domain.Pageable pageable)Finds all authorized clients within an authorization server.Optional<P>findApplicationClient(String applicationId)Finds the authorized client for the application within the given context.Optional<P>findApplicationClient(String applicationId, String tenantId)Finds the authorized client for the application within the given context.Optional<P>findByClientId(String authorizedClientId)Find an authorized client by its client ID.Optional<P>findById(String id)Find an authorized client by its ID.protected Optional<D>findRepositoryDomainById(String id)protected Optional<P>fromRepositoryDomain(Optional<D> optionalDomain)protected org.springframework.data.domain.Page<P>fromRepositoryDomain(org.springframework.data.domain.Page<D> page)protected StringgenerateAuthorizedClientId(P authorizedClient)Generates a Base64, 16-bit string appended with the server name as the client ID for a newly created authorized client.protected SimplePayloadMappergetMapper()protected org.springframework.security.crypto.password.PasswordEncodergetPasswordEncoder()protected AuthorizedClientRepository<D>getRepository()protected AuthorizationServerService<AuthorizationServer>getServerService()protected TenantUrlResolvergetTenantUrlResolver()protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManagergetValidator()Preplace(String id, P authorizedClient)Replace an authorized client.Optional<String>resolveAbsolutePathForUri(String uri, AuthorizedClient client)Resolves the absolute path for the string uri providedOptional<String>resolveAbsolutePathsForRelativeDefaultRedirectUri(AuthorizedClient client)Resolves the absolute path for the default redirect uri on the providedAuthorizedClientSet<String>resolveAbsolutePathsForRelativeRedirectUris(AuthorizedClient client)Resolves the absolute path for the redirect uris on the providedAuthorizedClientSet<String>resolveAbsolutePathsForUris(Set<String> uris, AuthorizedClient client)Resolves the absolute path for the string uris providedprotected Optional<org.springframework.web.util.UriComponentsBuilder>resolveBaseUri(AuthorizedClient client)Determines the base URI of the application or admin the client is used for.Psave(P authorizedClient)Save an authorized client.protected voidvalidate(P authorizedClient)protected voidvalidateUniqueAdminClientPerTenant(P authorizedClient, org.springframework.validation.Errors errors)
-
-
-
Constructor Detail
-
DefaultAuthorizedClientService
public DefaultAuthorizedClientService(AuthorizationServerService<AuthorizationServer> serverService, AuthorizedClientRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, TenantUrlResolver tenantUrlResolver)
-
-
Method Detail
-
findAll
public org.springframework.data.domain.Page<P> findAll(org.springframework.data.domain.Pageable pageable)
Description copied from interface:AuthorizedClientServiceFind all authorized clients.- Specified by:
findAllin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
pageable- the pageable- Returns:
- a page of authorized client
-
findAllByServerId
public org.springframework.data.domain.Page<P> findAllByServerId(String serverId, org.springframework.data.domain.Pageable pageable)
Description copied from interface:AuthorizedClientServiceFinds all authorized clients within an authorization server.- Specified by:
findAllByServerIdin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
serverId- the server IDpageable- the pageable- Returns:
- a page of authorized client
-
findAdminClient
public Optional<P> findAdminClient(String tenantId)
Description copied from interface:AuthorizedClientServiceFinds the authorized client for the admin within the given context.- Specified by:
findAdminClientin interfaceAuthorizedClientService<P extends AuthorizedClient>- Returns:
- an optional of authorized client
-
findApplicationClient
public Optional<P> findApplicationClient(String applicationId, String tenantId)
Description copied from interface:AuthorizedClientServiceFinds the authorized client for the application within the given context.- Specified by:
findApplicationClientin interfaceAuthorizedClientService<P extends AuthorizedClient>- Returns:
- an optional of authorized client
-
findApplicationClient
public Optional<P> findApplicationClient(String applicationId)
Description copied from interface:AuthorizedClientServiceFinds the authorized client for the application within the given context.- Specified by:
findApplicationClientin interfaceAuthorizedClientService<P extends AuthorizedClient>- Returns:
- an optional of authorized client
-
existsById
public boolean existsById(String id)
Description copied from interface:AuthorizedClientServiceCheck if an authorized client exists by its ID.- Specified by:
existsByIdin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
id- the authorized client ID- Returns:
- whether or the not the authorized client exists
-
findById
public Optional<P> findById(String id)
Description copied from interface:AuthorizedClientServiceFind an authorized client by its ID.- Specified by:
findByIdin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
id- the authorized client ID- Returns:
- an optional of authorized client
-
findByClientId
public Optional<P> findByClientId(String authorizedClientId)
Description copied from interface:AuthorizedClientServiceFind an authorized client by its client ID.- Specified by:
findByClientIdin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
authorizedClientId- the client ID of the authorization client- Returns:
- an optional of authorized client
-
create
public P create(P authorizedClient)
Description copied from interface:AuthorizedClientServiceCreate a new authorized client.AuthorizedClient#getServer()must not be null.- Specified by:
createin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
authorizedClient- the authorized client to create- Returns:
- the created authorized client
-
generateAuthorizedClientId
protected String generateAuthorizedClientId(P authorizedClient)
Generates a Base64, 16-bit string appended with the server name as the client ID for a newly created authorized client.- Parameters:
authorizedClient- the new authorized client- Returns:
- the client ID
-
save
public P save(P authorizedClient)
Description copied from interface:AuthorizedClientServiceSave an authorized client.- Specified by:
savein interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
authorizedClient- the authorized client to save- Returns:
- the saved authorized client
-
replace
public P replace(String id, P authorizedClient)
Description copied from interface:AuthorizedClientServiceReplace an authorized client.- Specified by:
replacein interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
id- the authorized client ID to replaceauthorizedClient- the authorized client replacement- Returns:
- the created authorized client
-
delete
public void delete(P authorizedClient)
Description copied from interface:AuthorizedClientServiceDelete an authorized client.- Specified by:
deletein interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
authorizedClient- the authorized client to delete
-
deleteById
public void deleteById(String id)
Description copied from interface:AuthorizedClientServiceDelete an authorized client by ID.- Specified by:
deleteByIdin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
id- the ID of the authorized client to delete
-
resolveAbsolutePathsForRelativeDefaultRedirectUri
public Optional<String> resolveAbsolutePathsForRelativeDefaultRedirectUri(AuthorizedClient client)
Description copied from interface:AuthorizedClientServiceResolves the absolute path for the default redirect uri on the providedAuthorizedClient- Specified by:
resolveAbsolutePathsForRelativeDefaultRedirectUriin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
client- TheAuthorizedClientto resolve the default redirect uri for- Returns:
- The absolute path for the default redirect uri on the provided
AuthorizedClientif one is resolved else an emptyOptional
-
resolveAbsolutePathsForRelativeRedirectUris
public Set<String> resolveAbsolutePathsForRelativeRedirectUris(AuthorizedClient client)
Description copied from interface:AuthorizedClientServiceResolves the absolute path for the redirect uris on the providedAuthorizedClient- Specified by:
resolveAbsolutePathsForRelativeRedirectUrisin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
client- TheAuthorizedClientto resolve the redirect uris for- Returns:
- The absolute paths for the redirect uris on the provided
AuthorizedClientthat could be resolved
-
resolveAbsolutePathForUri
public Optional<String> resolveAbsolutePathForUri(String uri, AuthorizedClient client)
Description copied from interface:AuthorizedClientServiceResolves the absolute path for the string uri provided- Specified by:
resolveAbsolutePathForUriin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
uri- The uri to resolve the absolute path forclient- TheAuthorizedClientto use for finding the domain, host, etc.- Returns:
- The uri resolved to an absolute path if possible else an empty
Optional
-
resolveAbsolutePathsForUris
public Set<String> resolveAbsolutePathsForUris(Set<String> uris, AuthorizedClient client)
Description copied from interface:AuthorizedClientServiceResolves the absolute path for the string uris provided- Specified by:
resolveAbsolutePathsForUrisin interfaceAuthorizedClientService<P extends AuthorizedClient>- Parameters:
uris- The uris to resolve absolute paths forclient- TheAuthorizedClientto use for finding the domain, host, etc.- Returns:
- The uris that could be resolved to absolute paths
-
resolveBaseUri
protected Optional<org.springframework.web.util.UriComponentsBuilder> resolveBaseUri(AuthorizedClient client)
Determines the base URI of the application or admin the client is used for.Delegates to
TenantUrlResolver.To preserve best-effort for the remainder of the flow, this method will not throw exceptions. Errors will be gracefully logged, and
Optional.empty()will be returned.- Parameters:
client- the client whose admin or application base URI needs to be found- Returns:
- a
UriComponentsBuilderrepresenting the base URI if successfully found,Optional.empty()otherwise
-
fromRepositoryDomain
protected org.springframework.data.domain.Page<P> fromRepositoryDomain(org.springframework.data.domain.Page<D> page)
-
validate
protected void validate(P authorizedClient)
-
validateUniqueAdminClientPerTenant
protected void validateUniqueAdminClientPerTenant(P authorizedClient, org.springframework.validation.Errors errors)
-
getServerService
protected AuthorizationServerService<AuthorizationServer> getServerService()
-
getRepository
protected AuthorizedClientRepository<D> getRepository()
-
getMapper
protected SimplePayloadMapper getMapper()
-
getValidator
protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
-
getPasswordEncoder
protected org.springframework.security.crypto.password.PasswordEncoder getPasswordEncoder()
-
getTenantUrlResolver
protected TenantUrlResolver getTenantUrlResolver()
-
-