Jwma

dtw.webmail
Class JwmaSession

java.lang.Object
  |
  +--dtw.webmail.JwmaSession
All Implemented Interfaces:
java.io.Serializable

public class JwmaSession
extends java.lang.Object
implements java.io.Serializable

Class that models the state of a jwma session.

Each instance stores the state and provides accessor and mutator operations for retrieving and changing.

The reference to the instance itself is stored in the HttpSession as session attribute.

Note that this class is actually the bridge between the web session and the mail client session, and that instances have the responsibility to manage the state of both.

Version:
0.9.7 07/02/2003
Author:
Dieter Wimberger
See Also:
Serialized Form

Constructor Summary
JwmaSession(javax.servlet.http.HttpSession session)
          Constructs a JwmaSession instance.
 
Method Summary
 boolean authenticate(java.lang.String username, java.lang.String password, boolean newAccount)
          Authenticates the given user by initializing the mail session, thus authenticating against the post office of this session.
 void end()
          Ends this session, by cleaning up user related data and resources.
 void ensureAdministrator()
          Tests whether the user associated with this session is allowed to administrate jwma and throws a JwmaException if not, thus ensuring an administrative user.
 void ensureAuthenticated()
          Tests wheter this session is authenticated, throwing a JwmaException if not, thus ensuring an authenticated session.
 void ensurePostOfficeConnection()
          Tests wheter a connection to the post office exists, throwing a JwmaException if not, thus it ensures that a connection to the post office exists.
 void finalize()
          Overrides the superclass method to call end().
 JwmaStoreImpl getJwmaStore()
          Returns the actual mailsession's JwmaStoreImpl.
 JwmaTransportImpl getJwmaTransport()
          Returns the actual mailsession's JwmaTransportImpl.
 java.lang.String getLastLogin()
          Returns a String representing the user's last login date and originating host.
 javax.mail.Session getMailSession()
          Returns this instances mailsession.
 MailTransportAgent getMTA()
           
 PostOffice getPostOffice()
           
 JwmaPreferencesImpl getPreferences()
          Returns the JwmaPreferencesImpl instance of this session instance's user.
 javax.servlet.http.HttpServletRequest getRequest()
          Returns the reference to the actual HttpServletRequest instance.
 java.lang.String getRequestParameter(java.lang.String name)
          Returns the value of a request parameter from this session's HttpServletRequest.
 java.lang.String[] getRequestParameters(java.lang.String name)
          Returns the values of a request parameter from this session's HttpServletRequest.
 javax.servlet.http.HttpServletResponse getResponse()
          Returns the reference to the actual HttpServletResponse instance.
 java.lang.String getUserIdentity()
          Returns the assembled user's identity as String.
 java.lang.String getUserIdentity(java.lang.String username)
          Returns the assembled user's identity as String.
 java.lang.String getUsername()
          Returns the username associated with this JwmaSession.
 javax.servlet.http.HttpSession getWebSession()
          Returns the reference to the actual HttpSession instance.
 boolean isAdministrator()
          Tests if this session's associated user is an administrator.
 boolean isAuthenticated()
          Tests if this session is authenticated.
 boolean isPostOfficeConnected()
          Tests if this session has a connection to the post office.
 boolean isValidWebSession()
          Tests if the associated web session is valid.
 void redirect(java.lang.String view)
          Redirects the the actual HttpServletRequest to an abstract view.
 void redirectToActual()
          Redirects the the actual HttpServletRequest to the present view.
 void redirectToLast()
          Redirects the the actual HttpServletRequest to the last view.
 void removeBean(java.lang.String name)
          Removes a reference to a bean (model) in the actual HttpSession.
 java.lang.Object retrieveBean(java.lang.String name)
          Returns a reference to a bean(model) in the actual HttpSession.
 boolean savePreferences()
          Saves the JwmaPreferencesImpl instance of this session instance's user.
 void setLocale()
          Sets the Locale of this Session to the one that is stored in the user's preferences.
 void setMTA(MailTransportAgent MTA)
           
 void setPostOffice(PostOffice office)
           
 void setRequest(javax.servlet.http.HttpServletRequest request)
          Sets the reference to the actual HttpServletRequest instance.
 void setResponse(javax.servlet.http.HttpServletResponse response)
          Sets the reference to the actual HttpServletResponse instance.
 void setWebSession(javax.servlet.http.HttpSession websession)
          Sets the reference to the actual HttpSession instance.
 void storeBean(java.lang.String name, java.lang.Object bean)
          Stores a reference to a bean(model) in the actual HttpSession.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JwmaSession

public JwmaSession(javax.servlet.http.HttpSession session)
Constructs a JwmaSession instance.

Parameters:
session - reference to the actual HttpSession instance.
Method Detail

setRequest

public void setRequest(javax.servlet.http.HttpServletRequest request)
Sets the reference to the actual HttpServletRequest instance.

Parameters:
request - reference to the actual incoming HttpServletRequest instance.

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Returns the reference to the actual HttpServletRequest instance.

Returns:
reference to the actual HttpServletRequest instance.

setResponse

public void setResponse(javax.servlet.http.HttpServletResponse response)
Sets the reference to the actual HttpServletResponse instance.


getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Returns the reference to the actual HttpServletResponse instance.

Returns:
reference to the actual HttpServletResponse instance.

getWebSession

public javax.servlet.http.HttpSession getWebSession()
Returns the reference to the actual HttpSession instance.

Returns:
reference to the actual HttpSession instance.

isValidWebSession

public boolean isValidWebSession()
Tests if the associated web session is valid. This is the case if it is not new, and if it has not been invalidated.

Returns:
true if valid, false otherwise.

setWebSession

public void setWebSession(javax.servlet.http.HttpSession websession)
Sets the reference to the actual HttpSession instance.


getRequestParameter

public java.lang.String getRequestParameter(java.lang.String name)
Returns the value of a request parameter from this session's HttpServletRequest. This is a convenience method that trims the Strings.

Returns:
the value of the request parameter or null if it doesn't have a value.

getRequestParameters

public java.lang.String[] getRequestParameters(java.lang.String name)
Returns the values of a request parameter from this session's HttpServletRequest. This is a convenience method that trims the Strings.

Returns:
the value of the request parameters or null if it doesn't have any value.

redirect

public void redirect(java.lang.String view)
Redirects the the actual HttpServletRequest to an abstract view.

The String parameter passed in has to be one of the defined abstract view constants.

Parameters:
view - representing one of the constants defining an abstract view.
See Also:
JwmaKernel.LOGIN_VIEW, JwmaKernel.ERROR_VIEW, JwmaKernel.LOGOUT_VIEW, JwmaKernel.FOLDER_VIEW, JwmaKernel.MESSAGE_VIEW, JwmaKernel.PREFERENCES_VIEW, JwmaKernel.COMPOSE_VIEW, JwmaKernel.FIRSTTIME_VIEW, JwmaKernel.CONTACTS_VIEW

redirectToLast

public void redirectToLast()
Redirects the the actual HttpServletRequest to the last view.

The last view is traced by a simple history mechanism implemented in the redirect() method.


redirectToActual

public void redirectToActual()
Redirects the the actual HttpServletRequest to the present view.

The actual view is traced by a simple history mechanism implemented in the redirect() method. This method helps to acquire an updated view of the actual view.


storeBean

public void storeBean(java.lang.String name,
                      java.lang.Object bean)
Stores a reference to a bean(model) in the actual HttpSession.

All stored beans are traced, so that they can be properly removed.

Parameters:
name - the unique identifier of bean to be stored as session attribute.
bean - the reference to the bean to be stored as session attribute.

retrieveBean

public java.lang.Object retrieveBean(java.lang.String name)
Returns a reference to a bean(model) in the actual HttpSession.

If no bean with the given name/identifyer is stored in the actual session, then it returns null.

Parameters:
name - the unique identifier of bean to be stored as session attribute.
Returns:
the reference to the bean stored as session attribute or null.

removeBean

public void removeBean(java.lang.String name)
Removes a reference to a bean (model) in the actual HttpSession.

Parameters:
name - the unique identifier of bean to be stored as session attribute.

getLastLogin

public java.lang.String getLastLogin()
Returns a String representing the user's last login date and originating host.

Returns:
the last login with date and originating host as String.

getMailSession

public javax.mail.Session getMailSession()
Returns this instances mailsession.

Returns:
this instances mailsession as javax.mail.Session.
See Also:
Session

getJwmaStore

public JwmaStoreImpl getJwmaStore()
Returns the actual mailsession's JwmaStoreImpl.

Returns:
the actual mailsession's store as JwmaStoreImpl
See Also:
JwmaStoreImpl

getJwmaTransport

public JwmaTransportImpl getJwmaTransport()
Returns the actual mailsession's JwmaTransportImpl.

Returns:
the actual mailsession's transport as JwmaTransportImpl
See Also:
JwmaTransportImpl

getMTA

public MailTransportAgent getMTA()

setMTA

public void setMTA(MailTransportAgent MTA)

getPostOffice

public PostOffice getPostOffice()

setPostOffice

public void setPostOffice(PostOffice office)

ensurePostOfficeConnection

public void ensurePostOfficeConnection()
                                throws JwmaException
Tests wheter a connection to the post office exists, throwing a JwmaException if not, thus it ensures that a connection to the post office exists.

Throws:
JwmaException - if there is no connection to the post office.

isPostOfficeConnected

public boolean isPostOfficeConnected()
Tests if this session has a connection to the post office.

Returns:
true if there is a connection, false otherwise.

setLocale

public void setLocale()
Sets the Locale of this Session to the one that is stored in the user's preferences.


getUserIdentity

public java.lang.String getUserIdentity(java.lang.String username)
Returns the assembled user's identity as String.

Parameters:
username - the user's name as String.
Returns:
the identifier is assembled like a standard email address using the set postoffice host.

getUserIdentity

public java.lang.String getUserIdentity()
Returns the assembled user's identity as String.

Returns:
the identifier assembled like a standard email address using the set username and hostname.

getUsername

public java.lang.String getUsername()
Returns the username associated with this JwmaSession.

Returns:
the name as String.

getPreferences

public JwmaPreferencesImpl getPreferences()
Returns the JwmaPreferencesImpl instance of this session instance's user.

Returns:
this session instance's user's preferences as JwmaPreferencesImpl.

savePreferences

public boolean savePreferences()
                        throws JwmaException
Saves the JwmaPreferencesImpl instance of this session instance's user. Note that the actual process of saving is delegated to the active PreferencesPersistencePlugin instance obtained from the kernel.

Returns:
true if saved properly, false otherwise.
JwmaException
See Also:
PreferencesPersistencePlugin.savePreferences(JwmaPreferencesImpl)

isAuthenticated

public boolean isAuthenticated()
Tests if this session is authenticated. If the session is flagged as authenticated, the initialization of the mail session worked successfully, and the user associated with this session could be authenticated against the post office.

Returns:
true if authenticated, false otherwise.

ensureAuthenticated

public void ensureAuthenticated()
                         throws JwmaException
Tests wheter this session is authenticated, throwing a JwmaException if not, thus ensuring an authenticated session.

Throws:
JwmaException - if the session is not authenticated.

isAdministrator

public boolean isAdministrator()
Tests if this session's associated user is an administrator.

Returns:
true if associated username represents an admin, false otherwise.

ensureAdministrator

public void ensureAdministrator()
                         throws JwmaException
Tests whether the user associated with this session is allowed to administrate jwma and throws a JwmaException if not, thus ensuring an administrative user.

Throws:
JwmaException - if the associated username is not an admin.

authenticate

public boolean authenticate(java.lang.String username,
                            java.lang.String password,
                            boolean newAccount)
                     throws JwmaException
Authenticates the given user by initializing the mail session, thus authenticating against the post office of this session. Note that the credentials (i.e. password) are not stored anywhere.

Parameters:
username - the name of this session's user as String.
password - the related credentials as String.
newAccount - a flag that denotes whether a jwma account already exists (false) or not (true).
Throws:
JwmaException - if initializing a mailsession or authenticating against the post office fails.

end

public void end()
Ends this session, by cleaning up user related data and resources. If the session is authenticated, then the new last login String is stored in the users preferences, before they are saved. Consequently the mail session is closed, and the bean references stored in this session are cleaned up.

See Also:
isAuthenticated(), savePreferences()

finalize

public void finalize()
Overrides the superclass method to call end().

Overrides:
finalize in class java.lang.Object
See Also:
end()

Jwma

Copyright © 2000-2003 jwma team (All Rights Reserved.)