Package de.terrestris.shoguncore.service
Class AbstractUserTokenService<E extends UserToken,D extends AbstractUserTokenDao<E>>
- java.lang.Object
-
- de.terrestris.shoguncore.service.AbstractDaoService<E,D>
-
- de.terrestris.shoguncore.service.AbstractCrudService<E,D>
-
- de.terrestris.shoguncore.service.PermissionAwareCrudService<E,D>
-
- de.terrestris.shoguncore.service.AbstractTokenService<E,D>
-
- de.terrestris.shoguncore.service.AbstractUserTokenService<E,D>
-
- Direct Known Subclasses:
PasswordResetTokenService,RegistrationTokenService
public abstract class AbstractUserTokenService<E extends UserToken,D extends AbstractUserTokenDao<E>> extends AbstractTokenService<E,D>
- Author:
- Daniel Koch, Nils Bühner
-
-
Field Summary
-
Fields inherited from class de.terrestris.shoguncore.service.PermissionAwareCrudService
permissionCollectionService
-
Fields inherited from class de.terrestris.shoguncore.service.AbstractDaoService
dao, logger
-
-
Constructor Summary
Constructors Modifier Constructor Description AbstractUserTokenService()Default constructor, which calls the type-constructorprotectedAbstractUserTokenService(Class<E> entityClass)Constructor that sets the concrete entity class for the service.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract EbuildConcreteInstance(User user, Integer expirationTimeInMinutes)Has to be implemented by subclasses to return a concrete instance for the given values.EfindByUser(User user)protected EgetValidTokenForUser(User user, Integer expirationTimeInMinutes)Returns a valid (i.e.voidvalidateToken(E userToken)If the passed token is null or expired or if there is no user associated with the token, this method will throw anException.-
Methods inherited from class de.terrestris.shoguncore.service.AbstractTokenService
findByTokenValue
-
Methods inherited from class de.terrestris.shoguncore.service.PermissionAwareCrudService
addAndSaveGroupPermissions, addAndSaveUserPermissions, findAllUserGroupPermissionsOfUserGroup, findAllUserPermissionsOfUser, getPermissionCollectionService, removeAndSaveGroupPermissions, removeAndSaveUserPermissions, setDao, setPermissionCollectionService
-
Methods inherited from class de.terrestris.shoguncore.service.AbstractCrudService
delete, findAll, findAllRestricted, findAllWhereFieldEquals, findAllWithCollectionContaining, findById, findBySimpleFilter, loadById, saveOrUpdate, updatePartialWithJsonNode
-
Methods inherited from class de.terrestris.shoguncore.service.AbstractDaoService
getDao, getEntityClass
-
-
-
-
Method Detail
-
buildConcreteInstance
protected abstract E buildConcreteInstance(User user, Integer expirationTimeInMinutes)
Has to be implemented by subclasses to return a concrete instance for the given values. Should return an instance with a default expiration time if expirationTimeInMinutes is null.- Parameters:
user-expirationTimeInMinutes-- Returns:
-
findByUser
@Transactional(readOnly=true) public E findByUser(User user)
- Parameters:
user-- Returns:
-
validateToken
@Transactional(readOnly=true) public void validateToken(E userToken) throws Exception
If the passed token is null or expired or if there is no user associated with the token, this method will throw anException.- Overrides:
validateTokenin classAbstractTokenService<E extends UserToken,D extends AbstractUserTokenDao<E>>- Parameters:
userToken-- Throws:
Exception- if the token is not valid (e.g. because it is expired)
-
getValidTokenForUser
protected E getValidTokenForUser(User user, Integer expirationTimeInMinutes) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
Returns a valid (i.e. non-expired)UserTokenfor the given user. If the user already owns a valid token, it will be returned. If the user has an invalid/expired token, it will be deleted and a new one will be generated and returned by this method.An expiration time in minutes can also be passed. If this value is null, the default value will be used.
- Parameters:
user- The user that needs a token.expirationTimeInMinutes- The expiration time in minutes. If null, the default value will be used.- Returns:
- A valid user token.
- Throws:
SecurityExceptionNoSuchMethodExceptionInvocationTargetExceptionIllegalArgumentExceptionIllegalAccessExceptionInstantiationException
-
-