Class JaloSession

    • Constructor Detail

      • JaloSession

        public JaloSession()
    • Method Detail

      • getTenant

        public <T extends Tenant> T getTenant()
      • assureSessionNotStale

        public static boolean assureSessionNotStale​(JaloSession session)
        Returns:
        false whenever given JaloSession has not exactly the same tenantRestartMarker with the Tenant which is referenced by this JaloSession.
      • init

        protected void init()
        Overwrite this class for special initialization logic.
      • isDefaultAnonymous

        protected boolean isDefaultAnonymous​(java.util.Map props)
      • createSessionID

        protected java.lang.String createSessionID()
        creates a session ID for a newly created session. currently this is done by creating a new PK of the session typecode.

        override this method to create own session ids.

        Returns:
        the session id string
      • getInitialSessionLanguage

        protected Language getInitialSessionLanguage​(User user)
      • getInitialSessionCurrency

        protected Currency getInitialSessionCurrency​(User user)
      • generateLoginTokenCookieValue

        public java.lang.String generateLoginTokenCookieValue()
                                                       throws EJBPasswordEncoderNotFoundException
        Generates a value entry for a CookieBasedLoginToken instance, which will be used by some web apps (like printcockpit, hmc, ...) for an 'auto' login process
        Returns:
        the generated token. format: ${session.user PK}${session.language PK}${session.user.password} (sample: 11326704420716009013969790041776ee10c315eba2c75b403ea79136f5b38d)
        Throws:
        EJBPasswordEncoderNotFoundException
      • generateLoginTokenCookieValue

        public java.lang.String generateLoginTokenCookieValue​(java.lang.String iso)
                                                       throws EJBPasswordEncoderNotFoundException
        Generates a value entry for a CookieBasedLoginToken instance, which will be used by some web apps (like printcockpit, hmc, ...) for an 'auto' login process
        Parameters:
        iso - language
        Returns:
        the generated token. format: ${session.user PK}${session.language PK}${session.user.password} (sample: 11326704420716009013969790041776ee10c315eba2c75b403ea79136f5b38d)
        Throws:
        EJBPasswordEncoderNotFoundException
      • performLogin

        protected User performLogin​(LoginToken token,
                                    java.util.Map loginProperties)
                             throws JaloSecurityException
        performs login for a given login token and additionally params. the method must return an existing user item - otherwise the session creation process will report an error.

        this method is called during session creation and session transfer.

        subclasses may override this method to implement own user search and/or login check behaviour.

        Parameters:
        token - login token
        loginProperties - logging properties ( see JaloSession.LoginProperties )
        Returns:
        the user which is associated with this newly created session
        Throws:
        JaloSecurityException
      • performLogin

        protected User performLogin​(java.lang.String login,
                                    java.lang.String password,
                                    java.util.Map loginProperties)
                             throws JaloSecurityException
        performs login for a given login, password and additionally params. the method must return an existing user item - otherwise the session creation process will report an error.

        this method is called during session creation and session transfer.

        subclasses may override this method to implement own user search and/or login check behaviour.

        Parameters:
        login - user's login
        password - user's password
        loginProperties - logging properties ( see JaloSession.LoginProperties )
        Returns:
        the user which is associated with this newly created session
        Throws:
        JaloSecurityException
      • isAnonymousAndAnonymousLoginIsDisabled

        protected boolean isAnonymousAndAnonymousLoginIsDisabled​(java.lang.String login)
        Tells whether this is the anonymous account and anonymous login is disallowed ( using the login.anonymous.always.disabled configuration parameter ).
      • isNotAnonymousOrAnonymousLoginIsAllowed

        protected boolean isNotAnonymousOrAnonymousLoginIsAllowed​(java.lang.String login)
        Tells whether this is not anonymous account or anonymous login is allowed by setting login.anonymous.always.disabled configuration parameter to false.
      • activate

        public void activate()
        Set the given JaloSession as the active session for the current thread.

        It is very important not to forget this. It can be not guaranteed that you can access objects that belongs to a 'not activated' session.

        This always ensures that you have no problems accessing the jalo objects. This method is automatically called e.g. when using WebSessionFunctions.getSession() to get a session.

      • deactivate

        public static void deactivate()
        remove the active session from the current thread.

      • setLastAccessed

        protected void setLastAccessed​(long accessed)
      • getCreationTime

        public long getCreationTime()
        Returns:
        the creationTime
      • getLastAccessed

        public long getLastAccessed()
        Returns:
        the lastAccessed
      • getCurrentSession

        public static JaloSession getCurrentSession()
        Returns the active session for the current thread and tenant

        If none is available, a new anonymous session will be created.

        Returns:
        the current session
        Throws:
        java.lang.IllegalStateException - in case no tenant is active
      • checkSessionValidity

        protected void checkSessionValidity()
        returns false if session is already closed()
      • touch

        public void touch()
        mark this session as used. The timeout is being reset. See also the setTimeout(), getTimeout() and isExpired()
        Since:
        3.0
      • getTimeout

        @Deprecated
        public int getTimeout()
        Deprecated.
        since 5.5.1 session management was changed and this method always return -1
        get the timeout in seconds. If the timeout is 0 or less the session will never expire.
        Returns:
        the timeout in seconds
        Since:
        3.0
      • setTimeout

        @Deprecated
        public void setTimeout​(int seconds)
        Deprecated.
        since 5.5.1 session management was changed and this method has no effect
        set the timeout in seconds. If 0 or less is specified, the session will never expire.
        Parameters:
        seconds - the timeout in seconds
        Since:
        3.0
      • setTimeoutInMillis

        @Deprecated
        public void setTimeoutInMillis​(long timeOutInMillis)
        Deprecated.
        since 5.5.1 session management was changed and this method has no effect
        Set the timeout in milliseconds! Same as setTimeout(int) but expects the timeout in milliseconds here! If 0 or less is specified, the session will never expire.
        Parameters:
        timeOutInMillis - the time out of the session in milli seconds
        Since:
        4.5
      • isExpired

        @Deprecated
        public boolean isExpired()
        Deprecated.
        since 5.5.1 session management was changed and this method always return false
        checks whether the current session is expired. if the timeout was set to 0 seconds or less, the session will never expire
        Since:
        3.0
      • getDefaultSessionTimeout

        protected int getDefaultSessionTimeout()
        returns the default session timeout in seconds which will be assigned to a new session if it is created The default implementation returns the value of the "default.session.timeout" configuration parameter or '86400' if not set (that is 1 day). this method can be overridden by subclasses.
        Since:
        3.0
      • internalGetCurrentSession

        public static JaloSession internalGetCurrentSession()
        Returns the active session for the current thread.

        If none is available NULL is returned

        Returns:
        the JaloSession or null
      • hasCurrentSession

        public static boolean hasCurrentSession()
        Helper method for testing if the current thread has an active session.

        The advantage of calling this method instead of getCurrentSession() is that you do not have to catch an Exception.

        Returns:
        true if the current thread has an active session (that is not already closed()), false otherwise
      • hasCurrentSession

        public static boolean hasCurrentSession​(Tenant tenant)
      • getUser

        public User getUser()
        Returns the user which is currently associated with this session.
        Returns:
        the user which is currently associated with this session
      • setUser

        public void setUser​(User user)
        Changes the session user without any login processing. Further the session cart is assigned to the new user.
        Parameters:
        user - the new user
      • transfer

        public void transfer​(java.lang.String user,
                             java.lang.String pwd)
                      throws JaloSecurityException
        changes the session user including the full login process. any settings made to this session are kept except that the session cart is assigned to the new session user. The default language and currency will not be set for the new user. Therefore use transfer(Map props, boolean activateUserLanguageAndCurrency) with last parameter = true.
        Parameters:
        user - the new user
        pwd - the password of the user
        Throws:
        JaloSecurityException - in case login process failed
      • transfer

        public void transfer​(java.util.Map props,
                             boolean activateUserLanguageAndCurrency)
                      throws JaloSecurityException,
                             JaloInvalidParameterException
        changes the session user including the full login process. any settings made to this session are kept except that the session cart is assigned to the new session user. if specified the session language and session currency is changed to the values belonging to the new user ( see GeneratedUser.getSessionLanguage() and GeneratedUser.getSessionCurrency() ). Set the Boolean activateUserLanguageAndCurrency to true if you want the new user to use his / her default language and currency. If set to false, the new user will have the language and currency used by the former user.
        Parameters:
        props - logging properties ( see JaloSession.LoginProperties )
        activateUserLanguageAndCurrency - if true the session language and session currency are set to the values set at the new user
        Throws:
        JaloSecurityException - in case login process failed
        JaloInvalidParameterException - in case some provided parameter had an unexpected value
      • getLoginToken

        protected LoginToken getLoginToken​(java.util.Map props)
      • getCart

        public Cart getCart()
        Returns the cart which is currently associated with this session. if no cart is available at this time, a new one is created.
        Returns:
        the cart which is currently associated with this session
      • getAttachedCart

        protected Cart getAttachedCart()
      • setAttachedCart

        protected void setAttachedCart​(Cart cart)
      • createCart

        protected Cart createCart()
        Used by getCart() to create a new cart.
        Returns:
        the new Cart
      • getCartType

        protected ComposedType getCartType()
        Provides composed type for newly created cart. Fetches type from either session context (first) or configuration (second). If no type has been specified it returns null.
      • hasCart

        public boolean hasCart()
      • removeCart

        public void removeCart()
        Removes a cart from the current session and database, if the Item.remove() fails it is always clearing the internal reference.
      • setCart

        public void setCart​(Cart cart)
      • restoreSavedCart

        public void restoreSavedCart​(Cart savedCart)
        Restores all entries from a saved cart to the session cart, thereby removes currently existing entries.
        Parameters:
        savedCart -
      • appendSavedCart

        public void appendSavedCart​(Cart appendCart)
        Appends the entries from the saved cart to the session cart.
        Parameters:
        appendCart -
      • getLoginProperties

        public java.util.Map getLoginProperties()
        returns the properties that was used to create this session.

        When creating a session with JaloConnection.createSession() you have to specify a map with user informations.

        This method returns this 'login-information' map.

        Returns:
        the properties that were used to create this session
      • setLoginProperties

        protected void setLoginProperties​(java.util.Map loginProperties)
      • setAttributes

        public void setAttributes​(java.util.Map attributes)
        Replaces multiple session attributes at once. Please note that previously stored attributes are not removed if their keys are not included in the new map.
        Parameters:
        attributes - the attributes to store
      • getAttributes

        public java.util.Map getAttributes()
        Returns the attribute map of the session context.
        Returns:
        the attribute map of the current session context
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String name)
        Returns the value of the attribute with the specified name from the attribute map of the current session context.
        Parameters:
        name - of the attribute
        Returns:
        the value of the attribute specified in the parameter name
      • setAttribute

        public java.lang.Object setAttribute​(java.lang.String name,
                                             java.lang.Object value)
        Sets a new value for the attribute with the specified name in the attribute map of the current session context.
        Parameters:
        name - of the attribute
        value - the new value
        Returns:
        the old value of the attribute specified in the parameter name
      • getAttributeNames

        public java.util.Enumeration getAttributeNames()
        Returns an Enumeration of String objects containing the names of all the objects bound to this session.
        Returns:
        an Enumeration of String objects containing the names of all the objects bound to this session.
      • removeAttribute

        public java.lang.Object removeAttribute​(java.lang.String name)
        Removes the specified attribute from the attribute map of the current session context.
        Parameters:
        name - of the attribute, which should be removed
        Returns:
        the value of the removed attribute
      • getAccessManager

        public AccessManager getAccessManager()
        returns the AccessManager.
        Returns:
        the AccessManager object
      • getUserManager

        public UserManager getUserManager()
        returns the UserManager.
        Returns:
        the UserManager object
      • getProductManager

        public ProductManager getProductManager()
        returns the ProductManager.
        Returns:
        the ProductManager object
      • getNumberSeriesManager

        public NumberSeriesManager getNumberSeriesManager()
        returns the NumberSeriesManager.
        Returns:
        the NumberSeriesManager object
      • getFlexibleSearch

        public FlexibleSearch getFlexibleSearch()
        returns the FlexibleSearch.
        Returns:
        the FlexibleSearch object
      • getC2LManager

        public C2LManager getC2LManager()
        returns the C2LManager.
        Returns:
        the C2LManager object
      • getMetaInformationManager

        public MetaInformationManager getMetaInformationManager()
        returns the MetaInformationManager.
        Returns:
        the MetaInformationManager object
      • getMediaManager

        public MediaManager getMediaManager()
        returns the MediaManager.
        Returns:
        the MediaManager object
      • getOrderManager

        public OrderManager getOrderManager()
        returns the OrderManager.
        Returns:
        the OrderManager object
      • getLinkManager

        public LinkManager getLinkManager()
        returns the LinkManager.
        Returns:
        the LinkManager object
      • getExtensionManager

        public ExtensionManager getExtensionManager()
        returns the ExtensionManger.
        Returns:
        the ExtensionManager object
      • getTypeManager

        public TypeManager getTypeManager()
        returns the TypeManager.
        Returns:
        the TypeManager object
      • getEnumerationManager

        public EnumerationManager getEnumerationManager()
        return the enumeration manager
        Returns:
        the EnumerationManager object
      • getSessionContext

        public SessionContext getSessionContext()
        Returns the SessionContext currently bound to this session.

        All changes in this SessionContext will directly modify the session's context.

        You can use the following code fragment to change the session language:

         SessionContext ctx = jaloSession.getSessionContext();
         ctx.setLanguage(xy);
         
        .
        Returns:
        the SessionContext object
      • getLocalSessionContext

        protected SessionContext getLocalSessionContext()
      • addLocalSessionContext

        protected void addLocalSessionContext​(SessionContext localCtx)
      • createSessionContext

        public SessionContext createSessionContext()
        Returns a SessionContext which is filled with the current session settings but is NOT bound to the session.

        This means you can change the returned SessionContext object without reflecting these changes into the session.

        Returns:
        the SessionContext object
      • createLocalSessionContext

        public SessionContext createLocalSessionContext()
        creates a new session context which hides this session's current context within the current thread until it is disabled via removeLocalSessionContext(). since createLocalSessionContext may be called multiple time the now visible context might be a local context too.

        please note that any changes made on this sessions context will not pass through to the original context and therefore will be lost after disabling the local context.

        the saves way to use local session context requires finally blocks:

         try
         {
                SessionContext myLocalCtx = JaloSession.getCurrentSession().createLocalSessionContext();
                myLocalCtx.setAttribute("specialForThisThreadOnly", myValue);
                // do whatever in this context should be done
         }
         finally
         {
                JaloSession.getCurrentSession().removeLocalSessionContext();
         }
         
        Returns:
        the new (thread)local session context
      • removeLocalSessionContext

        public void removeLocalSessionContext()
        removes the (thread)local session context associated with this session so that the previous session context is visible again. since createLocalSessionContext() may be called multiple time the now visible context might be a local context too.
      • removeAllLocalSessionContexts

        protected void removeAllLocalSessionContexts()
      • createSearchContext

        public SearchContext createSearchContext()
        Returns a SearchContext object which is used for Search operations.
        Returns:
        a SearchContext object
      • getItem

        public <T extends Item> T getItem​(PK pk)
                                   throws JaloItemNotFoundException
        returns the item with the given PK.
        Parameters:
        pk - the primary key object of the item
        Returns:
        the Item, if found
        Throws:
        JaloItemNotFoundException - if the item could not be found in the system
      • getItem

        @Deprecated
        public <T extends Item> T getItem​(java.lang.String pk)
                                   throws JaloItemNotFoundException,
                                          java.lang.IllegalArgumentException
        Deprecated.
        since ages - please usegetItem(PK) with PK.parse(String)
        returns the item with the given PK.
        Parameters:
        pk - the item primary key as string representation ( see PK.toString() )
        Returns:
        the item if found
        Throws:
        JaloItemNotFoundException - in case no item can be found
        java.lang.IllegalArgumentException - in case the string is no valid PK representation
      • getItems

        public java.util.Collection<? extends Item> getItems​(java.util.Collection<PK> pks)
                                                      throws JaloItemNotFoundException
        Returns a collection of items for a given collection of PKs.

        Use this method for example, if you transfer PKs via GET/POST request from one JSP page to another and then want to 'reincarnate' the item.

        Parameters:
        pks - the primary key collection
        Returns:
        a collection containing Item instances
        Throws:
        JaloItemNotFoundException - if one item could not be found in the system
      • getItems

        public java.util.Collection<? extends Item> getItems​(SessionContext ctx,
                                                             java.util.Collection<PK> pks)
                                                      throws JaloItemNotFoundException
        Returns a collection of items for a given collection of PKs.

        Use this method for example, if you transfer PKs via GET/POST request from one JSP page to another and then want to 'reincarnate' the item.

        Parameters:
        ctx - the session context to define advanced settings like data prefetching
        pks - the primary key collection
        Returns:
        a collection containing Item instances
        Throws:
        JaloItemNotFoundException - if one item could not be found in the system
      • getItems

        public java.util.Collection<? extends Item> getItems​(SessionContext ctx,
                                                             java.util.Collection<PK> pks,
                                                             boolean ignoreMissingItems)
                                                      throws JaloItemNotFoundException
        Returns a collection of items for a given collection of PKs.

        Use this method for example, if you transfer PKs via GET/POST request from one JSP page to another and then want to 'reincarnate' the item.

        Parameters:
        ctx - the session context to define advanced settings like data pre-fetching
        pks - the primary key collection
        ignoreMissingItems - if true invalid item PKs are simply ignored and omitted from the result collection
        Returns:
        a collection containing Item instances
        Throws:
        JaloItemNotFoundException - if one item could not be found in the system unless ignoreMissingItems is true
      • getItems

        public java.util.Collection<? extends Item> getItems​(SessionContext ctx,
                                                             java.util.Collection<PK> pks,
                                                             boolean ignoreMissingItems,
                                                             boolean returnMissingAsNull)
                                                      throws JaloItemNotFoundException
        Returns a collection of items for a given collection of PKs.

        Use this method for example, if you transfer PKs via GET/POST request from one JSP page to another and then want to 'reincarnate' the item.

        Parameters:
        ctx - the session context to define advanced settings like data pre-fetching
        pks - the primary key collection
        ignoreMissingItems - if true invalid item PKs are simply ignored and omitted from the result collection
        returnMissingAsNull - if true when ignoring missing items all non-existent PKs will be returned as NULL within the result collection - otherwise the missing PK is filtered completely
        Returns:
        a collection containing Item instances
        Throws:
        JaloItemNotFoundException - if one item could not be found in the system unless ignoreMissingItems is true
      • getSessionID

        public java.lang.String getSessionID()
        Returns the session ID. The session id is a generated unique string.

        Returns:
        the session id
      • toString

        public java.lang.String toString()
        returns a String representation which contains the SessionID and the UserID which is currently assigned to this Session.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation of this session
      • isClosed

        public boolean isClosed()
        returns true if this session is closed.
        Returns:
        true if this session is closed.
      • close

        public void close()
        Closes this session.

        After closing a session is cannot be guaranteed that you can access items or manager belonging to this session.

        You should call this method if you do not need this session anymore, because all reserved resources will be freed.

      • cleanup

        protected void cleanup()
      • isRemoveCartOnSessionClose

        protected boolean isRemoveCartOnSessionClose()
      • getHttpSession

        @Deprecated
        public javax.servlet.http.HttpSession getHttpSession()
        Deprecated.
        since 5.5.1 session management was changed and this method always returns null
        returns the HttpSession, which is currently associated to this jalo session.

        can be null. A HttpSession is automatically associated if this session is created via WebSessionFunctions.getSession(..)

        Returns:
        the HttpSession
      • setHttpSessionId

        public void setHttpSessionId​(java.lang.String httpSessionId)
        Stores a http session id inside this session.
      • getHttpSessionId

        public java.lang.String getHttpSessionId()
      • search

        public SearchResult search​(GenericQuery query,
                                   SearchContext ctx)
        Initiates a search with the given GenericQuery and SearchContext.
        Parameters:
        query - A GenericQuery instance that specifies your search query.
        ctx - Besides standard evaluation of SearchContext, following custom properties are considered valid: GenericSearchConstants.DONT_NEED_TOTAL -> default is true.
        Returns:
        SearchResult
      • setPriceFactory

        public void setPriceFactory​(PriceFactory factory)
      • search

        public SearchResult search​(GenericQuery genericQuery,
                                   Principal principal,
                                   SearchContext searchCtx)
        Initiates a search with the given GenericQuery and SearchContext.
        Parameters:
        genericQuery - A GenericQuery instance that specifies your search query.
        principal - A Principal instance for restriction evaluation.
        searchCtx - Besides standard evaluation of SearchContext, following custom properties are considered valid: GenericSearchConstants.DONT_NEED_TOTAL -> default is true.
        Returns:
        SearchResult
      • notifyExtensionsBeforeSessionClose

        protected void notifyExtensionsBeforeSessionClose()
      • equals

        public final boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • compareTo

        public int compareTo​(java.lang.Object object)
        Implements item comparison by PK. Subclasses may override this.
        Parameters:
        object - which will be compared to this item.
        Returns:
        the value 0 if the argument item pk is equal to this item pk; a value less than 0 if this item pk is lexicographically less than the argument item pk; and a value greater than 0 if this item pk is lexicographically greater than the argument item pk.
      • hashCode

        public final int hashCode()
        Returns the hashcode of this JaloSession

        The hashcode of an item is defined as the hashcode of its primary key object.

        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hashcode of this item.