Clean security code
This commit is contained in:
@@ -62,7 +62,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||
response.setContentType("application/json");
|
||||
|
||||
ErrorResponse errorResponse = new ErrorResponse("Your session has expired. Refresh your token.");
|
||||
ObjectMapper objectMapper = new ObjectMapper(); // You may need to import ObjectMapper
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
response.getWriter().write(objectMapper.writeValueAsString(errorResponse));
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ public class JwtService {
|
||||
private long jwtExpiration;
|
||||
@Value("${application.security.jwt.refresh-token.expiration}")
|
||||
private long refreshExpiration;
|
||||
// private final AuthenticationService authenticationService;
|
||||
|
||||
|
||||
public String extractUsername(String token) {
|
||||
|
||||
@@ -45,22 +45,9 @@ public class SecurityConfiguration {
|
||||
.cors(Customizer.withDefaults())
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
// .requestMatchers("/api/v1/auth/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.oauth2Login(withDefaults());
|
||||
// .exceptionHandling(exceptionHandling ->
|
||||
// exceptionHandling
|
||||
// .authenticationEntryPoint(authenticationEntryPoint())
|
||||
// )
|
||||
// .oauth2Login(oauth2Login ->
|
||||
// oauth2Login
|
||||
// .loginPage("/login")
|
||||
// .clientRegistrationRepository(clientRegistrationRepository)
|
||||
// .userInfoEndpoint(userInfoEndpoint ->
|
||||
// userInfoEndpoint.userService(oAuth2UserService())
|
||||
// )
|
||||
// .successHandler(jwtAuthenticationSuccessHandler()));
|
||||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@@ -71,16 +71,15 @@ public class AuthenticationService {
|
||||
.build();
|
||||
}
|
||||
|
||||
// Extract user details from OAuth2User
|
||||
|
||||
String givenName = oAuth2User.getAttribute("given_name");
|
||||
String familyName = oAuth2User.getAttribute("family_name");
|
||||
String email = oAuth2User.getAttribute("email");
|
||||
|
||||
// Create a new User entity and save it to the database
|
||||
User user = User.builder()
|
||||
.firstName(givenName)
|
||||
.lastName(familyName)
|
||||
.username(email) // You can adjust the username as needed
|
||||
.username(email)
|
||||
.build();
|
||||
|
||||
String randomPassword = passwordGenerator.generateRandomPassword(8);
|
||||
@@ -98,7 +97,6 @@ public class AuthenticationService {
|
||||
System.out.println("New user: " + user);
|
||||
System.out.println("New credentials: " + credential);
|
||||
|
||||
// Return the registered user's authentication response
|
||||
return AuthenticationResponse.builder()
|
||||
.accessToken(jwtToken)
|
||||
.refreshToken(refreshToken)
|
||||
|
||||
Reference in New Issue
Block a user