You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jo...@apache.org on 2001/10/14 03:03:16 UTC

cvs commit: jakarta-turbine-3/src/java/org/apache/turbine/services/rundata DefaultTurbineRunData.java

jon         01/10/13 18:03:16

  Modified:    src/java/org/apache/turbine RunData.java
               src/java/org/apache/turbine/modules/actions
                        AccessController.java
               src/java/org/apache/turbine/services/rundata
                        DefaultTurbineRunData.java
  Log:
  a few fairly minor api modifications (nothing that will break backwards
  compatible code) to make storing the ACL the same as storing the User
  
  Revision  Changes    Path
  1.4       +18 -3     jakarta-turbine-3/src/java/org/apache/turbine/RunData.java
  
  Index: RunData.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/RunData.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RunData.java	2001/08/28 00:37:24	1.3
  +++ RunData.java	2001/10/14 01:03:16	1.4
  @@ -79,7 +79,7 @@
    * @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
    * @author <a href="mailto:bhoeneis@ee.ethz.ch">Bernie Hoeneisen</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  - * @version $Id: RunData.java,v 1.3 2001/08/28 00:37:24 dlr Exp $
  + * @version $Id: RunData.java,v 1.4 2001/10/14 01:03:16 jon Exp $
    */
   public interface RunData
   {
  @@ -241,6 +241,21 @@
       public boolean removeUserFromSession();
   
       /**
  +     * Attempts to get the ACL from the session. If it does
  +     * not exist, it returns null.
  +     *
  +     * @return a acl.
  +     */
  +    public AccessControlList getACLFromSession();
  +
  +    /**
  +     * Allows one to invalidate the acl in the default session.
  +     *
  +     * @return true if acl was invalidated.
  +     */
  +    public boolean removeACLFromSession();
  +
  +    /**
        * Gets the print writer. First time calling this
        * will set the print writer via the response.
        *
  @@ -393,13 +408,13 @@
       public String getUserAgent();
   
       /**
  -     * Pulls a user object from the session and increments the access
  +     * Pulls a user object and acl from the session and increments the access
        * counter and sets the last access date for the object.
        */
       public void populate();
   
       /**
  -     * Saves a user object into the session.
  +     * Saves a user object and acl into the session.
        */
       public void save();
   
  
  
  
  1.3       +5 -8      jakarta-turbine-3/src/java/org/apache/turbine/modules/actions/AccessController.java
  
  Index: AccessController.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/modules/actions/AccessController.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AccessController.java	2001/09/01 16:58:11	1.2
  +++ AccessController.java	2001/10/14 01:03:16	1.3
  @@ -91,7 +91,7 @@
    *
    * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
    * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
  - * @version $Id: AccessController.java,v 1.2 2001/09/01 16:58:11 jvanzyl Exp $
  + * @version $Id: AccessController.java,v 1.3 2001/10/14 01:03:16 jon Exp $
    */
   public class AccessController
       extends Action
  @@ -110,15 +110,12 @@
       public void doPerform( RunData data )
           throws Exception
       {
  -        if ( data.getUser() != null && data.getUser().hasLoggedIn() )
  +        if (data.getUser() != null && data.getUser().hasLoggedIn())
           {
  -            AccessControlList acl = (AccessControlList)
  -                data.getSession().getValue(AccessControlList.SESSION_KEY);
  -            if ( acl == null )
  +            AccessControlList acl = data.getACLFromSession();
  +            if (acl == null)
               {
  -                acl = TurbineSecurity.getACL( data.getUser() );
  -                data.getSession().putValue( AccessControlList.SESSION_KEY,
  -                                            (Object)acl );
  +                acl = TurbineSecurity.getACL(data.getUser());
               }
               data.setACL(acl);
           }
  
  
  
  1.4       +124 -63   jakarta-turbine-3/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java
  
  Index: DefaultTurbineRunData.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultTurbineRunData.java	2001/09/03 06:37:02	1.3
  +++ DefaultTurbineRunData.java	2001/10/14 01:03:16	1.4
  @@ -95,7 +95,7 @@
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    * @author <a href="mailto:bhoeneis@ee.ethz.ch">Bernie Hoeneisen</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  - * @version $Id: DefaultTurbineRunData.java,v 1.3 2001/09/03 06:37:02 dlr Exp $
  + * @version $Id: DefaultTurbineRunData.java,v 1.4 2001/10/14 01:03:16 jon Exp $
    */
   public class DefaultTurbineRunData
       extends RecyclableSupport
  @@ -299,62 +299,6 @@
       }
   
       /**
  -     * Attempts to get the User object from the session.  If the user
  -     * does not exist in the session, <code>null</code> is returned.
  -     *
  -     * <p> Anyone overriding this method should be sure to leverage
  -     * the <code>SessionBindingEventProxy</code> when pulling the
  -     * <code>User</code> object from the session, allowing hook
  -     * functions to be called on the listener when it is removed from
  -     * the session (which happens on session timeout).
  -     *
  -     * @param session The session to retrieve a <code>User</code>
  -     * object from.
  -     * @return The retreived user, or <code>null</code> if errors
  -     * occur.
  -     * @see org.apache.turbine.services.SessionBindingEventProxy
  -     * @see org.apache.fulcrum.security.entity.User
  -     * @see org.apache.fulcrum.session.SessionBindingListener
  -     */
  -    public static User getUserFromSession(HttpSession session)
  -    {
  -        try
  -        {
  -            SessionBindingEventProxy proxy =
  -                (SessionBindingEventProxy) session.getValue(User.SESSION_KEY);
  -
  -            // If the user isn't yet logged in, return null so that
  -            // the session validator can take the correct action
  -            // (i.e. make a temporary anonymous user).
  -            return (proxy == null ? null : (User) proxy.getListener());
  -        }
  -        catch ( ClassCastException e )
  -        {
  -            return null;
  -        }
  -    }
  -
  -    /**
  -     * Allows one to invalidate the user in a session.
  -     *
  -     * @param session An HttpSession.
  -     * @return True if user was invalidated.
  -     */
  -    public static boolean removeUserFromSession(HttpSession session)
  -    {
  -        try
  -        {
  -            session.removeValue(User.SESSION_KEY);
  -        }
  -        catch ( Exception e )
  -        {
  -            return false;
  -        }
  -        return true;
  -    }
  -
  -
  -    /**
        * Gets the default locale defined by properties named
        * "locale.default.lang" and "locale.default.country".
        *
  @@ -706,6 +650,99 @@
       }
   
       /**
  +     * Attempts to get the User object from the session.  If the user
  +     * does not exist in the session, <code>null</code> is returned.
  +     *
  +     * <p> Anyone overriding this method should be sure to leverage
  +     * the <code>SessionBindingEventProxy</code> when pulling the
  +     * <code>User</code> object from the session, allowing hook
  +     * functions to be called on the listener when it is removed from
  +     * the session (which happens on session timeout).
  +     *
  +     * @param session The session to retrieve a <code>User</code>
  +     * object from.
  +     * @return The retreived user, or <code>null</code> if errors
  +     * occur.
  +     * @see org.apache.turbine.services.SessionBindingEventProxy
  +     * @see org.apache.fulcrum.security.entity.User
  +     * @see org.apache.fulcrum.session.SessionBindingListener
  +     */
  +    public static User getUserFromSession(HttpSession session)
  +    {
  +        try
  +        {
  +            SessionBindingEventProxy proxy =
  +                (SessionBindingEventProxy) session.getValue(User.SESSION_KEY);
  +
  +            // If the user isn't yet logged in, return null so that
  +            // the session validator can take the correct action
  +            // (i.e. make a temporary anonymous user).
  +            return (proxy == null ? null : (User) proxy.getListener());
  +        }
  +        catch ( ClassCastException e )
  +        {
  +            return null;
  +        }
  +    }
  +
  +    /**
  +     * Allows one to invalidate the user in a session.
  +     *
  +     * @param session An HttpSession.
  +     * @return True if user was invalidated.
  +     */
  +    public static boolean removeUserFromSession(HttpSession session)
  +    {
  +        try
  +        {
  +            session.removeValue(User.SESSION_KEY);
  +        }
  +        catch ( Exception e )
  +        {
  +            return false;
  +        }
  +        return true;
  +    }
  +
  +    /**
  +     * Retrieves the ACL from the session
  +     */
  +    public static AccessControlList getACLFromSession(HttpSession session)
  +    {
  +        try
  +        {
  +            AccessControlList acl = (AccessControlList)
  +                session.getValue(AccessControlList.SESSION_KEY);
  +
  +            // If the acl isn't yet defined, return null
  +            return (acl == null ? null : acl);
  +        }
  +        catch ( ClassCastException e )
  +        {
  +            return null;
  +        }
  +    }
  +
  +    /**
  +     * Allows one to invalidate the acl in a session.
  +     *
  +     * @param session An HttpSession.
  +     * @return True if acl was invalidated.
  +     */
  +    public static boolean removeACLFromSession(HttpSession session)
  +    {
  +        try
  +        {
  +            session.removeValue(AccessControlList.SESSION_KEY);
  +        }
  +        catch ( Exception e )
  +        {
  +            return false;
  +        }
  +        return true;
  +    }
  +
  +    /**
        * Attempts to get the user from the session. If it does
        * not exist, it returns null.
        *
  @@ -727,6 +764,27 @@
       }
   
       /**
  +     * Attempts to get the ACL from the session. If it does
  +     * not exist, it returns null.
  +     *
  +     * @return a acl.
  +     */
  +    public AccessControlList getACLFromSession()
  +    {
  +        return getACLFromSession(session);
  +    }
  +
  +    /**
  +     * Allows one to invalidate the acl in the default session.
  +     *
  +     * @return true if acl was invalidated.
  +     */
  +    public boolean removeACLFromSession()
  +    {
  +        return removeACLFromSession(session);
  +    }
  +
  +    /**
        * Gets the print writer. First time calling this
        * will set the print writer via the response.
        *
  @@ -995,7 +1053,7 @@
       }
   
       /**
  -     * Pulls a user object from the session and increments the access
  +     * Pulls a user and ACL object from the session and increments the access
        * counter and sets the last access date for the object.
        */
       public void populate()
  @@ -1011,22 +1069,25 @@
       }
   
       /**
  -     * <p>Saves this user object to the session.</p>
  +     * <p>Saves this user object and ACL to the session.</p>
        *
        * <p>Anyone overriding this method should be sure to leverage
        * the <code>SessionBindingEventProxy</code> when adding the user
  -     * into the session.  This allows hook functions to be called on
  -     * the <code>User</code> when it is removed from the session
  -     * (which happens on session timeout).</p>
  +     * and acl into the session.  This allows hook functions to be called on
  +     * the <code>User</code> and <code>AccessControlList</code> when it is 
  +     * removed from the session (which happens on session timeout).</p>
        *
  -     * @see #setUser(User user)
  +     * @see #setUser(User)
  +     * @see #setAcl(AccessControlList)
        * @see org.apache.turbine.services.SessionBindingEventProxy
        * @see org.apache.fulcrum.security.entity.User
  +     * @see org.apache.fulcrum.security.util.AccessControlList
        * @see org.apache.fulcrum.session.SessionBindingListener
        */
       public void save()
       {
           session.putValue(User.SESSION_KEY, new SessionBindingEventProxy(user));
  +        session.putValue(AccessControlList.SESSION_KEY, (Object) acl);
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org