Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow data containing groups from SSO server to be a List of Maps in addition to a List of Strings. #198

Merged
merged 5 commits into from
Feb 18, 2023

Conversation

bsmoyers
Copy link
Contributor

Allow data containing groups from SSO server to be a List of Maps in addition to a List of Strings. In cases where groups is a List of Maps, give option to specify which key in the Map holds the group name, defaulting to a key "name".

Oracle IDCS is the product we needed to integrate with in this case. I don't currently know if any other providers need this change.

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

addition to a List of Strings. In cases where groups is a List of Maps, give option to specify which key in the Map holds the group name, defaulting to a key "name"
@bsmoyers
Copy link
Contributor Author

[michael-doubez] I missed your comment on my older PR. I reconciled my change with the latest changes this week so that I could continue using my forked version. If you still think this is not the right approach, I understand. I am willing to retry using a different method if you prefer. Thanks.

@codecov
Copy link

codecov bot commented Jan 27, 2023

Codecov Report

Merging #198 (cfb0ab2) into master (f9571ad) will decrease coverage by 0.67%.
The diff coverage is 70.27%.

@@             Coverage Diff              @@
##             master     #198      +/-   ##
============================================
- Coverage     73.27%   72.61%   -0.67%     
- Complexity      182      186       +4     
============================================
  Files             9        9              
  Lines           696      723      +27     
  Branches        110      120      +10     
============================================
+ Hits            510      525      +15     
- Misses          132      140       +8     
- Partials         54       58       +4     
Impacted Files Coverage Δ
...va/org/jenkinsci/plugins/oic/OicSecurityRealm.java 68.99% <70.27%> (-0.69%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@michael-doubez
Copy link
Contributor

@bsmoyers Thank you for your the PR.

I had initially planned to use JMESPath (see #149) but at his time, I have not found a suitable java library for that so I guess we can at least stay somewhat compatible with it.

Instead of introducing yet-another-parameter, I'd rather implement it in the JMESPath way:

path.to.array[].nested.field

I expect, your current additional parameter can be generated by splitting the current group name with this specific syntax.
Better would be to recursively handling multiple [] but a single [] is acceptable IMHO.

If you think I am asking for too much, I am willing to contribute on your PR.

@michael-doubez michael-doubez linked an issue Jan 30, 2023 that may be closed by this pull request
@bsmoyers
Copy link
Contributor Author

@michael-doubez Thanks for the update. That sounds fine with me, and it will make it much simpler to not add the additional field. Can you confirm that you want the existing group field to handle a top level groups field "groups" with a nested field "name" would be input in the text box as "groups[].name"

@michael-doubez
Copy link
Contributor

Yes. That would be be fine.
Let keep it simple.

If people need it we 'll be able to improve on that and not break the format.

… nested group field name for case where SSO server returns groups as an array of maps.
Copy link
Contributor

@michael-doubez michael-doubez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move parsing in setter

@@ -136,6 +137,7 @@ public static enum TokenAuthMethod { client_secret_basic, client_secret_post };
private String fullNameFieldName = null;
private String emailFieldName = null;
private String groupsFieldName = null;
private String nestedGroupFieldName = "name";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the parsing of groupsFieldName in the setter (setGroupsFieldName) and use transient variables to be used latter on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in latest changes

// if groupsFieldName contains []., then groupsFieldName
// is first portion, and nestedGroupFieldName is
// second portion
String[] parts = groupsFieldName.split("\\[\\]\\.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use limit to limit splitting to 2 String[] split(String regex, int limit) - granted there should be only one and warning should be generated if format is not correct.

Note: a method doCheckGroupsFieldName should be added to check field format for GUI users.
If you don't do it, I'll make it is another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in latest changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added doCheckGroupsFieldName() to check format

// second portion
String[] parts = groupsFieldName.split("\\[\\]\\.");
// don't modify groupsFieldName
String localGroupsFieldName = parts.length > 1 ? parts[0] : groupsFieldName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no split, parts[0] will be the content of groupsFieldName, conditional is not required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in latest changes

String[] parts = groupsFieldName.split("\\[\\]\\.");
// don't modify groupsFieldName
String localGroupsFieldName = parts.length > 1 ? parts[0] : groupsFieldName;
nestedGroupFieldName = parts.length > 1 ? parts[1] : nestedGroupFieldName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nestedGroupField shoud be null if not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in latest changes

} else if (group instanceof ArrayMap) {
// if its a Map, we use the nestedGroupFieldName to grab the groups
Map<String, String> groupMap = (Map<String, String>) group;
if (groupMap.keySet().contains(nestedGroupFieldName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test nestedGroupFieldName not null (with new logic)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in latest changes

@bsmoyers
Copy link
Contributor Author

bsmoyers commented Feb 1, 2023

working on updating, may be a little while before I can get to it.

Copy link
Contributor

@michael-doubez michael-doubez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - don't bother about the small codecov gap

@michael-doubez michael-doubez merged commit ca69a2e into jenkinsci:master Feb 18, 2023
@michael-doubez
Copy link
Contributor

Thanks for the feature. I have scheduled a release in the coming week (or the week after).

@michael-doubez michael-doubez added this to the 2.6 milestone Feb 18, 2023
@bsmoyers
Copy link
Contributor Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use JMESPath for group fields
2 participants