Skip to content

Commit f5ff8b1

Browse files
update formatIssuer to describeIssuer
1 parent 7de3149 commit f5ff8b1

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlObjectHandler.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected static String describe(Collection<X509Credential> credentials) {
161161
return credentials.stream().map(credential -> describe(credential.getEntityCertificate())).collect(Collectors.joining(","));
162162
}
163163

164-
void validateSignature(Signature signature, Issuer issuer) {
164+
void validateSignature(Signature signature, @Nullable Issuer issuer) {
165165
final String signatureText = text(signature, 32);
166166
SAMLSignatureProfileValidator profileValidator = new SAMLSignatureProfileValidator();
167167
try {
@@ -200,7 +200,7 @@ void validateSignature(Signature signature, Issuer issuer) {
200200
);
201201
return true;
202202
} catch (PrivilegedActionException e) {
203-
logger.warn("SecurityException while attempting to validate SAML signature" + formatIssuer(issuer), e);
203+
logger.warn("SecurityException while attempting to validate SAML signature." + describeIssuer(issuer), e);
204204
return false;
205205
}
206206
});
@@ -214,7 +214,7 @@ void validateSignature(Signature signature, Issuer issuer) {
214214
* Tests whether the provided function returns {@code true} for any of the IdP's signing credentials.
215215
* @throws ElasticsearchSecurityException - A SAML exception if no matching credential is found.
216216
*/
217-
protected void checkIdpSignature(CheckedFunction<Credential, Boolean, Exception> check, String signatureText, Issuer issuer) {
217+
protected void checkIdpSignature(CheckedFunction<Credential, Boolean, Exception> check, String signatureText, @Nullable Issuer issuer) {
218218
final Predicate<Credential> predicate = credential -> {
219219
try {
220220
return check.apply(credential);
@@ -231,7 +231,7 @@ protected void checkIdpSignature(CheckedFunction<Credential, Boolean, Exception>
231231
logger.trace("SAML Signature failure caused by", e);
232232
return false;
233233
} catch (Exception e) {
234-
logger.warn("Exception while attempting to validate SAML Signature" + formatIssuer(issuer), e);
234+
logger.warn("Exception while attempting to validate SAML Signature." + describeIssuer(issuer), e);
235235
return false;
236236
}
237237
};
@@ -245,15 +245,15 @@ protected void checkIdpSignature(CheckedFunction<Credential, Boolean, Exception>
245245
* Constructs a SAML specific exception with a consistent message regarding SAML Signature validation failures
246246
*/
247247
private ElasticsearchSecurityException samlSignatureException(
248-
Issuer issuer,
248+
@Nullable Issuer issuer,
249249
List<Credential> credentials,
250250
String signature,
251251
Exception cause
252252
) {
253253
logger.warn(
254254
"The XML Signature of this SAML message cannot be validated. Please verify that the saml realm uses the correct SAML "
255-
+ "metadata file/URL for this Identity Provider{}",
256-
formatIssuer(issuer)
255+
+ "metadata file/URL for this Identity Provider.{}",
256+
describeIssuer(issuer)
257257
);
258258
final String msg = "SAML Signature [{}] could not be validated against [{}]";
259259
if (cause != null) {
@@ -267,8 +267,8 @@ private ElasticsearchSecurityException samlSignatureException(Issuer issuer, Lis
267267
return samlSignatureException(issuer, credentials, signature, null);
268268
}
269269

270-
private String formatIssuer(Issuer issuer) {
271-
return issuer != null ? Strings.format(" [%s]", issuer.getValue()) : "";
270+
private String describeIssuer(@Nullable Issuer issuer) {
271+
return issuer != null ? Strings.format(" The issuer included in the SAML message was [%s]", issuer.getValue()) : "";
272272
}
273273

274274
private static String describeCredentials(List<Credential> credentials) {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public class SamlAuthenticatorTests extends SamlResponseHandlerTests {
107107
+ "Change your IdP configuration to use a different attribute *"
108108
+ " that will not clash with any of [*]";
109109
private static final String SIGNATURE_VALIDATION_FAILED_LOG_MESSAGE = "The XML Signature of this SAML message cannot be validated. "
110-
+ "Please verify that the saml realm uses the correct SAML metadata file/URL for this Identity Provider "
111-
+ "[https://idp.saml.elastic.test/]";
110+
+ "Please verify that the saml realm uses the correct SAML metadata file/URL for this Identity Provider. "
111+
+ "The issuer included in the SAML message was [https://idp.saml.elastic.test/]";
112112

113113
private SamlAuthenticator authenticator;
114114

@@ -1356,7 +1356,8 @@ public void testFailureWhenIdPCredentialsAreNull() throws Exception {
13561356
"Null credentials",
13571357
authenticator.getClass().getName(),
13581358
Level.WARN,
1359-
"Exception while attempting to validate SAML Signature [https://idp.saml.elastic.test/]"
1359+
"Exception while attempting to validate SAML Signature. " +
1360+
"The issuer included in the SAML message was [https://idp.saml.elastic.test/]"
13601361
)
13611362
);
13621363

0 commit comments

Comments
 (0)