Commit 54afbc25 authored by Matija Obreza's avatar Matija Obreza
Browse files

Incorrect exception thrown in user lookup method

- causes spring security to invalidate credentials in <sec:auhorize tag
parent e090c517
......@@ -25,7 +25,6 @@ import org.genesys.blocks.security.model.BasicUser;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
/**
* The Interface BasicUserService.
......@@ -40,18 +39,16 @@ public interface BasicUserService<R extends GrantedAuthority, T extends BasicUse
*
* @param id the id
* @return the user or <code>null</code>
* @throws NoUserFoundException the no user found exception
*/
T getUser(long id) throws NoUserFoundException;
T getUser(long id);
/**
* Get User by email.
*
* @param email the email
* @return the user
* @throws UsernameNotFoundException the username not found exception
*/
T getUserByEmail(String email) throws UsernameNotFoundException;
T getUserByEmail(String email);
/**
* Create a new user account with {@link #getDefaultUserRole()} assigned.
......
......@@ -100,7 +100,11 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
*/
@Override
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {
return getUserByEmail(username);
T user = getUserByEmail(username);
if (user == null) {
throw new UsernameNotFoundException(username);
}
return user;
}
/*
......@@ -108,10 +112,10 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
* @see org.genesys.blocks.security.service.BasicUserService#getUser(long)
*/
@Override
public T getUser(final long id) throws NoUserFoundException {
public T getUser(final long id) {
final T user = userRepository.findOne(id);
if (user == null) {
throw new NoUserFoundException(id);
if (user != null) {
user.getRoles().size();
}
return user;
}
......
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