JENKINS-48900 - Show "Full Name" on Assign Roles page

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

JENKINS-48900 - Show "Full Name" on Assign Roles page

Tidhar Klein Orbach
Hi

I looked on https://issues.jenkins-ci.org/browse/JENKINS-48900 and the relevant code in role strategy plugin.

I have found that RoleMap uses org.acegisecurity.userdetails.UserDetails to get the user details.
I see that UserDetails interface has getUserName() which is used for the "sid" in the role-strategy-plugin. But there is no getDisaplyName  in the interface.
It does exist  in some of its implemented classes (for example ActiveDirectoryUserDetail)

any suggestions how to get the full name if exists?

thanks,
Tidhar

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/ecc3230d-118c-4c42-a7c8-cf98258bc2a4o%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: JENKINS-48900 - Show "Full Name" on Assign Roles page

Oleg Nenashev
Hi,

hudson.model.user.getById(String id, false).getFullName() would be the best approach.
It uses direct access to user profiles inside Jenkins. https://javadoc.jenkins-ci.org/hudson/model/User.html

Best regards,
Oleg

On Tuesday, July 14, 2020 at 2:21:12 PM UTC+2, Tidhar Klein Orbach wrote:
Hi

I looked on <a href="https://issues.jenkins-ci.org/browse/JENKINS-48900" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fissues.jenkins-ci.org%2Fbrowse%2FJENKINS-48900\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHkjC0WKqmQOdJoSdZKwyQ19sdp_w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fissues.jenkins-ci.org%2Fbrowse%2FJENKINS-48900\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHkjC0WKqmQOdJoSdZKwyQ19sdp_w&#39;;return true;">https://issues.jenkins-ci.org/browse/JENKINS-48900 and the relevant code in role strategy plugin.

I have found that <a href="https://github.com/jenkinsci/role-strategy-plugin/blob/master/src/main/java/com/michelin/cio/hudson/plugins/rolestrategy/RoleMap.java#L90" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Frole-strategy-plugin%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Fcom%2Fmichelin%2Fcio%2Fhudson%2Fplugins%2Frolestrategy%2FRoleMap.java%23L90\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH9_gY0y9Qv5HsPfdJp13BAvVENWg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Frole-strategy-plugin%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Fcom%2Fmichelin%2Fcio%2Fhudson%2Fplugins%2Frolestrategy%2FRoleMap.java%23L90\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH9_gY0y9Qv5HsPfdJp13BAvVENWg&#39;;return true;">RoleMap uses <a href="http://org.acegisecurity.userdetails.UserDetails" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.acegisecurity.userdetails.UserDetails\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHmqFutJnEA1JhcAgthT3H8L0SRzw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.acegisecurity.userdetails.UserDetails\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHmqFutJnEA1JhcAgthT3H8L0SRzw&#39;;return true;">org.acegisecurity.userdetails.UserDetails to get the user details.
I see that UserDetails interface has getUserName() which is used for the "sid" in the role-strategy-plugin. But there is no getDisaplyName  in the interface.
It does exist  in some of its implemented classes (for example ActiveDirectoryUserDetail)

any suggestions how to get the full name if exists?

thanks,
Tidhar

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/96aeb71a-c61a-4d8c-b977-d0c11e601634o%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: JENKINS-48900 - Show "Full Name" on Assign Roles page

Jesse Glick-4
On Wed, Jul 15, 2020 at 11:02 AM Oleg Nenashev <[hidden email]> wrote:
> hudson.model.user.getById(String id, false).getFullName() would be the best approach.

Rather pass true.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1MLXgyrqCVTYViF47k%2BPjarPmeBYCQM9L%3DydXT3PZ-cg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: JENKINS-48900 - Show "Full Name" on Assign Roles page

Oleg Nenashev
Passing true would create a user account if it is missing. I do not think it is a good idea for Role Strategy UI which already supports missing SIDs.

On Wed, Jul 15, 2020, 19:40 Jesse Glick <[hidden email]> wrote:
On Wed, Jul 15, 2020 at 11:02 AM Oleg Nenashev <[hidden email]> wrote:
> hudson.model.user.getById(String id, false).getFullName() would be the best approach.

Rather pass true.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/fQ8aOxAIwPw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1MLXgyrqCVTYViF47k%2BPjarPmeBYCQM9L%3DydXT3PZ-cg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAPfivLDmAM96rBa8zJJisu6xvN_%3DQwB3WUUcmnO066JHjJW6DQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: JENKINS-48900 - Show "Full Name" on Assign Roles page

Jesse Glick-4
On Wed, Jul 15, 2020 at 1:49 PM Oleg Nenashev <[hidden email]> wrote:
> Passing true would create a user account if it is missing.

Does not _save_ a user account, merely ensures that a `User` object is
created in memory if it were not already on disk, which it very well
might not be. The Javadoc is perhaps misleading.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr38avQDyWpFPdPkQDs2u_HRn4V-gGTKEPA2mAtA6NG2qg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: JENKINS-48900 - Show "Full Name" on Assign Roles page

Tidhar Klein Orbach
Thanks guys!
I'm still playing with it to understand how everything works.
This is what I have so far:

I created a new method in RoleBasedAuthorizationStrategy:

public Map<String,String> getSIDsFullNames(String type) {
SortedSet<String> sids = getRoleMap(RoleType.fromString(type)).getSids();
Map<String, String> sidToUser = new HashMap<String, String>(sids.size());
for(String sid: sids) {
String fullName = User.getById(sid, true).getFullName();
sidToUser.put(sid, fullName);
}
return sidToUser;
}

then in assign-roles.jelly, changed 
<j:set var="globalSIDs" value="${it.strategy.getSIDs(it.strategy.GLOBAL)}"/>

into this
<j:set var="globalSIDs" value="${it.strategy.getSIDsFullNames(it.strategy.GLOBAL)}"/>

and in assign-global-roles.jelly I used sid.value instead of sid:
<j:forEach var="sid" items="${globalSIDs}">
<tr name="[${sid.value}]" class="permission-row">
<local:userRow sid="${sid.value}" title="${sid.value}" global="${true}" type="${it.strategy.GLOBAL}"/>
</tr>
<j:set var="nbAssignedGlobalRoles" value="${nbAssignedGlobalRoles+1}" />
</j:forEach>

there is a checkForWhitespace form validation on this form, so it didn't work for user that has a full name with a whitespace.
I did fullname.replaceAll(" ", "_") just to see that it works and it did. I got the user name.

what do you think, is it a good direction?
how should we deal with the whitespace validation?

Thanks,
Tidhar

On Wednesday, July 15, 2020 at 9:59:20 PM UTC+3, Jesse Glick wrote:
On Wed, Jul 15, 2020 at 1:49 PM Oleg Nenashev <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="AUyev5B-AwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">o.v.n...@...> wrote:
> Passing true would create a user account if it is missing.

Does not _save_ a user account, merely ensures that a `User` object is
created in memory if it were not already on disk, which it very well
might not be. The Javadoc is perhaps misleading.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/fe8dcafb-33dc-4c56-aa61-0d68ec8c1a8eo%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: JENKINS-48900 - Show "Full Name" on Assign Roles page

Gavin Mogan
Why is the full name being validated. You'd still want to enter/store the Id. Full name would only be display purposes so not the input tag.

No?

On Thu., Jul. 16, 2020, 8:42 a.m. Tidhar Klein Orbach, <[hidden email]> wrote:
Thanks guys!
I'm still playing with it to understand how everything works.
This is what I have so far:

I created a new method in RoleBasedAuthorizationStrategy:

public Map<String,String> getSIDsFullNames(String type) {
SortedSet<String> sids = getRoleMap(RoleType.fromString(type)).getSids();
Map<String, String> sidToUser = new HashMap<String, String>(sids.size());
for(String sid: sids) {
String fullName = User.getById(sid, true).getFullName();
sidToUser.put(sid, fullName);
}
return sidToUser;
}

then in assign-roles.jelly, changed 
<j:set var="globalSIDs" value="${it.strategy.getSIDs(it.strategy.GLOBAL)}"/>

into this
<j:set var="globalSIDs" value="${it.strategy.getSIDsFullNames(it.strategy.GLOBAL)}"/>

and in assign-global-roles.jelly I used sid.value instead of sid:
<j:forEach var="sid" items="${globalSIDs}">
<tr name="[${sid.value}]" class="permission-row">
<local:userRow sid="${sid.value}" title="${sid.value}" global="${true}" type="${it.strategy.GLOBAL}"/>
</tr>
<j:set var="nbAssignedGlobalRoles" value="${nbAssignedGlobalRoles+1}" />
</j:forEach>

there is a checkForWhitespace form validation on this form, so it didn't work for user that has a full name with a whitespace.
I did fullname.replaceAll(" ", "_") just to see that it works and it did. I got the user name.

what do you think, is it a good direction?
how should we deal with the whitespace validation?

Thanks,
Tidhar

On Wednesday, July 15, 2020 at 9:59:20 PM UTC+3, Jesse Glick wrote:
On Wed, Jul 15, 2020 at 1:49 PM Oleg Nenashev <[hidden email]> wrote:
> Passing true would create a user account if it is missing.

Does not _save_ a user account, merely ensures that a `User` object is
created in memory if it were not already on disk, which it very well
might not be. The Javadoc is perhaps misleading.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/fe8dcafb-33dc-4c56-aa61-0d68ec8c1a8eo%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_Dus3eeQFZHhXDom7prfZePHjwkbkqutzFtF2BfFynVPbyQ%40mail.gmail.com.