View Javadoc

1   /*
2    * $Id: AcegiSecurityContext.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.extras.acegi;
12  
13  import org.mule.umo.security.UMOAuthentication;
14  import org.mule.umo.security.UMOSecurityContext;
15  
16  import org.acegisecurity.context.SecurityContext;
17  import org.acegisecurity.context.SecurityContextHolder;
18  
19  /**
20   * <code>AcegiSecurityContext</code> is a UMOSecurityContext wrapper used to
21   * interface with an Acegi SecurityContext
22   */
23  
24  public class AcegiSecurityContext implements UMOSecurityContext
25  {
26      private SecurityContext delegate;
27      private AcegiAuthenticationAdapter authentication;
28  
29      public AcegiSecurityContext(SecurityContext delegate)
30      {
31          this.delegate = delegate;
32          SecurityContextHolder.setContext(this.delegate);
33      }
34  
35      public void setAuthentication(UMOAuthentication authentication)
36      {
37          this.authentication = ((AcegiAuthenticationAdapter)authentication);
38          delegate.setAuthentication(this.authentication.getDelegate());
39          SecurityContextHolder.setContext(delegate);
40      }
41  
42      public UMOAuthentication getAuthentication()
43      {
44          return this.authentication;
45      }
46  }