From c8321fc96e071f61f9d219be32fd9b7a87210701 Mon Sep 17 00:00:00 2001 From: mposolda Date: Thu, 19 Jun 2014 11:51:20 +0200 Subject: [PATCH] Improvement for AD integration to avoid exception when mulitple users without email are synced to Keycloak DB --- .../picketlink/PicketlinkAuthenticationProvider.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/authentication/authentication-picketlink/src/main/java/org/keycloak/authentication/picketlink/PicketlinkAuthenticationProvider.java b/authentication/authentication-picketlink/src/main/java/org/keycloak/authentication/picketlink/PicketlinkAuthenticationProvider.java index 615e2c7acf..b2310ede9c 100755 --- a/authentication/authentication-picketlink/src/main/java/org/keycloak/authentication/picketlink/PicketlinkAuthenticationProvider.java +++ b/authentication/authentication-picketlink/src/main/java/org/keycloak/authentication/picketlink/PicketlinkAuthenticationProvider.java @@ -51,9 +51,15 @@ public class PicketlinkAuthenticationProvider implements AuthenticationProvider try { User picketlinkUser = BasicModel.getUser(identityManager, username); - return picketlinkUser == null ? null : new AuthUser(picketlinkUser.getId(), picketlinkUser.getLoginName(), getName()) + if (picketlinkUser == null) { + return null; + } + + String email = (picketlinkUser.getEmail() != null && picketlinkUser.getEmail().trim().length() > 0) ? picketlinkUser.getEmail() : null; + + return new AuthUser(picketlinkUser.getId(), picketlinkUser.getLoginName(), getName()) .setName(picketlinkUser.getFirstName(), picketlinkUser.getLastName()) - .setEmail(picketlinkUser.getEmail()) + .setEmail(email) .setProviderName(getName()); } catch (IdentityManagementException ie) { throw convertIDMException(ie);