I need to import users photos from thumbnailPhoto field in ActiveDirectory to Drupal user profile for use as user picture.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johnbarclay’s picture

Component: Code » SimpleTests
Category: feature » task

This is core to the ldap 7.x-2.x branch in LDAP User. I'm tagging this as simpletest so that image uploads are covered in the simpletests. Part of its implementation has to do with binary fields, in some ldaps.

trumanru’s picture

Thank you for good job. This module helps me to enroll Drupal in my company enterprise environment.

Am I correctly understanding that import thumbmailPhoto is available now in 7.x-2.x-dev branch?
Where can I read a manual to setup it?

I've tried to set up mapping "[thumbnailphoto]" to new Image field in user profile ("Test LDAP Server 1 for LDAP Authorization LDAP Server Mappings" section on "Ldap Configuration - 3. User" tab with LDAP Server connection provided by LDAP SipleTest module) but it doesn't work.

omaster’s picture

I have not been able to get image success either.

trumanru’s picture

@omaster - why? What is the problem?
I thought that it is jpeg picture which we can get and directly save to user profile without any convertion.

omaster’s picture

I haven't been able to get the jpegPhoto into the user Photo. first I can't select the standard user photo Field to place it into. And then if I create an image field to try and place it in it says this when a user logs in.

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '[jpegPhoto]' for column 'fid' at row 1: INSERT INTO {file_usage} (fid, module, type, id, count) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( [:db_insert_placeholder_0] => [jpegPhoto] [:db_insert_placeholder_1] => file [:db_insert_placeholder_2] => user [:db_insert_placeholder_3] => 568 [:db_insert_placeholder_4] => 1 ) in file_usage_add() (line 661 of /var/www/html/includes/file.inc).

trumanru’s picture

It's not a problem. This function is not supported. But this issue is a feature request for this function.

After i've got your first comment I thought that you are the developer of this module.

omaster’s picture

Unfortunately not the developer of this module. But this issue is vital to get working for me. So looks like will probably have to see if I can find a way to make it work if nothing done soon.

Two issues for me with this module. One the photos and two cron updates everything else works great or is not critical.

johnbarclay’s picture

Component: SimpleTests » Code
johnbarclay’s picture

Assigned: Unassigned » johnbarclay
johnbarclay’s picture

Assigned: johnbarclay » Unassigned
johnbarclay’s picture

Title: Import thumbnailPhoto from ActiveDirectory to Drupal user profile » LDAP User: Import thumbnailPhoto from ActiveDirectory to Drupal user profile
Category: task » feature
Status: Active » Closed (duplicate)
trumanru’s picture

Status: Closed (duplicate) » Active

Sorry for my persistency but this is very specific case of binary AD data. For this case target of binary data from AD must be special user data object named "Picture" wich used as file in file structure and not available as field in fields selection dialog of LDAP User module.

johnbarclay’s picture

Status: Active » Postponed

Sounds good. Lets keep them separate. I'm setting this to postponed as I don't see any commitment to work on it and I expect to get to it in the the 8.x version. Patches are welcome and here's how I think they should be implemented:

[property.picture] would be the token for going from drupal to ldap and the value in the ldap to drupal pulldown.

in LdapUserConf::entryToUserEdit(), add something like

if ($this->isSynched('[property.picture]', $prov_events, $direction) && !isset($edit['name'])) {
// 1) get image from ldap
// 2) insert image into drupal
// 3) and associate with the user object.
//some code to borrow from:
//user_validate_picture() // http://api.drupal.org/api/drupal/modules%21user%21user.module/function/u...
// user_save() http://api.drupal.org/api/drupal/modules%21user%21user.module/function/u...
//
}

vgalindus’s picture

Version: 7.x-2.x-dev » 7.x-2.0-beta3
Status: Postponed » Active
FileSize
246.33 KB

Hi All I have written a fast patch to allow thumbnailPicture to sync with user thumbnail. This patch applies to beta3 release, please be aware that it is only tested against my current configuration (LDAP). It is up to you using it or not. When I have time I will try to clean up the code and write some tests as well as commit patch to queue in dev branch.

Best regards.

vgalindus’s picture

Version: 7.x-2.0-beta3 » 7.x-2.x-dev

Sorry I moved to beta3, fixing.

omaster’s picture

I just tested it and success it works. You can also sync jpegphoto with it which is great.

What would be good now is to get it into dev so it goes with future versions but thankyou soo much for it. :)

johnbarclay’s picture

The approach looks good to me as it treats the thumbnail as the unique field that it is. Appreciate the offer to clean it up and add some tests; that will make sure it doesn't break down the line.

omaster’s picture

Ok I have found one issue still but I assume it is not really related to this and may get solved by this
http://drupal.org/node/1787970 and vice versa their issues can be solved by this module. now we just need them both at dev level to work.

omaster’s picture

FileSize
266.65 KB

I have moved this onto the dev environment and got it working. Attached is a patch for the dev environment. Sorry it is a little messy inside. But it should do the trick.

--Edit it worked for a short time then started to fail. Not sure why. Maybe missed something.

omaster’s picture

Ok there is something wrong with it now both beta and dev. Need to look into it more.

Basicly though the end result is you get an error log 'Some error happened during thumbnailPhoto sync" which also then screws up the log viewer in Drupal so you have to go to the database to find it.

--edit it appears to be only if you edit a user account then try and resync the image. It only affects specific users. It would be great to know how to correct this for those users.

omaster’s picture

FileSize
13.69 KB

New patch with a corrected watchdog error for 7.x-2.x-dev, and cleaned up so it is much easier to comprehend.

vgalindus’s picture

Hi, I will take a look when I have some time to write unit tests and check this. In my env users are not allowed to change profile so I didn't realized about.

vgalindus’s picture

Hi omaster, i tried updating the thumb. It result in default thumb displayed and no resync happened after login again, is the same for you?
Br

johnbarclay’s picture

I committed 21 with a number of small changes:

  • removed filter = strtolower(filter); Was unclear why this was added in.
  • added drupal_username parameter to userPictureFromLdapEntry() function. Since it can be derived from the ldap entry in a number of ways, it isn't correct to useldap_entry[this->user_attr][0]
  • Some formatting changes

Please test.

omaster’s picture

Excellent. Will test today.

Galindus - Yes that is what I am getting also.

omaster’s picture

Testing went well. So far nothing but the aforementioned problem.

johnbarclay’s picture

for the simpletests I have ldap images in the following format:

jpegPhoto:: /9j/4AAQSkZJRgABAQEAZABkAAD/4gVASUNDX1BST0ZJTEUAAQEAAAUwYXBwbAIg
 AABtbnRyUkdCIFhZWiAH2QACABkACwAaAAthY3NwQVBQTAAAAABhcHBsAAAAAAAAAAAAAAAAAAA
...
 g+H2kRlTF9puL6YE9WAWFP/Qnr451uUSajrCDmT7cxY9cgd6KKbYdTnLv/j7Leqg/pVaiikAUUU
 UAFFFFABTn6j6UUUANooooAKKKKACiiigAooooAmhxubIzRRRQB//Z

What format(s) should be in the ldap php array for the simpletest? That is what formats would you expect the ldap php array?

If you can just post examples that would help with the simpletests.

vgalindus’s picture

I have this kind too

/9j/4RONRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAA
UAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAeAAAAcgEyAAIAAAAUAAAAkIdpAAQAAAABAAA
ApAAAANAACvyAAAAnEAAK
......
OWT1F4gKAtOhHj1y3dGyE3rviq0Ur74quhLeqKDAWQTWP1Qo4iq9sg2NgzV2FPHFO6Ev8A1Kjl08ck
GMkH3H45NqW7/Riq4Yqr2tfXj/1hX78Kv//Z

BR

trumanru’s picture

I don't beleive my eyes! It's really works!

Guys, you saved my day!
No, no.... More than a one day! You saved my MONTH!

The next question is: does it work with LDAP Feeds module?
I have a phonebook directory on corporative portal with all users from Active Directory and it would be good to have all user's photos. Not only photos of users who have logged in portal but all of them.

omaster’s picture

It sounds more like cron functionality which is what I am looking for would be good. If the user data can update via cron then I am all set.

vgalindus’s picture

Hi All, I've been working a bit more on this. Now you can set the same options as for email attr under authentication form. I think update process has been improved but needs some test. Updated to last dev release. To work is required to apply this patch http://drupal.org/node/1787970

Not sure about cron functionality, if it is already there it should work.

BR

johnbarclay’s picture

Category: feature » bug
Status: Active » Needs review

Thanks. Seems like a useful direction especially with the clear explanation of the options.

This should go into ldap_user and ldap_server module, not ldap_authentication. Ideally as field in the ldap_user provisioning grid/table/mapping. If it can't fit into that format because of the unique nature of profile images, the provisioning part should go in ldap_user with things like update options and anything specific to the ldap_server such as the attribute holding the image should go in ldap_server.

@galindus_olidop can you start another issue as a feature request for the additional options. That way we can close this one out when the images themselves are working correctly.

trumanru’s picture

Thumbnails import from AD works good thru LDAP Feeds.

But after installed last dev release (2013-02-28) i've some problems.

First.
SSO doesn't work. I cant distinguish the source of this problems till now. Perhaps it's depended on other changes.

Second.
After login thru form on user/login page ordinary users see error messages:

  • Notice: Undefined variable: account in LdapServer->userPictureFromLdapEntry() (line 1020 of C:\www\portal\sites\all\modules\ldap\ldap_servers\LdapServer.class.php).
  • Notice: Trying to get property of non-object in LdapServer->userPictureFromLdapEntry() (line 1020 of C:\www\portal\sites\all\modules\ldap\ldap_servers\LdapServer.class.php).

As I see in this error message, the function which have a problem is userPictureFromLdapEntry().

johnbarclay’s picture

sso may be related to:[#892368]

johnbarclay’s picture

@#33. I fixed the obvious issue with userPictureFromLdapEntry and committed it. http://drupalcode.org/project/ldap.git/commitdiff/f0c1a07ae2cf18ff1f7cb2... and the one after that. Please keep testing and thanks for the quick fixes.

trumanru’s picture

I reverted my site's ldap installation to LDAP module 7.x-2.x-dev version 2013-02-26.
Only this version can imports thumbnailPhoto AD field via LDAP Feeds. Versions 2013-02-28 and 2013-03-11 don't do it.

trumanru’s picture

7.x-2.x-dev still doesn't work with LDAP Feeds but 7.x-2.x-dev version 2013-02-26 worked fine.

trumanru’s picture

Version: 7.x-2.x-dev » 7.x-2.0-beta4

Provisioning during user logon works fine but LDAP Feeds still doesn't load thumbnailPicture to user profile. As I said before 7.x-2.x-dev version 2013-02-26 did it.

I've made this process many times:
1. install new dev version
2. check loading thumbnails via LDAP Feeds = unsuccessfull
3. remove new version
4. setup version 2013-02-26
5. checking LDAP Feeds = successfully loaded thumbnailPictures

johnbarclay’s picture

Version: 7.x-2.0-beta4 » 7.x-2.x-dev
Status: Needs review » Closed (duplicate)

Lets start one issue for feeds issues and one for ldap user. This issue is all over the place.