Merge branch '71-login-doesn-t-work-anymore-since-user-projection' into 'master'
Resolve "Login doesn't work anymore since user projection" Closes #71 See merge request marcel.schwarz/2020ss-qbc-geofence-timetracking!44
This commit is contained in:
commit
ad0d279b82
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
16
backend/src/main/java/de/hft/geotime/security/LoginUser.java
Normal file
16
backend/src/main/java/de/hft/geotime/security/LoginUser.java
Normal file
@ -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;
|
||||
|
||||
}
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user