diff --git a/backend/src/main/java/de/hft/geotime/security/JWTAuthenticationFilter.java b/backend/src/main/java/de/hft/geotime/security/JWTAuthenticationFilter.java index f111c1f..7ca7442 100644 --- a/backend/src/main/java/de/hft/geotime/security/JWTAuthenticationFilter.java +++ b/backend/src/main/java/de/hft/geotime/security/JWTAuthenticationFilter.java @@ -2,7 +2,6 @@ package de.hft.geotime.security; import com.auth0.jwt.JWT; import com.fasterxml.jackson.databind.ObjectMapper; -import de.hft.geotime.user.TimetrackUser; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; @@ -32,7 +31,7 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte HttpServletRequest req, HttpServletResponse res) throws AuthenticationException { try { - TimetrackUser creds = new ObjectMapper().readValue(req.getInputStream(), TimetrackUser.class); + LoginUser creds = new ObjectMapper().readValue(req.getInputStream(), LoginUser.class); return authenticationManager.authenticate( new UsernamePasswordAuthenticationToken( creds.getUsername(), @@ -41,7 +40,9 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte ) ); } catch (IOException e) { - throw new RuntimeException(e); + logger.info("Unsuccessful login attempt: " + e.getMessage()); + res.setStatus(HttpServletResponse.SC_FORBIDDEN); + return null; } } diff --git a/backend/src/main/java/de/hft/geotime/security/LoginUser.java b/backend/src/main/java/de/hft/geotime/security/LoginUser.java new file mode 100644 index 0000000..13a0bb6 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/security/LoginUser.java @@ -0,0 +1,16 @@ +package de.hft.geotime.security; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class LoginUser { + + private String password; + private String username; + +} diff --git a/backend/src/main/java/de/hft/geotime/user/UserController.java b/backend/src/main/java/de/hft/geotime/user/UserController.java index 723dde1..0bb15d6 100644 --- a/backend/src/main/java/de/hft/geotime/user/UserController.java +++ b/backend/src/main/java/de/hft/geotime/user/UserController.java @@ -4,7 +4,10 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; @RestController public class UserController {