36
36
import javax .servlet .http .HttpServletRequest ;
37
37
import javax .servlet .http .HttpServletResponse ;
38
38
39
+ import org .eclipse .jetty .http .HttpHeader ;
39
40
import org .jose4j .jwt .JwtClaims ;
40
41
import org .slf4j .Logger ;
41
42
import org .slf4j .LoggerFactory ;
@@ -184,7 +185,7 @@ protected AuthStatus oidcLogin(MessageInfo messageInfo, Subject clientSubject, H
184
185
return FAILURE ;
185
186
}
186
187
if (OpenIDProvider .ISSO .equals (configuration .get ().type ())) {
187
- LOG . info ( "OPENAM incoming openam, target {}" , request . getRequestURL (). toString () );
188
+ loggOpenAm ( request , " incoming openam" );
188
189
}
189
190
190
191
var expiresAt = claims .map (JwtUtil ::getExpirationTime ).orElseGet (() -> Instant .now ().plusSeconds (300 ));
@@ -212,7 +213,6 @@ protected AuthStatus oidcLogin(MessageInfo messageInfo, Subject clientSubject, H
212
213
private Optional <OpenIDToken > refreshCookieTokenVedBehov (HttpServletRequest request , OpenIDToken token , JwtClaims claims ) {
213
214
if (OpenIDProvider .ISSO .equals (token .provider ()) && openAmTokenProvider .isOpenAmTokenSoonExpired (token ) && tokenLocator .isTokenFromCookie (request )
214
215
&& Set .of (OidcLogin .LoginResult .SUCCESS , OidcLogin .LoginResult .ID_TOKEN_EXPIRED ).contains (OidcLogin .validerToken (token ).loginResult ())) {
215
- LOG .info ("OPENAM refresh token" );
216
216
return openAmTokenProvider .refreshOpenAmIdToken (token , Optional .ofNullable (claims ).map (JwtUtil ::getClientName ).orElse (null ));
217
217
}
218
218
return Optional .empty ();
@@ -309,7 +309,7 @@ protected AuthStatus responseUnAuthorized(MessageInfo messageInfo) {
309
309
|| (authorizationHeader != null && authorizationHeader .startsWith (OpenIDToken .OIDC_DEFAULT_TOKEN_TYPE ))) {
310
310
response .sendError (HttpServletResponse .SC_UNAUTHORIZED , "Resource is protected, but id token is missing or invalid." );
311
311
} else {
312
- LOG . info ( "OPENAM redirect login pga tom header, target {}" , request . getRequestURL (). toString () );
312
+ loggOpenAm ( request , " redirect login pga tom header" );
313
313
IssoAuthorizationRequestBuilder builder = new IssoAuthorizationRequestBuilder ();
314
314
// TODO (u139158): CSRF attack protection. See RFC-6749 section 10.12 (the
315
315
// state-cookie containing redirectURL shold be encrypted to avoid tampering)
@@ -323,6 +323,12 @@ protected AuthStatus responseUnAuthorized(MessageInfo messageInfo) {
323
323
return SEND_CONTINUE ;
324
324
}
325
325
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
+
326
332
private String encode (String redirectLocation ) {
327
333
return URLEncoder .encode (redirectLocation , StandardCharsets .UTF_8 );
328
334
}
0 commit comments