+ @SuppressWarnings("unchecked")
+ public LdifAuthorization(User user, List<Role> allRoles) {
+ if (user == null) {
+ this.name = null;
+ this.displayName = "anonymous";
+ } else {
+ this.name = user.getName();
+ Dictionary<String, Object> props = user.getProperties();
+ Object displayName = props.get(LdifName.displayName);
+ if (displayName == null)
+ displayName = props.get(LdifName.cn);
+ if (displayName == null)
+ displayName = props.get(LdifName.uid);
+ if (displayName == null)
+ displayName = user.getName();
+ if (displayName == null)
+ throw new UserDirectoryException("Cannot set display name for "
+ + user);
+ this.displayName = displayName.toString();
+ }
+ // roles
+ String[] roles = new String[allRoles.size()];
+ for (int i = 0; i < allRoles.size(); i++) {
+ roles[i] = allRoles.get(i).getName();
+ }
+ this.allRoles = Collections.unmodifiableList(Arrays.asList(roles));