From 4ad4e4cff2c072ef612281cc93ca1c66017b7af8 Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Sun, 23 Oct 2016 13:07:17 +0000 Subject: [PATCH] Prepare CurrentUser refactoring git-svn-id: https://svn.argeo.org/commons/trunk@9278 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../cms/util/useradmin/UserAdminUtils.java | 47 +++++-------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/org.argeo.cms.ui/src/org/argeo/cms/util/useradmin/UserAdminUtils.java b/org.argeo.cms.ui/src/org/argeo/cms/util/useradmin/UserAdminUtils.java index fdd61d69d..34b528e1b 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/util/useradmin/UserAdminUtils.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/util/useradmin/UserAdminUtils.java @@ -19,6 +19,7 @@ import org.osgi.service.useradmin.User; import org.osgi.service.useradmin.UserAdmin; /** Centralise common patterns to manage roles with a user admin */ +@Deprecated public class UserAdminUtils { /** Retrieves a {@link Role} given a LDAP name */ @@ -60,16 +61,15 @@ public class UserAdminUtils { return isRegistered(); } - // SELF HELPERS /** Simply retrieves the current logged-in user display name. */ - public static User getCurrentUser(UserAdmin userAdmin) { - return (User) getRole(userAdmin, getCurrentUserLdapName()); + public static String getCurrentUserDisplayName() { + return CurrentUser.getDisplayName(); } + // SELF HELPERS /** Simply retrieves the current logged-in user display name. */ - public static String getCurrentUserDisplayName(UserAdmin userAdmin) { - String username = CurrentUser.getUsername(); - return getUserDisplayName(userAdmin, username); + public static User getCurrentUser(UserAdmin userAdmin) { + return (User) getRole(userAdmin, getCurrentUserLdapName()); } /** Simply retrieves the current logged-in user display name. */ @@ -79,9 +79,8 @@ public class UserAdminUtils { } /** Returns the local name of the current connected user */ - public final static String getUsername(UserAdmin userAdmin) { - LdapName dn = getCurrentUserLdapName(); - return getUsername((User) getRole(userAdmin, dn)); + public final static String getUsername() { + return CurrentUser.getUsername(); } /** Returns true if the current user is in the specified role */ @@ -101,7 +100,8 @@ public class UserAdminUtils { else return false; } catch (InvalidNameException e) { - throw new CmsException("User " + user + " has an unvalid dn: " + userName, e); + throw new CmsException("User " + user + " has an unvalid dn: " + + userName, e); } } @@ -110,30 +110,6 @@ public class UserAdminUtils { return getLdapName(name); } - /** - * Simply retrieves username for current user, generally a LDAP dn - * - * @deprecated Use {@link CurrentUser#getUsername()} - */ - @Deprecated - public static String getCurrentUsername() { - return CurrentUser.getUsername(); - } - - // /** - // * Fork of the {@link CurrentUser#currentSubject} method that is private. - // * TODO Enhance and factorize - // */ - // private static Subject currentSubject() { - // CmsView cmsView = CmsUtils.getCmsView(); - // if (cmsView != null) - // return cmsView.getSubject(); - // Subject subject = Subject.getSubject(AccessController.getContext()); - // if (subject != null) - // return subject; - // throw new RuntimeException("Cannot find related subject"); - // } - // HOME MANAGEMENT /** * Simply retrieves the *relative* path to the current user home node from @@ -162,7 +138,8 @@ public class UserAdminUtils { || last.getType().toLowerCase().equals(LdapAttrs.cn.name())) return (String) last.getValue(); else - throw new CmsException("Cannot retrieve user uid, " + "non valid dn: " + dn); + throw new CmsException("Cannot retrieve user uid, " + + "non valid dn: " + dn); } /** -- 2.30.2