Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3667f1f
update User.toXContent() to create array of attributes as key=value f…
markdboyd Sep 22, 2025
f0f0b03
update testUserXContentIncludesCustomAttributes to test for correct s…
markdboyd Sep 22, 2025
08265dc
update User.parse() for XContent to parse the custom attribute names …
markdboyd Sep 22, 2025
3c5214a
update test to validate that custom_attribute_names are set properly
markdboyd Sep 22, 2025
e18bf52
update User.toXContent() to remove custom_attributes property
markdboyd Sep 22, 2025
6a92d54
update test of User.toXContent() to verify that custom_attributes is …
markdboyd Sep 22, 2025
60b3279
apply spotless formatting
markdboyd Sep 22, 2025
b3907db
update User.parse() for XContent to parse custom_attribute_names entr…
markdboyd Sep 22, 2025
a64b951
add tests for parsing of custom_attribute_names for User.parse() of X…
markdboyd Sep 22, 2025
0efdd9f
apply spotless formatting
markdboyd Sep 22, 2025
e53fbea
remove parsing of custom_attributes from XContent in User.parse() sin…
markdboyd Sep 22, 2025
58d1b3b
update test for User.parse() of XContent to remove custom attributes …
markdboyd Sep 22, 2025
75633d7
update User.toString() to include custom attribute names as list inst…
markdboyd Sep 22, 2025
3009510
apply spotless formatting
markdboyd Sep 22, 2025
8f75530
remove CUSTOM_ATTRIBUTES field on User
markdboyd Sep 22, 2025
74d2fb9
add javadoc to User.parse() for XContent
markdboyd Sep 22, 2025
1f1bedb
update User.parse() to throw IOException when custom_attribute_names …
markdboyd Sep 22, 2025
0b411af
refactor logic for getting parsing user attribute info from custom_at…
markdboyd Sep 22, 2025
730d50d
remove duplicate logic
markdboyd Sep 22, 2025
73dbe1b
update User.parseAttributeInfoFromCustomAttributeName to throw Illega…
markdboyd Sep 22, 2025
ccfddde
update thrown exceptions for User.parse() of string
markdboyd Sep 22, 2025
fd273cd
remove unnecessary throws declarations
markdboyd Sep 23, 2025
2e2979e
remove more unnecessary throws declarations
markdboyd Sep 23, 2025
1749759
update test to use a java text block
markdboyd Sep 23, 2025
da33e93
apply spotless formatting
markdboyd Sep 23, 2025
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
11 changes: 8 additions & 3 deletions src/main/java/org/opensearch/commons/authuser/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ public static User parse(XContentParser parser) throws IOException {
case CUSTOM_ATTRIBUTE_NAMES_FIELD:
ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser);
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
customAttributes.put(parser.text(), null);
// Assume custom attribute name values are key=value with no extra "="
String[] attrInfo = parser.text().split("=");
customAttributes.put(attrInfo[0], attrInfo[1]);
}
break;
case REQUESTED_TENANT_FIELD:
Expand Down Expand Up @@ -283,7 +285,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
.field(REQUESTED_TENANT_ACCESS, requestedTenantAccess);

if (customAttributes.size() > 0) {
builder.field(CUSTOM_ATTRIBUTES_FIELD, customAttributes);
builder.field(CUSTOM_ATTRIBUTE_NAMES_FIELD, this.getCustomAttributeNamesFromMap(customAttributes));
} else {
builder.field(CUSTOM_ATTRIBUTE_NAMES_FIELD, new ArrayList<>());
}
Expand Down Expand Up @@ -379,7 +381,10 @@ private Map<String, String> convertCustomAttributeNamesToMap(List<String> custom
}

private List<String> getCustomAttributeNamesFromMap(Map<String, String> customAttributes) {
List<String> customAttNames = new ArrayList<>(this.customAttributes.keySet());
List<String> customAttNames = new ArrayList<>();
for (Map.Entry<String, String> entry : this.customAttributes.entrySet()) {
customAttNames.add(entry.getKey() + "=" + entry.getValue());
}
return customAttNames;
}
}
8 changes: 5 additions & 3 deletions src/test/java/org/opensearch/commons/authuser/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -474,6 +475,7 @@ public void testParseUserXContent() throws IOException {
assertEquals(1, user.getCustomAttributes().size());
assertTrue(user.getCustomAttributes().containsKey("attr1"));
assertTrue(user.getCustomAttributes().containsValue("val1"));
assertEquals(user.getCustomAttNames(), Arrays.asList("attr1=val1"));
}

@Test
Expand Down Expand Up @@ -541,9 +543,9 @@ public void testUserXContentIncludesCustomAttributes() throws IOException {
"roles": ["ops_data"],
"user_requested_tenant": null,
"user_requested_tenant_access": null,
"custom_attributes": {
"attr1": "value1"
}
"custom_attribute_names": [
"attr1=value1"
]
}
""";
assertEquals(expectedUserJson.replace("\n", "").replace("\s", ""), xcontent.toString().replace("\n", ""));
Expand Down
Loading