if (name==null || name.length()==0) { throw new IllegalStateException("Group associated with "+username+" does not have a valid name for attribute "+groupNameAttr); }
   protected User newUserFromAttributes(DirContext context,Attributes attrs)      throws NamingException   {      String username = getAttributeValue(uidAttr,attrs);      String password = getAttributeValue(userPasswordAttr, attrs);      String digestPassword = getAttributeValue(userDigestPasswordAttr, attrs);      String gid = getAttributeValue(gidNumberAttr, attrs);      String g_dn = groupByIdPatternFormat.format(new String[] { gid });            LOG.info("Searching for "+gidNumberAttr+"="+gid+" in "+groupBase);      String mainGroup = null;      SearchControls constraints = new SearchControls();      constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);      NamingEnumeration groups = context.search(groupBase,"("+gidNumberAttr+"="+gid+")",constraints);      while (mainGroup==null && groups.hasMore()) {         SearchResult result = (SearchResult)groups.next();         mainGroup = getAttributeValue(groupNameAttr, result.getAttributes());      }      int uid = Integer.parseInt(getAttributeValue(uidNumberAttr, attrs));      LOG.info("Constructing user "+username+"/"+uid+" in group "+(mainGroup==null ? "<none>" : mainGroup));      User user = new User(username, null, mainGroup);      user.setUID(uid);      if (password!=null) {         if (password.charAt(0)=='{') {            int end = password.indexOf('}');            String type = password.substring(0,end+1);            String value = password.substring(end+1);            LOG.info("  digest: "+type+", "+value);            if (!type.equals("{MD5}")) {               throw new IllegalStateException("User "+username+" has a non-md5 digested password: "+type);            }            user.setEncodedPassword(value);         } else {            user.setPassword(password);         }      }      if (digestPassword!=null) {         user.setPasswordDigest(digestPassword);      }            LOG.info("Finding additional groups...");      String fullName = uidAttr+"="+username+","+userBase;      groups = context.search(groupBase,"("+groupMemberName+"="+fullName+")",constraints);      while (groups.hasMore()) {         SearchResult result = (SearchResult)groups.next();         String name = getAttributeValue(groupNameAttr, result.getAttributes());         if (!name.equals(mainGroup)) {            LOG.info("   ...adding: "+name);            user.addGroup(name);         }      }      return user;   }