From a2666f0f058b87b096062308de402c8628fcfa21 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 28 Nov 2019 16:27:34 +0100 Subject: [PATCH] =?UTF-8?q?naprawy=20b=C5=82=C4=99d=C3=B3w=20z=20logowanie?= =?UTF-8?q?m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/user/UserDetailsServiceImpl.java | 27 +++++++++++++++++++ .../security/JWTAuthenticationFilter.java | 1 + .../src/main/resources/application.properties | 4 +-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 BackEnd/src/main/java/studycave/studycaverestservice/model/user/UserDetailsServiceImpl.java 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