Package de.terrestris.shoguncore.service
Class UserService<E extends User,D extends UserDao<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.PersonService<E,D>
-
- de.terrestris.shoguncore.service.UserService<E,D>
-
@Service("userService") public class UserService<E extends User,D extends UserDao<E>> extends PersonService<E,D>Service class for theUsermodel.- Author:
- Nils Bühner
- See Also:
AbstractCrudService
-
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.security.crypto.password.PasswordEncoderpasswordEncoderThe autowired PasswordEncoderprotected RegistrationTokenService<RegistrationToken,RegistrationTokenDao<RegistrationToken>>registrationTokenServiceRegistration token serviceprotected RoleService<Role,RoleDao<Role>>roleServiceRole service-
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 UserService()Default constructor, which calls the type-constructorprotectedUserService(Class<E> entityClass)Constructor that sets the concrete entity class for the service.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateUser(String tokenValue)EfindByAccountName(String accountName)Returns the user for the given (unique) account name.EfindByEmail(String email)RolegetDefaultUserRole()Set<UserGroup>getGroupsOfUser(Integer userId)org.springframework.security.crypto.password.PasswordEncodergetPasswordEncoder()EgetUserBySession()EpersistNewUser(E user, boolean encryptPassword)Persists a new user in the database.EregisterUser(E user, javax.servlet.http.HttpServletRequest request)Registers a new user.voidsetDao(D dao)We have to useQualifierto define the correct dao here.voidsetDefaultUserRole(Role defaultUserRole)voidsetPasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)voidupdatePassword(E user, String rawPassword)-
Methods inherited from class de.terrestris.shoguncore.service.PermissionAwareCrudService
addAndSaveGroupPermissions, addAndSaveUserPermissions, findAllUserGroupPermissionsOfUserGroup, findAllUserPermissionsOfUser, getPermissionCollectionService, removeAndSaveGroupPermissions, removeAndSaveUserPermissions, 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
-
-
-
-
Field Detail
-
registrationTokenService
@Autowired protected RegistrationTokenService<RegistrationToken,RegistrationTokenDao<RegistrationToken>> registrationTokenService
Registration token service
-
roleService
@Autowired protected RoleService<Role,RoleDao<Role>> roleService
Role service
-
passwordEncoder
@Autowired protected org.springframework.security.crypto.password.PasswordEncoder passwordEncoder
The autowired PasswordEncoder
-
-
Method Detail
-
setDao
@Autowired @Qualifier("userDao") public void setDao(D dao)We have to useQualifierto define the correct dao here. Otherwise, spring can not decide which dao has to be autowired here as there are multiple candidates.
-
findByAccountName
@PostAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#accountName, \'READ\')") @Transactional(readOnly=true) public E findByAccountName(String accountName)Returns the user for the given (unique) account name. If no user was found, null will be returned.- Parameters:
accountName- A unique account name.- Returns:
- The unique user for the account name or null.
-
findByEmail
@PostAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#email, \'READ\')") @Transactional(readOnly=true) public E findByEmail(String email)- Parameters:
email-- Returns:
-
registerUser
public E registerUser(E user, javax.servlet.http.HttpServletRequest request) throws Exception
Registers a new user. Initially, the user will be inactive. An email with an activation link will be sent to the user.- Parameters:
user- A user with an UNencrypted password (!)request-- Throws:
Exception
-
persistNewUser
public E persistNewUser(E user, boolean encryptPassword)
Persists a new user in the database.- Parameters:
user- The user to createencryptPassword- Whether or not the current password of the user object should be encrypted or not before the object is persisted in the db- Returns:
- The persisted user object (incl. ID value)
-
updatePassword
public void updatePassword(E user, String rawPassword) throws Exception
- Parameters:
user-rawPassword-- Throws:
Exception
-
getUserBySession
@Transactional(readOnly=true) public E getUserBySession()
-
getGroupsOfUser
@PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, \'READ\')") @Transactional(readOnly=true) public Set<UserGroup> getGroupsOfUser(Integer userId) throws Exception- Parameters:
userId-- Throws:
Exception
-
getPasswordEncoder
public org.springframework.security.crypto.password.PasswordEncoder getPasswordEncoder()
- Returns:
- the passwordEncoder
-
setPasswordEncoder
public void setPasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)
- Parameters:
passwordEncoder- the passwordEncoder to set
-
getDefaultUserRole
public Role getDefaultUserRole()
- Returns:
- the defaultUserRole
-
setDefaultUserRole
public void setDefaultUserRole(Role defaultUserRole)
- Parameters:
defaultUserRole- the defaultUserRole to set
-
-