Commit 3e5b11d7 authored by Matija Obreza's avatar Matija Obreza
Browse files

BasicUserService#setAccountType added

parent bb783aac
......@@ -22,6 +22,7 @@ import org.genesys.blocks.security.NoUserFoundException;
import org.genesys.blocks.security.NotUniqueUserException;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser;
import org.genesys.blocks.security.model.BasicUser.AccountType;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetailsService;
......@@ -134,4 +135,13 @@ public interface BasicUserService<R extends GrantedAuthority, T extends BasicUse
* @return the default user role
*/
R getDefaultUserRole();
/**
* Sets the account type.
*
* @param user the user
* @param accountType the account type
* @return the t
*/
T setAccountType(T user, AccountType accountType);
}
......@@ -147,10 +147,10 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
if (!StringUtils.equals(email, user.getEmail()) && getUserByEmail(email) != null) {
throw new NotUniqueUserException("Email address already registered");
}
user.setEmail(email);
user.setFullName(fullName);
return deepLoad(userRepository.save(user));
}
......@@ -272,4 +272,16 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
setAccountLockLocal(userId, locked);
}
@Override
@Transactional
public T setAccountType(T user, AccountType accountType) {
T u = userRepository.findOne(user.getId());
u.setAccountType(accountType);
if (accountType != AccountType.LOCAL) {
user.setPassword(THIS_IS_NOT_A_PASSWORD);
}
return userRepository.save(u);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment