Cleaned a little bit up

This commit is contained in:
lobo committed 2026-04-04 10:43:18 +02:00
1 parent 41ce5d93e9
commit 71e4f38357
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.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; 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.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
@@ -83,6 +84,7 @@ public class SecurityConfig {
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth .authorizeHttpRequests(auth -> auth
.requestMatchers(WHITE_LIST_URLS).permitAll() .requestMatchers(WHITE_LIST_URLS).permitAll()
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
) )
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class); .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
@@ -8,6 +8,6 @@ public abstract class ApiMapper {
} }
public static User toModel(LoginRequest loginRequest) { 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 { public class User {
private long id; private long id;
private String email; private String email;
private String encryptedPassword; private String password;
} }
@@ -14,7 +14,7 @@ public abstract class EntityMapper {
if (entity != null) { if (entity != null) {
model.setId(entity.getId()); model.setId(entity.getId());
model.setEmail(entity.getEmail()); model.setEmail(entity.getEmail());
model.setEncryptedPassword(entity.getPassword()); model.setPassword(entity.getPassword());
} }
return model; return model;
@@ -19,11 +19,8 @@ public class LoginService {
private final JwtService jwtService; private final JwtService jwtService;
public String login(User userToLogin) { public String login(User userToLogin) {
var userEntity = minimalUserRepository.findByEmail(userToLogin.getEmail()).orElseThrow(() -> new UserNotFoundException("User not found with given email")); var userFromDatabase = minimalUserRepository.findByEmail(userToLogin.getEmail()).orElseThrow(() -> new UserNotFoundException("User not found with given email"));
var loginSuccessful = passwordEncoder.matches(userToLogin.getPassword(), userFromDatabase.getPassword());
log.info("Login attempt for user {}", passwordEncoder.encode(userToLogin.getEncryptedPassword()) + " " + userEntity.getEncryptedPassword());
var loginSuccessful = passwordEncoder.matches(userToLogin.getEncryptedPassword(), userEntity.getEncryptedPassword());
if (!loginSuccessful) { if (!loginSuccessful) {
throw new InvalidCredentialsException("Invalid credentials"); throw new InvalidCredentialsException("Invalid credentials");
} }
+1 -1
View File
@@ -7,7 +7,7 @@ spring:
profiles: profiles:
active: dev # Default profile for local startup active: dev # Default profile for local startup
jpa: jpa:
open-in-view: false open-in-view: true
flyway: flyway:
# Force Flyway to be enabled # Force Flyway to be enabled
enabled: true enabled: true