How to display Phone number from LDAP/Active directory?

157 views
Skip to first unread message

Timothy Yim

unread,
Sep 3, 2019, 11:24:46 PM9/3/19
to xnat_discussion
We would like to ask if we can get the "phone number" from Active directory for account registration? 

  It can retrieved "Username", "First name", "Last name" and "email address". Please help. Thanks.


Capture.PNG

McKay, Mike

unread,
Sep 4, 2019, 4:53:56 PM9/4/19
to xnat_discussion

No, I'm pretty sure there is no easy way of doing this. Assuming you are on a 1.7.x version of XNAT (rather than 1.6) and are using the LDAP plugin (https://bitbucket.org/xnatx/ldap-auth-plugin), you would have to download the plugin's source code and make some changes. Just glancing at the code, it might be sufficient to customize https://bitbucket.org/xnatx/ldap-auth-plugin/src/master/src/main/java/org/nrg/xnat/auth/ldap/XnatLdapUserDetailsMapper.java so that the mapUserFromContext method calls the cacheRegistrationData(found, comments, phone, lab) method that is called when registering through the XNAT UI (see https://bitbucket.org/xnatdev/xdat/src/master/src/main/java/org/nrg/xdat/turbine/modules/actions/XDATRegisterUser.java ). That is assuming that the context object in mapUserFromContext has a phone number property (you may want to do context.getAttributes() either in a debugger or writing the contents of the Attributes object to a log file to see what the names are for all the properties you care about and make sure that they are accessible here). So it may be possible, but it would require more advanced level XNAT customizations.


-Mike


From: xnat_di...@googlegroups.com <xnat_di...@googlegroups.com> on behalf of Timothy Yim <timti...@gmail.com>
Sent: Tuesday, September 3, 2019 10:24:46 PM
To: xnat_discussion <xnat_di...@googlegroups.com>
Subject: [XNAT Discussion] How to display Phone number from LDAP/Active directory?
 
We would like to ask if we can get the "phone number" from Active directory for account registration? 

  It can retrieved "Username", "First name", "Last name" and "email address". Please help. Thanks.


--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/0b532769-1e6f-4428-a695-5d075301606b%40googlegroups.com.

 


The materials in this message are private and may contain Protected Healthcare Information or other information of a sensitive nature. If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error, please immediately notify the sender via telephone or return mail.

Timothy Yim

unread,
Sep 4, 2019, 11:23:17 PM9/4/19
to xnat_di...@googlegroups.com
Hi, Mike,

 Thanks for your great help. Thanks.

Timothy

McKay, Mike <mfm...@wustl.edu> 於 2019年9月5日 週四 上午4:53寫道:
You received this message because you are subscribed to a topic in the Google Groups "xnat_discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/xnat_discussion/DAIgVS116tY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/DM6PR02MB5100C41425EF4D3B9573AD62BFB80%40DM6PR02MB5100.namprd02.prod.outlook.com.

Timothy Yim

unread,
Sep 5, 2019, 5:10:34 AM9/5/19
to xnat_discussion
Hi, Mike,

  We face the problem of the compilation. Would you please help?

  Some attributes added in XnatLdapUserDetailsMapper.java but found error.

  XnatLdapUserDetailsMapper.java line 79: (Add 2 attributes phone and dept)  
        final UserI userDetails = _userAuthService.getUserDetailsByNameAndAuth(username, XdatUserAuthService.LDAP, _providerId, email, lastName, firstName, phone, dept);

  Thanks.

Regards,
Timothy
Mike McKay於 2019年9月5日星期四 UTC+8上午4時53分56秒寫道:

No, I'm pretty sure there is no easy way of doing this. Assuming you are on a 1.7.x version of XNAT (rather than 1.6) and are using the LDAP plugin (https://bitbucket.org/xnatx/ldap-auth-plugin), you would have to download the plugin's source code and make some changes. Just glancing at the code, it might be sufficient to customize https://bitbucket.org/xnatx/ldap-auth-plugin/src/master/src/main/java/org/nrg/xnat/auth/ldap/XnatLdapUserDetailsMapper.java so that the mapUserFromContext method calls the cacheRegistrationData(found, comments, phone, lab) method that is called when registering through the XNAT UI (see https://bitbucket.org/xnatdev/xdat/src/master/src/main/java/org/nrg/xdat/turbine/modules/actions/XDATRegisterUser.java ). That is assuming that the context object in mapUserFromContext has a phone number property (you may want to do context.getAttributes() either in a debugger or writing the contents of the Attributes object to a log file to see what the names are for all the properties you care about and make sure that they are accessible here). So it may be possible, but it would require more advanced level XNAT customizations.


-Mike



Sent: Tuesday, September 3, 2019 10:24:46 PM
To: xnat_discussion <xnat_di...@googlegroups.com>
Subject: [XNAT Discussion] How to display Phone number from LDAP/Active directory?
We would like to ask if we can get the "phone number" from Active directory for account registration? 

  It can retrieved "Username", "First name", "Last name" and "email address". Please help. Thanks.


--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_di...@googlegroups.com.
gradlew-output.txt

McKay, Mike

unread,
Sep 5, 2019, 9:29:35 AM9/5/19
to xnat_discussion

That's because there is no getUserDetailsByNameAndAuth method that takes in a phone number. I was suggesting using cacheRegistrationData. That additional user information is stored separately.


-Mike


From: xnat_di...@googlegroups.com <xnat_di...@googlegroups.com> on behalf of Timothy Yim <timti...@gmail.com>
Sent: Thursday, September 5, 2019 4:10:34 AM
To: xnat_discussion <xnat_di...@googlegroups.com>
Subject: Re: [XNAT Discussion] How to display Phone number from LDAP/Active directory?
 
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/b6f411f3-415c-4fb2-976b-a67a27b02bd8%40googlegroups.com.

Timothy Yim

unread,
Sep 5, 2019, 9:33:59 AM9/5/19
to xnat_di...@googlegroups.com
Hi,

  I have tried to change "firstname" to "telephoneNumber" and it's work.

  Can you help and check how to add 1/2 attributes instead of only 3 attributes (firstname, lastname & email) can be retrieved?

  thanks.

Timothy

You received this message because you are subscribed to a topic in the Google Groups "xnat_discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/xnat_discussion/DAIgVS116tY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/DM6PR02MB5100C92821676EC7ADE58F55BFBB0%40DM6PR02MB5100.namprd02.prod.outlook.com.

McKay, Mike

unread,
Sep 5, 2019, 9:41:17 AM9/5/19
to xnat_di...@googlegroups.com

I don't understand. Where did you change "firstname" to "telephoneNumber" and what do you mean that it worked? I also don't understand your question.


-Mike


Sent: Thursday, September 5, 2019 8:33:43 AM
To: xnat_di...@googlegroups.com <xnat_di...@googlegroups.com>

Timothy Yim

unread,
Sep 5, 2019, 9:48:22 AM9/5/19
to xnat_di...@googlegroups.com
Hi,

XnatLdapUserDetailsMapper.java line 79: 
  
orig: 

final UserI userDetails = _userAuthService.getUserDetailsByNameAndAuth(username, XdatUserAuthService.LDAP, _providerId, email, lastName, firstname);

new:
        final UserI userDetails = _userAuthService.getUserDetailsByNameAndAuth(username, XdatUserAuthService.LDAP, _providerId, email, lastName, phone);

i have specify to get telephoneNumber as "phone" and it's work.

if add more fields to line 79, error occured.


method XdatUserAuthService.getUserDetailsByNameAndAuth(String,String) is not applicable
      (actual and formal argument lists differ in length)
    method XdatUserAuthService.getUserDetailsByNameAndAuth(String,String,String) is not applicable
      (actual and formal argument lists differ in length)
    method XdatUserAuthService.getUserDetailsByNameAndAuth(String,String,String,String) is not applicable
      (actual and formal argument lists differ in length)
    method XdatUserAuthService.getUserDetailsByNameAndAuth(String,String,String,String,String,String) is not applicable
      (actual and formal argument lists differ in length)
1 error

Any idea to solve? Thanks.

Timothy

McKay, Mike

unread,
Sep 5, 2019, 10:17:07 AM9/5/19
to xnat_di...@googlegroups.com

This approach will not work. There are no versions of that method that take more fields and even though passing a phone number in as the firstname does not give you a build error, that does not mean it will work correctly.


What are you wanting? If you simply want LDAP phone numbers to be stored in XNAT just like phone numbers that users type in when registering through the XNAT site, you want to use the cacheRegistrationData method to store that information in the xhbm_user_registration_data table. However, this is currently only used in sending out new user emails, and the phone numbers will not be viewable from within the XNAT site.


-Mike

Sent: Thursday, September 5, 2019 8:48:07 AM

McKay, Mike

unread,
Sep 5, 2019, 11:10:35 AM9/5/19
to xnat_discussion

And you'd actually want to use cacheUserRegistrationData since cacheRegistrationData is a private method. Basically just copy the two lines from XDATRegisterUser.cacheRegistrationData and pass in the phone number (if you're able to obtain it successfully):


UserRegistrationDataService service = XDAT.getContextService().getBean(UserRegistrationDataService.class);
service.cacheUserRegistrationData(newUser, phone, lab, comments);

-Mike


Sent: Tuesday, September 3, 2019 10:24:46 PM
To: xnat_discussion <xnat_di...@googlegroups.com>
Subject: [XNAT Discussion] How to display Phone number from LDAP/Active directory?
We would like to ask if we can get the "phone number" from Active directory for account registration? 

  It can retrieved "Username", "First name", "Last name" and "email address". Please help. Thanks.


--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/0b532769-1e6f-4428-a695-5d075301606b%40googlegroups.com.

Timothy Yim

unread,
Sep 6, 2019, 2:33:36 AM9/6/19
to xnat_di...@googlegroups.com
Hi,

  How can I add those 2 lines? any other file should be included? Please advise. Thanks.

Timothy

McKay, Mike <mfm...@wustl.edu> 於 2019年9月5日 週四 下午11:10寫道:
You received this message because you are subscribed to a topic in the Google Groups "xnat_discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/xnat_discussion/DAIgVS116tY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/DM6PR02MB5100DDF12ADD146490E72F2ABFBB0%40DM6PR02MB5100.namprd02.prod.outlook.com.

McKay, Mike

unread,
Sep 6, 2019, 10:49:39 AM9/6/19
to xnat_di...@googlegroups.com

The instructions from my original message in this thread still apply. I was just clarifying that you should actually be adding those two lines instead of adding a call to cacheRegistrationData. You'd of course also need to make sure you add imports for all the classes mentioned in those two lines and add the XNAT dependencies that contain those classes to the build.gradle file for the plugin as dependencies. But as I said, this is a more advanced customization and maybe not something that makes sense to take on.


-Mike


Sent: Friday, September 6, 2019 1:33:23 AM
To: xnat_di...@googlegroups.com <xnat_di...@googlegroups.com>
Subject: Re: [XNAT Discussion] How to display Phone number from LDAP/Active directory?
 
Reply all
Reply to author
Forward
0 new messages