|
|
@@ -45,10 +45,6 @@ public class JwtAuthenticationController { |
|
|
|
@Qualifier("AuthenticationManager") |
|
|
|
private AuthenticationManager authenticationManager; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Qualifier("LdapAuthenticationManager") |
|
|
|
private AuthenticationManager ldapAuthenticationManager; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private JwtTokenUtil jwtTokenUtil; |
|
|
|
|
|
|
@@ -80,30 +76,11 @@ public class JwtAuthenticationController { |
|
|
|
return createAuthTokenResponse(authenticationRequest); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/ldap-login") |
|
|
|
public ResponseEntity<?> ldapLogin(@RequestBody JwtRequest authenticationRequest, HttpServletRequest request) throws Exception { |
|
|
|
String username = authenticationRequest.getUsername(); |
|
|
|
try { |
|
|
|
boolean success = ldapAuthenticate(authenticationRequest.getUsername(), authenticationRequest.getPassword()); |
|
|
|
loginLogService.createLoginLog(username, request.getRemoteAddr(), success); |
|
|
|
} catch (Exception e) { |
|
|
|
loginLogService.createLoginLog(username, request.getRemoteAddr(), false); |
|
|
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED) |
|
|
|
.body(new ExceptionResponse("Unauthorized", ExceptionUtils.getStackTrace(e))); |
|
|
|
} |
|
|
|
return createAuthTokenResponse(authenticationRequest); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean authenticate(String username, String password) throws Exception { |
|
|
|
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password)); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean ldapAuthenticate(String username, String password) throws Exception { |
|
|
|
ldapAuthenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password)); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private ResponseEntity<?> createAuthTokenResponse(JwtRequest authenticationRequest) { |
|
|
|
final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername()); |
|
|
|
if (userDetails == null) { |
|
|
|