Skip to content
This repository was archived by the owner on Nov 29, 2022. It is now read-only.

Commit da94a09

Browse files
committed
Surround debug statements with checks to see if debug logging is enabled
#436 (comment)
1 parent 44ad0f6 commit da94a09

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

samples/service-provider/starter/src/main/java/org/springframework/security/saml2/serviceprovider/authentication/Saml2AuthenticationProvider.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ private Assertion validateSaml2Response(Saml2ServiceProviderRegistration sp, Str
157157
}
158158

159159
final String issuer = samlResponse.getIssuer().getValue();
160-
logger.debug("Processing SAML response from " + issuer);
160+
if (logger.isDebugEnabled()) {
161+
logger.debug("Processing SAML response from " + issuer);
162+
}
161163
final Saml2IdentityProviderDetails idp = serviceProviderRepository
162164
.getIdentityProviders(sp.getEntityId())
163165
.getIdentityProviderById(issuer);
@@ -211,7 +213,9 @@ private boolean isValidAssertion(Saml2ServiceProviderRegistration sp, String rec
211213
}
212214

213215
if (signatureRequired && !hasValidSignature(a, idp)) {
214-
logger.debug(format("Assertion [%s] does not a valid signature.", a.getID()));
216+
if (logger.isDebugEnabled()) {
217+
logger.debug(format("Assertion [%s] does not a valid signature.", a.getID()));
218+
}
215219
return false;
216220
}
217221
a.setSignature(null);
@@ -222,13 +226,18 @@ private boolean isValidAssertion(Saml2ServiceProviderRegistration sp, String rec
222226
final ValidationResult result = validator.validate(a, vctx);
223227
final boolean valid = result.equals(ValidationResult.VALID);
224228
if (!valid) {
225-
logger.debug(format("Failed to validate assertion from %s with user %s", idp.getEntityId(),
226-
getUsername(sp, a)));
229+
if (logger.isDebugEnabled()) {
230+
logger.debug(format("Failed to validate assertion from %s with user %s", idp.getEntityId(),
231+
getUsername(sp, a)
232+
));
233+
}
227234
}
228235
return valid;
229236
}
230237
catch (AssertionValidationException e) {
231-
logger.debug("Failed to validate assertion:", e);
238+
if (logger.isDebugEnabled()) {
239+
logger.debug("Failed to validate assertion:", e);
240+
}
232241
return false;
233242
}
234243

samples/service-provider/starter/src/main/java/org/springframework/security/saml2/serviceprovider/servlet/filter/Saml2AuthenticationFailureHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public Saml2AuthenticationFailureHandler() {
4444
@Override
4545
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
4646
AuthenticationException exception) throws IOException, ServletException {
47-
logger.debug("Processing SAML2 Authentication Exception", exception);
47+
if (logger.isDebugEnabled()) {
48+
logger.debug("Processing SAML2 Authentication Exception", exception);
49+
}
4850
sendHtmlBody(response, errorHtml(Collections.singletonList(exception.getMessage())));
4951
}
5052

samples/service-provider/starter/src/main/java/org/springframework/security/saml2/serviceprovider/servlet/filter/Saml2AuthenticationRequestFilter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ private void sendAuthenticationRequest(HttpServletRequest request,
6868
HttpServletResponse response) throws IOException {
6969
String relayState = request.getParameter("RelayState");
7070
String alias = getIdpAlias(request);
71-
logger.debug("Creating SAML2 SP Authentication Request for IDP["+alias+"]");
71+
if (logger.isDebugEnabled()) {
72+
logger.debug("Creating SAML2 SP Authentication Request for IDP[" + alias + "]");
73+
}
7274
Assert.hasText(alias, "IDP Alias must be present and valid");
7375
Saml2ServiceProviderRegistration sp = serviceProviderRepository.getServiceProvider(getBasePath(request, false));
7476
Saml2IdentityProviderDetails idp = getIdentityProvider(sp, alias);
@@ -81,7 +83,9 @@ private void sendAuthenticationRequest(HttpServletRequest request,
8183
.build(true)
8284
.toUriString();
8385
response.sendRedirect(redirect);
84-
logger.debug("SAML2 SP Authentication Request Sent to Browser");
86+
if (logger.isDebugEnabled()) {
87+
logger.debug("SAML2 SP Authentication Request Sent to Browser");
88+
}
8589

8690
}
8791

0 commit comments

Comments
 (0)