X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.enterprise%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FLdifAuthorization.java;h=354f8c0e224d333f2f55b3903178c1bc285614d6;hb=f9ee9620626e471a99f25e84175e27380d902957;hp=c92ccf7a77e75918a0ec64b5f7e1090c68920599;hpb=57e34e0482e03cea9a6a34326c22c7c969ad07c8;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifAuthorization.java b/org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifAuthorization.java index c92ccf7a7..354f8c0e2 100644 --- a/org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifAuthorization.java +++ b/org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifAuthorization.java @@ -16,25 +16,13 @@ class LdifAuthorization implements Authorization { private final String displayName; private final List allRoles; - @SuppressWarnings("unchecked") public LdifAuthorization(User user, List allRoles) { if (user == null) { this.name = null; this.displayName = "anonymous"; } else { this.name = user.getName(); - Dictionary 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 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(); + } }