// Path: server/src/main/java/com/changeme/controller/utils/AuthenticationRequest.java
// public class AuthenticationRequest {
// 
//     private String username;
//     private String password;
// 
//     public AuthenticationRequest() {
//     }
// 
//     public AuthenticationRequest(String username, String password) {
//         this.username = username;
//         this.password = password;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// }
// 
// Path: server/src/main/java/com/changeme/controller/utils/AuthenticationResponse.java
// public class AuthenticationResponse {
// 
//     private String token;
// 
//     public AuthenticationResponse() {
//     }
// 
//     public AuthenticationResponse(String token) {
//         this.token = token;
//     }
// 
//     public String getToken() {
//         return token;
//     }
// 
//     public void setToken(String token) {
//         this.token = token;
//     }
// }
// 
// Path: server/src/main/java/com/changeme/security/TokenUtils.java
// @Component
// public class TokenUtils {
//     @Value("${changeme.token.secret}")
//     private String secret;
//     @Value("${changeme.token.expiration}")
//     private long expiration;
// 
//     public String getUsernameFromToken(String token) {
//         String username;
//         try {
//             username = Jwts.parser()
//                     .setSigningKey(secret)
//                     .parseClaimsJws(token)
//                     .getBody()
//                     .getSubject();
//         } catch (Exception e) {
//             username = null;
//         }
//         return username;
//     }
// 
//     private Date getExpirationDate(String token) {
//         Date expiration;
//         try {
//             expiration = Jwts.parser()
//                     .setSigningKey(secret)
//                     .parseClaimsJws(token)
//                     .getBody()
//                     .getExpiration();
//         } catch (Exception e) {
//             expiration = null;
//         }
//         return expiration;
//     }
// 
//     public String generateToken(UserDetails userDetails) {
//         return Jwts.builder()
//                 .setSubject(userDetails.getUsername())
//                 .setExpiration(new Date(System.currentTimeMillis() + expiration * 1000))
//                 .signWith(SignatureAlgorithm.HS512, secret)
//                 .compact();
//     }
// 
//     public boolean validateToken(String token, UserDetails userDetails) {
//         final String username = getUsernameFromToken(token);
//         final Date expiration = getExpirationDate(token);
//         return username.equals(userDetails.getUsername()) &&
//                 expiration.after(new Date(System.currentTimeMillis()));
//     }
// 
// 
// }


import com.changeme.controller.utils.AuthenticationRequest;
import com.changeme.controller.utils.AuthenticationResponse;
import com.changeme.security.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
package com.changeme.controller;


@RestController
@RequestMapping(path = "/public")
public class AuthenticationController {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Autowired
    private TokenUtils tokenUtils;

    @Autowired
    private UserDetailsService userDetailsService;

    @RequestMapping(method = RequestMethod.POST, value = "/auth")
// Path: server/src/main/java/com/changeme/controller/utils/AuthenticationRequest.java
// public class AuthenticationRequest {
// 
//     private String username;
//     private String password;
// 
//     public AuthenticationRequest() {
//     }
// 
//     public AuthenticationRequest(String username, String password) {
//         this.username = username;
//         this.password = password;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// }
// 
// Path: server/src/main/java/com/changeme/controller/utils/AuthenticationResponse.java
// public class AuthenticationResponse {
// 
//     private String token;
// 
//     public AuthenticationResponse() {
//     }
// 
//     public AuthenticationResponse(String token) {
//         this.token = token;
//     }
// 
//     public String getToken() {
//         return token;
//     }
// 
//     public void setToken(String token) {
//         this.token = token;
//     }
// }
// 
// Path: server/src/main/java/com/changeme/security/TokenUtils.java
// @Component
// public class TokenUtils {
//     @Value("${changeme.token.secret}")
//     private String secret;
//     @Value("${changeme.token.expiration}")
//     private long expiration;
// 
//     public String getUsernameFromToken(String token) {
//         String username;
//         try {
//             username = Jwts.parser()
//                     .setSigningKey(secret)
//                     .parseClaimsJws(token)
//                     .getBody()
//                     .getSubject();
//         } catch (Exception e) {
//             username = null;
//         }
//         return username;
//     }
// 
//     private Date getExpirationDate(String token) {
//         Date expiration;
//         try {
//             expiration = Jwts.parser()
//                     .setSigningKey(secret)
//                     .parseClaimsJws(token)
//                     .getBody()
//                     .getExpiration();
//         } catch (Exception e) {
//             expiration = null;
//         }
//         return expiration;
//     }
// 
//     public String generateToken(UserDetails userDetails) {
//         return Jwts.builder()
//                 .setSubject(userDetails.getUsername())
//                 .setExpiration(new Date(System.currentTimeMillis() + expiration * 1000))
//                 .signWith(SignatureAlgorithm.HS512, secret)
//                 .compact();
//     }
// 
//     public boolean validateToken(String token, UserDetails userDetails) {
//         final String username = getUsernameFromToken(token);
//         final Date expiration = getExpirationDate(token);
//         return username.equals(userDetails.getUsername()) &&
//                 expiration.after(new Date(System.currentTimeMillis()));
//     }
// 
// 
// }


// Path: server/src/main/java/com/changeme/controller/AuthenticationController.java
import com.changeme.controller.utils.AuthenticationRequest;
import com.changeme.controller.utils.AuthenticationResponse;
import com.changeme.security.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

package com.changeme.controller;


@RestController
@RequestMapping(path = "/public")
public class AuthenticationController {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Autowired
    private TokenUtils tokenUtils;

    @Autowired
    private UserDetailsService userDetailsService;

    @RequestMapping(method = RequestMethod.POST, value = "/auth")
    public ResponseEntity<?> authenticationRequest(@RequestBody AuthenticationRequest authenticationRequest)