Prepare CurrentUser refactoring
authorBruno Sinou <bsinou@argeo.org>
Sun, 23 Oct 2016 13:07:17 +0000 (13:07 +0000)
committerBruno Sinou <bsinou@argeo.org>
Sun, 23 Oct 2016 13:07:17 +0000 (13:07 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@9278 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.cms.ui/src/org/argeo/cms/util/useradmin/UserAdminUtils.java

index fdd61d69dd461f7a6af2100305a145d12fb8d005..34b528e1b17886a82c051bcf81cbceac13d690b4 100644 (file)
@@ -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);
        }
 
        /**