Class Users


  • public class Users
    extends java.lang.Object
    Utilities to work with users.

    Author:
    Javier Paniza
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ADMIN_OX  
      static java.lang.String SHARED_OX  
    • Constructor Summary

      Constructors 
      Constructor Description
      Users()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.prefs.Preferences getAdminPreferences()
      Preferences of the admin user.
      static java.lang.String getCurrent()
      The user name associated to the current thread.
      static java.lang.String getCurrentIP()  
      static java.util.prefs.Preferences getCurrentPreferences()
      Preferences of the user associated to the current thread.
      static UserInfo getCurrentUserInfo()
      Info about the current logged user.
      static java.util.prefs.Preferences getSharedPreferences()
      Preferences of the shared user.
      static void setCurrent​(java.lang.String userName)
      Associated an user to the current thread.
      static void setCurrent​(javax.servlet.http.HttpServletRequest request)
      Associated the user of the request to the current thread.
      static void setCurrentUserInfo​(UserInfo userInfo)
      Associated the UserInfo object to the current thread.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Users

        public Users()
    • Method Detail

      • getCurrent

        public static java.lang.String getCurrent()
        The user name associated to the current thread.

        Returns:
        null if no user logged.
      • getCurrentIP

        public static java.lang.String getCurrentIP()
        Since:
        6.1
      • getCurrentPreferences

        public static java.util.prefs.Preferences getCurrentPreferences()
                                                                 throws java.util.prefs.BackingStoreException
        Preferences of the user associated to the current thread.

        You can use this preference for read and update user preferences, in this way:

         // Obtain preferences for the current user and node (an arbitrary category of your choice).
         Preferences preferences = Users.getCurrentPreferences().node("mynode");
         
         // Read a property value
         boolean rowsHidden = preferences.getBoolean(ROWS_HIDDEN, false);
          
         // Modify and save a property  
         preferences.putBoolean(ROWS_HIDDEN, rowsHidden);
         preferences.flush();
         
        Remember, you must call flush() always in order to make persistent the changes in preferences.
        Returns:
        The preferences object associated to the current user.
        Throws:
        java.util.prefs.BackingStoreException - Some problem on load preferences.
      • getAdminPreferences

        public static java.util.prefs.Preferences getAdminPreferences()
                                                               throws java.util.prefs.BackingStoreException
        Preferences of the admin user.

        Returns:
        The preferences object associated to the admin user.
        Throws:
        java.util.prefs.BackingStoreException - Some problem on load preferences.
      • getSharedPreferences

        public static java.util.prefs.Preferences getSharedPreferences()
                                                                throws java.util.prefs.BackingStoreException
        Preferences of the shared user.

        Returns:
        The preferences object associated to the shared user.
        Throws:
        java.util.prefs.BackingStoreException - Some problem on load preferences.
      • getCurrentUserInfo

        public static UserInfo getCurrentUserInfo()
        Info about the current logged user.

        Returns:
        Not null. If not info available it returns a UserInfo object with no info.
      • setCurrent

        public static void setCurrent​(java.lang.String userName)
        Associated an user to the current thread.

      • setCurrentUserInfo

        public static void setCurrentUserInfo​(UserInfo userInfo)
        Associated the UserInfo object to the current thread.

      • setCurrent

        public static void setCurrent​(javax.servlet.http.HttpServletRequest request)
        Associated the user of the request to the current thread.