Coverage Report - org.restafarian.core.security.SessionBasedUserManager
 
Classes in this File Line Coverage Branch Coverage Complexity
SessionBasedUserManager
0%
0/9
0%
0/2
1.333
 
 1  
 package org.restafarian.core.security;
 2  
 
 3  
 import javax.servlet.ServletContext;
 4  
 import javax.servlet.http.HttpServletRequest;
 5  
 import javax.servlet.http.HttpServletResponse;
 6  
 
 7  
 import org.apache.commons.configuration.Configuration;
 8  
 import org.apache.commons.logging.Log;
 9  
 import org.apache.commons.logging.LogFactory;
 10  
 import org.restafarian.core.beans.Person;
 11  
 
 12  
 /**
 13  
  * <p>This module finds and returns the currently authenticated user
 14  
  * by returning the user stored in the session object.</p>
 15  
  */
 16  0
 public class SessionBasedUserManager implements UserManager {
 17  
         private static final String AUTHENTICATED_USER = "authenticatedUser";
 18  0
         private Log log = LogFactory.getLog(getClass());
 19  
 
 20  
         /**
 21  
          * <p>Initializes the module using the configuration.</p>
 22  
          *
 23  
          * @param context the <code>ServletContext</code> object
 24  
          * @param config the <code>Configuration</code> object
 25  
          */
 26  
         public void init(ServletContext context, Configuration config) {
 27  0
                 log.info("Initializing the SessionBasedUserManager.");
 28  0
         }
 29  
 
 30  
         /**
 31  
          * <p>Returns the currently authenticated user, or null, if there is
 32  
          * no user currently authenticated.</p>
 33  
          *
 34  
          * @param req the <code>HttpServletRequest</code> object
 35  
          * @return the currently authenticated user
 36  
          */
 37  
         public Person getAuthenticatedUser(HttpServletRequest req) {
 38  0
                 return (Person) req.getSession().getAttribute(AUTHENTICATED_USER);
 39  
         }
 40  
 
 41  
         /**
 42  
          * <p>Sets the currently authenticated user.</p>
 43  
          *
 44  
          * @param req the <code>HttpServletRequest</code> object
 45  
          * @param res the <code>HttpServletResponse</code> object
 46  
          * @param user the currently authenticated user
 47  
          */
 48  
         public void setAuthenticatedUser(HttpServletRequest req, HttpServletResponse res, Person user) {
 49  0
                 if (user != null) {
 50  0
                         req.getSession().setAttribute(AUTHENTICATED_USER, user);
 51  
                 } else {
 52  0
                         req.getSession().removeAttribute(AUTHENTICATED_USER);
 53  
                 }
 54  0
         }
 55  
 }