Recover from IllegalArgumentException on Principal
Log the exception (as a warning) and continue the rest of the loop,
rather than aborting the entire call to makeDefs(), when that exception
is thrown on a call to new {Group,User}Principal.
diff --git a/src/com/google/enterprise/adaptor/ad/AdAdaptor.java b/src/com/google/enterprise/adaptor/ad/AdAdaptor.java
index 10de468..f334fb5 100644
--- a/src/com/google/enterprise/adaptor/ad/AdAdaptor.java
+++ b/src/com/google/enterprise/adaptor/ad/AdAdaptor.java
@@ -311,7 +311,13 @@
}
String groupName = getPrincipalName(entity);
- GroupPrincipal group = new GroupPrincipal(groupName, namespace);
+ GroupPrincipal group;
+ try {
+ group = new GroupPrincipal(groupName, namespace);
+ } catch (IllegalArgumentException iae) {
+ log.log(Level.WARNING, "Skipping over badly-named group", iae);
+ continue;
+ }
List<Principal> def = new ArrayList<Principal>();
if (!feedBuiltinGroups
@@ -332,8 +338,23 @@
String memberName = getPrincipalName(member);
if (member.isGroup()) {
p = new GroupPrincipal(memberName, namespace);
+ try {
+ p = new GroupPrincipal(memberName, namespace);
+ } catch (IllegalArgumentException iae) {
+ String warning = "Skipping badly-named group \"" + memberName
+ + "\" from group \"" + groupName + "\".";
+ log.log(Level.WARNING, warning, iae);
+ continue;
+ }
} else {
- p = new UserPrincipal(memberName, namespace);
+ try {
+ p = new UserPrincipal(memberName, namespace);
+ } catch (IllegalArgumentException iae) {
+ String warning = "Skipping badly-named user \"" + memberName
+ + "\" from group \"" + groupName + "\".";
+ log.log(Level.WARNING, warning, iae);
+ continue;
+ }
}
def.add(p);
}