Skip to content

Commit 6096117

Browse files
authored
Prøve logge origin + host (#1213)
1 parent 91dfc1e commit 6096117

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

felles/sikkerhet/src/main/java/no/nav/vedtak/sikkerhet/jaspic/OidcAuthModule.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import javax.servlet.http.HttpServletRequest;
3737
import javax.servlet.http.HttpServletResponse;
3838

39+
import org.eclipse.jetty.http.HttpHeader;
3940
import org.jose4j.jwt.JwtClaims;
4041
import org.slf4j.Logger;
4142
import org.slf4j.LoggerFactory;
@@ -184,7 +185,7 @@ protected AuthStatus oidcLogin(MessageInfo messageInfo, Subject clientSubject, H
184185
return FAILURE;
185186
}
186187
if (OpenIDProvider.ISSO.equals(configuration.get().type())) {
187-
LOG.info("OPENAM incoming openam, target {}", request.getRequestURL().toString());
188+
loggOpenAm(request, "incoming openam");
188189
}
189190

190191
var expiresAt = claims.map(JwtUtil::getExpirationTime).orElseGet(() -> Instant.now().plusSeconds(300));
@@ -212,7 +213,6 @@ protected AuthStatus oidcLogin(MessageInfo messageInfo, Subject clientSubject, H
212213
private Optional<OpenIDToken> refreshCookieTokenVedBehov(HttpServletRequest request, OpenIDToken token, JwtClaims claims) {
213214
if (OpenIDProvider.ISSO.equals(token.provider()) && openAmTokenProvider.isOpenAmTokenSoonExpired(token) && tokenLocator.isTokenFromCookie(request)
214215
&& Set.of(OidcLogin.LoginResult.SUCCESS, OidcLogin.LoginResult.ID_TOKEN_EXPIRED).contains(OidcLogin.validerToken(token).loginResult())) {
215-
LOG.info("OPENAM refresh token");
216216
return openAmTokenProvider.refreshOpenAmIdToken(token, Optional.ofNullable(claims).map(JwtUtil::getClientName).orElse(null));
217217
}
218218
return Optional.empty();
@@ -309,7 +309,7 @@ protected AuthStatus responseUnAuthorized(MessageInfo messageInfo) {
309309
|| (authorizationHeader != null && authorizationHeader.startsWith(OpenIDToken.OIDC_DEFAULT_TOKEN_TYPE))) {
310310
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Resource is protected, but id token is missing or invalid.");
311311
} else {
312-
LOG.info("OPENAM redirect login pga tom header, target {}", request.getRequestURL().toString());
312+
loggOpenAm(request, "redirect login pga tom header");
313313
IssoAuthorizationRequestBuilder builder = new IssoAuthorizationRequestBuilder();
314314
// TODO (u139158): CSRF attack protection. See RFC-6749 section 10.12 (the
315315
// state-cookie containing redirectURL shold be encrypted to avoid tampering)
@@ -323,6 +323,12 @@ protected AuthStatus responseUnAuthorized(MessageInfo messageInfo) {
323323
return SEND_CONTINUE;
324324
}
325325

326+
private void loggOpenAm(HttpServletRequest request, String message) {
327+
var origins = Optional.ofNullable(request.getHeader(HttpHeader.ORIGIN.asString())).orElse("")
328+
+ "host:" + Optional.ofNullable(request.getHeader(HttpHeader.HOST.asString())).orElse("");
329+
LOG.info("OPENAM {}, target {} origin {}", message, request.getRequestURL().toString(), origins);
330+
}
331+
326332
private String encode(String redirectLocation) {
327333
return URLEncoder.encode(redirectLocation, StandardCharsets.UTF_8);
328334
}

0 commit comments

Comments
 (0)