add UserService unit test, modify UserService

This commit is contained in:
rjclancy
2019-03-26 12:05:42 +00:00
committed by Nanne Baars
parent 93830ac15b
commit bb7fb3f197
2 changed files with 76 additions and 9 deletions

View File

@ -1,6 +1,6 @@
package org.owasp.webwolf.user;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@ -10,26 +10,27 @@ import org.springframework.stereotype.Service;
* @since 3/19/17.
*/
@Service
@AllArgsConstructor
public class UserService implements UserDetailsService {
private final UserRepository userRepository;
private UserRepository userRepository;
@Autowired
public UserService(final UserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public WebGoatUser loadUserByUsername(String username) throws UsernameNotFoundException {
public WebGoatUser loadUserByUsername(final String username) throws UsernameNotFoundException {
WebGoatUser webGoatUser = userRepository.findByUsername(username);
if (webGoatUser == null) {
throw new UsernameNotFoundException("User not found");
} else {
webGoatUser.createUser();
}
webGoatUser.createUser();
return webGoatUser;
}
public void addUser(String username, String password) {
public void addUser(final String username, final String password) {
userRepository.save(new WebGoatUser(username, password));
}
}