X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Futil%2FUserAdminUtils.java;h=65f99c5e1836ba167a81a4065b58d948248b205f;hb=5f1074b1658db47705b0b532099e19ba918c5745;hp=2aa23b2d0023af4c25a4d687ca1830bd808bee95;hpb=d53071455192a97322935a911c9fbbfd92084912;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/util/UserAdminUtils.java b/org.argeo.cms.ui/src/org/argeo/cms/util/UserAdminUtils.java index 2aa23b2d0..65f99c5e1 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/util/UserAdminUtils.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/util/UserAdminUtils.java @@ -38,16 +38,21 @@ public class UserAdminUtils { return getLdapName(name); } - /** Retrieves the current logged-in user display name. */ + /** Retrieves the current logged-in user mail */ public static String getCurrentUserMail(UserAdmin userAdmin) { String username = CurrentUser.getUsername(); return getUserMail(userAdmin, username); } + /** Retrieves the current logged-in user common name */ + public final static String getCommonName(User user) { + return getProperty(user, LdapAttrs.cn.name()); + } + // OTHER USERS HELPERS /** - * Retrieves the local id of a user or group, that is respectively the uid - * or cn of the passed dn with no {@link UserAdmin} + * Retrieves the local id of a user or group, that is respectively the uid or cn + * of the passed dn with no {@link UserAdmin} */ public static String getUserLocalId(String dn) { LdapName ldapName = getLdapName(dn); @@ -60,8 +65,8 @@ public class UserAdminUtils { } /** - * Returns the local username if no user with this dn is found or if the - * found user has no defined display name + * Returns the local username if no user with this dn is found or if the found + * user has no defined display name */ public static String getUserDisplayName(UserAdmin userAdmin, String dn) { Role user = userAdmin.getRole(dn); @@ -92,8 +97,8 @@ public class UserAdminUtils { // LDAP NAMES HELPERS /** - * Easily retrieves one of the {@link Role}'s property or an empty String if - * the requested property is not defined + * Easily retrieves one of the {@link Role}'s property or an empty String if the + * requested property is not defined */ public final static String getProperty(Role role, String key) { Object obj = role.getProperties().get(key); @@ -103,9 +108,25 @@ public class UserAdminUtils { return ""; } + public final static String getProperty(Role role, Enum key) { + Object obj = role.getProperties().get(key.name()); + if (obj != null) + return (String) obj; + else + return ""; + } + + @SuppressWarnings("unchecked") + public final static void setProperty(Role role, String key, String value) { + role.getProperties().put(key, value); + } + + public final static void setProperty(Role role, Enum key, String value) { + setProperty(role, key.name(), value); + } + /** - * Simply retrieves a LDAP name from a {@link LdapAttrs.DN} with no - * exception + * Simply retrieves a LDAP name from a {@link LdapAttrs.DN} with no exception */ private static LdapName getLdapName(String dn) { try { @@ -120,7 +141,10 @@ public class UserAdminUtils { String dn = user.getName(); if (dn.endsWith(NodeConstants.ROLES_BASEDN)) return "System roles"; + if (dn.endsWith(NodeConstants.TOKENS_BASEDN)) + return "Tokens"; try { + // FIXME deal with non-DC LdapName name = new LdapName(dn); List rdns = name.getRdns(); String dname = null;