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

20 views
Skip to first unread message

Tidhar Klein Orbach

unread,
Jul 14, 2020, 8:21:12 AM7/14/20
to Jenkins Developers
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

Oleg Nenashev

unread,
Jul 15, 2020, 11:02:05 AM7/15/20
to Jenkins Developers
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

Jesse Glick

unread,
Jul 15, 2020, 1:40:46 PM7/15/20
to Jenkins Dev
On Wed, Jul 15, 2020 at 11:02 AM Oleg Nenashev <o.v.ne...@gmail.com> wrote:
> hudson.model.user.getById(String id, false).getFullName() would be the best approach.

Rather pass true.

Oleg Nenashev

unread,
Jul 15, 2020, 1:49:17 PM7/15/20
to JenkinsCI Developers
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.

--
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 jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1MLXgyrqCVTYViF47k%2BPjarPmeBYCQM9L%3DydXT3PZ-cg%40mail.gmail.com.

Jesse Glick

unread,
Jul 15, 2020, 2:59:20 PM7/15/20
to Jenkins Dev
On Wed, Jul 15, 2020 at 1:49 PM Oleg Nenashev <o.v.ne...@gmail.com> 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.

Tidhar Klein Orbach

unread,
Jul 16, 2020, 11:34:11 AM7/16/20
to Jenkins Developers
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:

Gavin Mogan

unread,
Jul 16, 2020, 11:59:34 AM7/16/20
to Jenkins Developers
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?

--
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 jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/fe8dcafb-33dc-4c56-aa61-0d68ec8c1a8eo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages