You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by di...@apache.org on 2015/03/24 05:02:06 UTC
incubator-ranger git commit: RANGER-320: Usersync NPE when object
does not have userNameAttribute
Repository: incubator-ranger
Updated Branches:
refs/heads/master ddf9cfa74 -> 405c51853
RANGER-320: Usersync NPE when object does not have userNameAttribute
Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/405c5185
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/405c5185
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/405c5185
Branch: refs/heads/master
Commit: 405c518531f63dd932791f9e5f0f6214aa7bd0a8
Parents: ddf9cfa
Author: Dilli Dorai Arumugam <da...@hortonworks.com>
Authored: Thu Mar 19 10:36:43 2015 -0700
Committer: Dilli Dorai Arumugam <da...@hortonworks.com>
Committed: Mon Mar 23 21:01:13 2015 -0700
----------------------------------------------------------------------
.../process/LdapUserGroupBuilder.java | 41 ++++++++++++++++++--
1 file changed, 37 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/405c5185/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java b/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
index b6bb811..011170c 100644
--- a/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
+++ b/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
@@ -31,6 +31,7 @@ import javax.naming.Context;
import javax.naming.InvalidNameException;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.Control;
@@ -274,10 +275,42 @@ public class LdapUserGroupBuilder implements UserGroupSource {
while (userSearchResultEnum.hasMore()) {
// searchResults contains all the user entries
final SearchResult userEntry = userSearchResultEnum.next();
- String userName = (String) userEntry.getAttributes()
- .get(userNameAttribute).get();
-
-
+
+ if (userEntry == null) {
+ if (LOG.isInfoEnabled()) {
+ LOG.info("userEntry null, skipping sync for the entry");
+ }
+ continue;
+ }
+
+ Attributes attributes = userEntry.getAttributes();
+ if (attributes == null) {
+ if (LOG.isInfoEnabled()) {
+ LOG.info("attributes missing for entry " + userEntry.getNameInNamespace() +
+ ", skipping sync");
+ }
+ continue;
+ }
+
+ Attribute userNameAttr = attributes.get(userNameAttribute);
+ if (userNameAttr == null) {
+ if (LOG.isInfoEnabled()) {
+ LOG.info(userNameAttribute + " missing for entry " + userEntry.getNameInNamespace() +
+ ", skipping sync");
+ }
+ continue;
+ }
+
+ String userName = (String) userNameAttr.get();
+
+ if (userName == null || userName.trim().isEmpty()) {
+ if (LOG.isInfoEnabled()) {
+ LOG.info(userNameAttribute + " empty for entry " + userEntry.getNameInNamespace() +
+ ", skipping sync");
+ }
+ continue;
+ }
+
if (userNameCaseConversionFlag) {
if (userNameLowerCaseFlag) {
userName = userName.toLowerCase() ;