portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlest...@apache.org
Subject cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/security/impl SecurityValveImpl.java
Date Sun, 23 May 2004 20:54:04 GMT
dlestrat    2004/05/23 13:54:04

  Modified:    portal/src/java/org/apache/jetspeed/security/impl
                        SecurityValveImpl.java
  Log:
  Leverage security service to populate subject.
  
  Revision  Changes    Path
  1.5       +34 -24    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/security/impl/SecurityValveImpl.java
  
  Index: SecurityValveImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/security/impl/SecurityValveImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SecurityValveImpl.java	8 Mar 2004 00:33:22 -0000	1.4
  +++ SecurityValveImpl.java	23 May 2004 20:54:04 -0000	1.5
  @@ -23,12 +23,16 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +
   import org.apache.jetspeed.Jetspeed;
   import org.apache.jetspeed.pipeline.PipelineException;
   import org.apache.jetspeed.pipeline.valve.AbstractValve;
   import org.apache.jetspeed.pipeline.valve.ValveContext;
   import org.apache.jetspeed.profiler.Profiler;
   import org.apache.jetspeed.request.RequestContext;
  +import org.apache.jetspeed.security.SecurityHelper;
  +import org.apache.jetspeed.security.UserManager;
  +import org.apache.jetspeed.security.UserPrincipal;
   
   /**
    * SecurityValve
  @@ -36,53 +40,59 @@
    * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
    * @version $Id$
    */
  -public class SecurityValveImpl
  -    extends AbstractValve
  -    implements org.apache.jetspeed.pipeline.valve.SecurityValve
  +public class SecurityValveImpl extends AbstractValve implements org.apache.jetspeed.pipeline.valve.SecurityValve
   {
  -    private static final Log log = LogFactory.getLog( SecurityValveImpl.class );
  -     
  -    /* (non-Javadoc)
  +    private static final Log log = LogFactory.getLog(SecurityValveImpl.class);
  +
  +    /**
        * @see org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext,
org.apache.jetspeed.pipeline.valve.ValveContext)
        */
  -    public void invoke(RequestContext request, ValveContext context)
  -        throws PipelineException
  +    public void invoke(RequestContext request, ValveContext context) throws PipelineException
       {
           try
  -        {        
  -            Profiler profiler = (Profiler)Jetspeed.getComponentManager().getComponent(Profiler.class);
  -            
  -            // simple place holder, waiting on security service impl       
  +        {
  +            Profiler profiler = (Profiler) Jetspeed.getComponentManager().getComponent(Profiler.class);
  +            UserManager userMgr = (UserManager) Jetspeed.getComponentManager().getComponent(UserManager.class);
  +
               Principal principal = request.getRequest().getUserPrincipal();
  -            Subject subject = (Subject)
  -                request.getRequest().getSession().getAttribute(this.getClass().toString()
+ ".subject");
  +            Subject subject = (Subject) request.getRequest().getSession().getAttribute(this.getClass().toString()
+ ".subject");
  +            if (null == principal)
  +            {
  +                principal = new UserPrincipalImpl(profiler.getAnonymousUser());
  +            }
               if (null == subject)
               {
                   Set principals = new HashSet();
  -                if (principal == null)
  -                {
  -                    principal = new UserPrincipalImpl(profiler.getAnonymousUser());
  -                }                
                   principals.add(principal);
                   subject = new Subject(true, principals, new HashSet(), new HashSet());
                   request.getRequest().getSession().setAttribute(this.getClass().toString()
+ ".subject", subject);
               }
  +            else
  +            {
  +                Principal userPrincipal = SecurityHelper.getPrincipal(subject, UserPrincipal.class);
  +                if ((userPrincipal.getName()).equals(profiler.getAnonymousUser())
  +                    && (!(principal.getName()).equals(profiler.getAnonymousUser())))
  +                {
  +                    subject = userMgr.getUser(principal.getName()).getSubject();
  +                    request.getRequest().getSession().setAttribute(this.getClass().toString()
+ ".subject", subject);
  +                }
  +            }
               request.setSubject(subject);
           }
           catch (Throwable t)
           {
               // TODO: valve exception handling formalized
  -            t.printStackTrace();            
  +            t.printStackTrace();
           }
  -            
  +
           // Pass control to the next Valve in the Pipeline
  -        context.invokeNext( request );
  -        
  +        context.invokeNext(request);
  +
       }
   
       public String toString()
       {
           return "SecurityValve";
       }
  -    
  +
   }
  
  
  

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


Mime
View raw message