-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/MatejFrnka/sportsmatch i…
…nto SMA-21_Add_endpoint_that_returns_all_sports
- Loading branch information
Showing
15 changed files
with
211 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
backend/sportsmatch/src/main/java/com/sportsmatch/auth/LogoutService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.sportsmatch.auth; | ||
|
||
import com.sportsmatch.models.Token; | ||
import com.sportsmatch.models.TokenType; | ||
import com.sportsmatch.models.User; | ||
import com.sportsmatch.repositories.TokenRepository; | ||
import com.sportsmatch.repositories.UserRepository; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.authentication.logout.LogoutHandler; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LogoutService implements LogoutHandler { | ||
|
||
private final JwtAuthFilter authFilter; | ||
private final TokenRepository tokenRepository; | ||
private final UserRepository userRepository; | ||
private final JwtService jwtService; | ||
|
||
@Override | ||
public void logout( | ||
HttpServletRequest request, HttpServletResponse response, Authentication authentication) { | ||
|
||
final String authHeader = request.getHeader("Authorization"); | ||
final String jwt = authHeader.substring(7); | ||
final String userEmail = jwtService.extractUserName(jwt); | ||
Optional<User> user = userRepository.findByEmail(userEmail); | ||
|
||
if (authFilter.isBearerTokenNotPresent(authHeader) || user.isEmpty()) { | ||
return; | ||
} | ||
|
||
tokenRepository.save( | ||
Token.builder() | ||
.token(jwt) | ||
.user(user.get()) | ||
.tokenType(TokenType.BEARER) | ||
.isValid(false) | ||
.build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
backend/sportsmatch/src/main/java/com/sportsmatch/configs/OpenApiConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.sportsmatch.configs; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn; | ||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; | ||
import io.swagger.v3.oas.annotations.info.Contact; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.security.SecurityScheme; | ||
import io.swagger.v3.oas.annotations.servers.Server; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@OpenAPIDefinition( | ||
info = | ||
@Info( | ||
contact = | ||
@Contact( | ||
name = "Sportsmingle", | ||
email = "[email protected]", | ||
url = "sportsmingle.com"), | ||
description = "Sport event scheduling and matchmaking", | ||
title = "Sportsmingle", | ||
version = "v1"), | ||
servers = {@Server(description = "Local ENV", url = "http://localhost:8080")}, | ||
security = {@SecurityRequirement(name = "bearerAuth")}) | ||
@SecurityScheme( | ||
name = "bearerAuth", | ||
description = "JWT auth description", | ||
scheme = "bearer", | ||
type = SecuritySchemeType.HTTP, | ||
bearerFormat = "JWT", | ||
in = SecuritySchemeIn.HEADER) | ||
public class OpenApiConfig {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.