Introduce Tokens and Argeo Studio styling
[lgpl/argeo-commons.git] / org.argeo.enterprise / src / org / argeo / osgi / useradmin / LdifAuthorization.java
index c92ccf7a77e75918a0ec64b5f7e1090c68920599..354f8c0e224d333f2f55b3903178c1bc285614d6 100644 (file)
@@ -16,25 +16,13 @@ class LdifAuthorization implements Authorization {
        private final String displayName;
        private final List<String> allRoles;
 
-       @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(LdapAttrs.displayName);
-                       if (displayName == null)
-                               displayName = props.get(LdapAttrs.cn);
-                       if (displayName == null)
-                               displayName = props.get(LdapAttrs.uid);
-                       if (displayName == null)
-                               displayName = user.getName();
-                       if (displayName == null)
-                               throw new UserDirectoryException("Cannot set display name for "
-                                               + user);
-                       this.displayName = displayName.toString();
+                       this.displayName = extractDisplayName(user);
                }
                // roles
                String[] roles = new String[allRoles.size()];
@@ -80,4 +68,18 @@ class LdifAuthorization implements Authorization {
        public String toString() {
                return displayName;
        }
+
+       final static String extractDisplayName(User user) {
+               Dictionary<String, Object> props = user.getProperties();
+               Object displayName = props.get(LdapAttrs.displayName);
+               if (displayName == null)
+                       displayName = props.get(LdapAttrs.cn);
+               if (displayName == null)
+                       displayName = props.get(LdapAttrs.uid);
+               if (displayName == null)
+                       displayName = user.getName();
+               if (displayName == null)
+                       throw new UserDirectoryException("Cannot set display name for " + user);
+               return displayName.toString();
+       }
 }