-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor security token handling and update logging configs. #deploy-…
…idporten-frontend Simplified and unified authentication token handling across reactive security classes. Adjusted logging configurations for better stack trace management. Enabled Playwright job in GitHub workflow.
- Loading branch information
Showing
6 changed files
with
56 additions
and
65 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
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
22 changes: 3 additions & 19 deletions
22
...ctive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/JwtResolver.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 |
---|---|---|
@@ -1,35 +1,19 @@ | ||
package no.nav.testnav.libs.reactivesecurity.action; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.authentication.CredentialsExpiredException; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.ReactiveSecurityContextHolder; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.oauth2.jwt.Jwt; | ||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.time.Instant; | ||
import java.time.ZonedDateTime; | ||
|
||
@Slf4j | ||
@SuppressWarnings("java:S1610") | ||
abstract class JwtResolver { | ||
|
||
Mono<JwtAuthenticationToken> getJwtAuthenticationToken() { | ||
Mono<Authentication> getJwtAuthenticationToken() { | ||
return ReactiveSecurityContextHolder | ||
.getContext() | ||
.switchIfEmpty(Mono.error(new JwtResolverException("ReactiveSecurityContext is empty"))) | ||
.doOnNext(context -> log.info("JwtResolver context.authentication {} {}", context.getAuthentication().getClass().getCanonicalName(), context.getAuthentication())) | ||
.map(SecurityContext::getAuthentication) | ||
.map(JwtAuthenticationToken.class::cast) | ||
.doOnError(throwable -> log.warn("Klarte ikke hente Jwt Auth Token", throwable)) | ||
.doOnSuccess(jwtAuthenticationToken -> { | ||
Jwt credentials = (Jwt) jwtAuthenticationToken.getCredentials(); | ||
Instant expiresAt = credentials.getExpiresAt(); | ||
if (expiresAt == null || expiresAt.isBefore(ZonedDateTime.now().toInstant().plusSeconds(120))) { | ||
throw new CredentialsExpiredException("Jwt er utløpt eller utløper innen kort tid"); | ||
} | ||
}); | ||
.map(SecurityContext::getAuthentication); | ||
} | ||
|
||
} |