Security branch #38

Merged
DmitriiKaban merged 6 commits from security_branch into master 2023-11-27 06:30:52 +00:00
4 changed files with 3 additions and 19 deletions
Showing only changes of commit fddd02b9ce - Show all commits

View File

@@ -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));

View File

@@ -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) {

View File

@@ -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();
}

View File

@@ -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)