diff --git a/BackEnd/src/main/java/studycave/studycaverestservice/model/user/UserDetailsServiceImpl.java b/BackEnd/src/main/java/studycave/studycaverestservice/model/user/UserDetailsServiceImpl.java new file mode 100644 index 0000000..5b16035 --- /dev/null +++ b/BackEnd/src/main/java/studycave/studycaverestservice/model/user/UserDetailsServiceImpl.java @@ -0,0 +1,27 @@ +package studycave.studycaverestservice.model.user; + +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import static java.util.Collections.emptyList; + +@Service +public class UserDetailsServiceImpl implements UserDetailsService { + private UserRepository applicationUserRepository; + + public UserDetailsServiceImpl(UserRepository applicationUserRepository) { + this.applicationUserRepository = applicationUserRepository; + } + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + studycave.studycaverestservice.model.user.User applicationUser = applicationUserRepository.findByUsername(username).orElse(null); + if (applicationUser == null) { + throw new UsernameNotFoundException(username); + } + return new User(applicationUser.getUsername(), applicationUser.getPassword(), emptyList()); + } +} diff --git a/BackEnd/src/main/java/studycave/studycaverestservice/security/JWTAuthenticationFilter.java b/BackEnd/src/main/java/studycave/studycaverestservice/security/JWTAuthenticationFilter.java index 5218fa5..f35453d 100644 --- a/BackEnd/src/main/java/studycave/studycaverestservice/security/JWTAuthenticationFilter.java +++ b/BackEnd/src/main/java/studycave/studycaverestservice/security/JWTAuthenticationFilter.java @@ -15,6 +15,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.userdetails.User; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/BackEnd/src/main/resources/application.properties b/BackEnd/src/main/resources/application.properties index 902d768..c265803 100644 --- a/BackEnd/src/main/resources/application.properties +++ b/BackEnd/src/main/resources/application.properties @@ -6,10 +6,10 @@ spring.datasource.password=L0XIcnvtWpYEnr4w spring.servlet.multipart.max-file-size=500KB spring.servlet.multipart.max-request-size=500KB -application.key = 5z57PPmtR4wXaRZDSpUH -application.secret = ccAxvXDqLwdkPpekJrS2fdfGQ2jLnb22fa4uB5Ef #usos instance to use usos.baseURI=https://usosapps.amu.edu.pl usos.basePath=/services usos.port=443 +application.key = 5z57PPmtR4wXaRZDSpUH +application.secret = ccAxvXDqLwdkPpekJrS2fdfGQ2jLnb22fa4uB5Ef \ No newline at end of file