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