Public Access
Cleaned a little bit up
This commit is contained in:
1 parent
afd71b82be
commit
5dc3632687
6 files changed
+8
-9
No files matched your search
@@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
@@ -83,6 +84,7 @@ public class SecurityConfig {
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers(WHITE_LIST_URLS).permitAll()
|
||||
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
|
||||
|
||||
@@ -8,6 +8,6 @@ public abstract class ApiMapper {
|
||||
}
|
||||
|
||||
public static User toModel(LoginRequest loginRequest) {
|
||||
return User.builder().email(loginRequest.email()).encryptedPassword(loginRequest.password()).build();
|
||||
return User.builder().email(loginRequest.email()).password(loginRequest.password()).build();
|
||||
}
|
||||
}
|
||||
@@ -8,5 +8,5 @@ import lombok.Data;
|
||||
public class User {
|
||||
private long id;
|
||||
private String email;
|
||||
private String encryptedPassword;
|
||||
private String password;
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public abstract class EntityMapper {
|
||||
if (entity != null) {
|
||||
model.setId(entity.getId());
|
||||
model.setEmail(entity.getEmail());
|
||||
model.setEncryptedPassword(entity.getPassword());
|
||||
model.setPassword(entity.getPassword());
|
||||
}
|
||||
|
||||
return model;
|
||||
|
||||
@@ -19,11 +19,8 @@ public class LoginService {
|
||||
private final JwtService jwtService;
|
||||
|
||||
public String login(User userToLogin) {
|
||||
var userEntity = minimalUserRepository.findByEmail(userToLogin.getEmail()).orElseThrow(() -> new UserNotFoundException("User not found with given email"));
|
||||
|
||||
log.info("Login attempt for user {}", passwordEncoder.encode(userToLogin.getEncryptedPassword()) + " " + userEntity.getEncryptedPassword());
|
||||
|
||||
var loginSuccessful = passwordEncoder.matches(userToLogin.getEncryptedPassword(), userEntity.getEncryptedPassword());
|
||||
var userFromDatabase = minimalUserRepository.findByEmail(userToLogin.getEmail()).orElseThrow(() -> new UserNotFoundException("User not found with given email"));
|
||||
var loginSuccessful = passwordEncoder.matches(userToLogin.getPassword(), userFromDatabase.getPassword());
|
||||
if (!loginSuccessful) {
|
||||
throw new InvalidCredentialsException("Invalid credentials");
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ spring:
|
||||
profiles:
|
||||
active: dev # Default profile for local startup
|
||||
jpa:
|
||||
open-in-view: false
|
||||
open-in-view: true
|
||||
flyway:
|
||||
# Force Flyway to be enabled
|
||||
enabled: true
|
||||
|
||||
Reference in new issue
Block a user