HiRISE

HiRISE.HiWish
Class HiWishAction

java.lang.Object
  extended by org.apache.struts.action.Action
      extended by org.apache.struts.actions.BaseAction
          extended by org.apache.struts.actions.DispatchAction
              extended by HiRISE.HiWish.HiWishAction
Direct Known Subclasses:
CastSuggestionAction, ChangeEmailAction, ChangePasswordAction, ConfirmAction, EditSelfAction, FootprintSearchAction, LocateAction, LoginAction, NewSuggestionAction, PreviewSuggestionAction, RegisterAction, RememberAction, ResetPasswordAction, ShowQuotaAction, SuggestionSearchAction, UpdateSelfAction, ViewSuggestionAction

public abstract class HiWishAction
extends org.apache.struts.actions.DispatchAction

Base class for actions that perform queries of the database or other common functions.

Version:
1.11

Field Summary
static String ID
          CVS ID
protected static Logger logger
          Logger instance
 
Fields inherited from class org.apache.struts.actions.DispatchAction
clazz, log, methods, types
 
Fields inherited from class org.apache.struts.actions.BaseAction
messages
 
Fields inherited from class org.apache.struts.action.Action
servlet
 
Constructor Summary
HiWishAction()
           
 
Method Summary
 void closeConnection(Connection conn)
          Close a connection safely.
 String generateSecureToken(javax.servlet.http.HttpServletRequest req)
          The generateToken method of the base Struts action class, as implemented in 1.3.8, returns an MD5 on the current time.
 Connection getConnection(String host)
          Obtain a new database connection.
 String getContextURL(javax.servlet.http.HttpServletRequest req)
          Get the URL for a request ending with the application context path.
 String getContextVariable(String key, String host)
           
 Session getMailSession()
          Obtain a Mail session
 int getWishQuota()
          Load the value of the wish quota from the configuration
 void memorizeUser(String digest, User user)
          Cache a user.
 User rememberUser(String digest)
          Lookup a user using the digested password.
protected  org.apache.struts.action.ActionMessages sendEmail(String recipient, String subject, String content)
          Send an email and handle errors by returning appropriate ActionMessages
 String sha1hex(String... inputs)
          Digests Strings and returns the SHA1 hash as hex.
 
Methods inherited from class org.apache.struts.actions.DispatchAction
cancelled, dispatchMethod, execute, getMethod, getMethodName, getParameter, unspecified
 
Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final String ID
CVS ID

See Also:
Constant Field Values

logger

protected static Logger logger
Logger instance

Constructor Detail

HiWishAction

public HiWishAction()
Method Detail

rememberUser

public User rememberUser(String digest)
Lookup a user using the digested password.

Parameters:
digest - The digested password
Returns:
User instance if found, null if not

memorizeUser

public void memorizeUser(String digest,
                         User user)
Cache a user. When the application or server is restarted, the cache will be emptied.

Parameters:
digest - The digested password (key)
user - User object (value)

getConnection

public Connection getConnection(String host)
                         throws SQLException,
                                NamingException
Obtain a new database connection.

Parameters:
host - server name
Returns:
JDBC connection
Throws:
SQLException - Could not create new connection
NamingException - Could not locate JNDI reference

getContextVariable

public String getContextVariable(String key,
                                 String host)
                          throws NamingException
Throws:
NamingException

closeConnection

public void closeConnection(Connection conn)
Close a connection safely. If the connection cannot be closed, an error message is logged.

Parameters:
conn - JDBC connection (not necessarily open)

getMailSession

public Session getMailSession()
                       throws NamingException
Obtain a Mail session

Returns:
JavaMail session
Throws:
NamingException - Could not locate JNDI reference

sha1hex

public String sha1hex(String... inputs)
               throws NoSuchAlgorithmException
Digests Strings and returns the SHA1 hash as hex.

Parameters:
inputs - One or more Strings to digest
Returns:
Digested strings in hex hash
Throws:
NoSuchAlgorithmException - Could not find algorithm

generateSecureToken

public String generateSecureToken(javax.servlet.http.HttpServletRequest req)
                           throws NoSuchAlgorithmException
The generateToken method of the base Struts action class, as implemented in 1.3.8, returns an MD5 on the current time. This is adequate for non-secure tokens, such as detecting double form submits. This method provides a more secure token based on the HttpSession ID. It does not put the token in the session. So the token should be unguessable and undiscoverable.

Parameters:
req - The request
Returns:
The token in hex string format
Throws:
NoSuchAlgorithmException - AlGore didn't invent it yet

getContextURL

public String getContextURL(javax.servlet.http.HttpServletRequest req)
Get the URL for a request ending with the application context path. TODO This is kind-of ridiculous, is there no existing method?

Parameters:
req - The request
Returns:
Base URL starting with protocol and ending with application context path.

getWishQuota

public int getWishQuota()
Load the value of the wish quota from the configuration

Returns:
number of wishes per day

sendEmail

protected org.apache.struts.action.ActionMessages sendEmail(String recipient,
                                                            String subject,
                                                            String content)
                                                     throws NamingException
Send an email and handle errors by returning appropriate ActionMessages

Parameters:
recipient - The email address to send the confirmation to
subject - The subject of the email message
content - The body of the email, which should include a confirmation link
Returns:
null if there are no delivery errors, or an ActionMessages object with any errors related to the email
Throws:
NamingException

HiRISE

Copyright (C) Arizona Board of Regents on behalf of the Planetary Image Research Laboratory, Lunar and Planetary Laboratory at the University of Arizona