Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/131173.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 131173
summary: Add attribute count to `SamlAttribute` `toString`
area: Authentication
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ static class SamlAttribute {

@Override
public String toString() {
StringBuilder str = new StringBuilder();
if (Strings.isNullOrEmpty(friendlyName)) {
return name + '=' + values;
str.append(name);
} else {
return friendlyName + '(' + name + ")=" + values;
str.append(friendlyName).append('(').append(name).append(')');
}
str.append("=").append(values).append("(len=").append(values.size()).append(')');
return str.toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.security.authc.saml;

import org.hamcrest.Matchers;
import org.opensaml.saml.saml2.core.NameID;

import java.util.List;

public class SamlAttributesTests extends SamlTestCase {

public void testToString() {
final String nameFormat = randomFrom(NameID.TRANSIENT, NameID.PERSISTENT, NameID.EMAIL);
final String nameId = randomIdentifier();
final String session = randomAlphaOfLength(16);
final SamlAttributes attributes = new SamlAttributes(
new SamlNameId(nameFormat, nameId, null, null, null),
session,
List.of(
new SamlAttributes.SamlAttribute("urn:oid:0.9.2342.19200300.100.1.1", null, List.of("peter.ng")),
new SamlAttributes.SamlAttribute("urn:oid:2.5.4.3", "name", List.of("Peter Ng")),
new SamlAttributes.SamlAttribute(
"urn:oid:1.3.6.1.4.1.5923.1.5.1.1",
"groups",
List.of("employees", "engineering", "managers")
)
)
);
assertThat(
attributes.toString(),
Matchers.equalTo(
"SamlAttributes("
+ ("NameId(" + nameFormat + ")=" + nameId)
+ ")["
+ session
+ "]{["
+ "urn:oid:0.9.2342.19200300.100.1.1=[peter.ng](len=1)"
+ ", "
+ "name(urn:oid:2.5.4.3)=[Peter Ng](len=1)"
+ ", "
+ "groups(urn:oid:1.3.6.1.4.1.5923.1.5.1.1)=[employees, engineering, managers](len=3)"
+ "]}"
)
);
}

}
Loading