View Javadoc

1   /*
2    * $Id: AcegiSecurityContext.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.module.acegi;
12  
13  import org.mule.api.security.Authentication;
14  import org.mule.api.security.SecurityContext;
15  
16  import org.acegisecurity.context.SecurityContextHolder;
17  
18  /**
19   * <code>AcegiSecurityContext</code> is a SecurityContext wrapper used to
20   * interface with an Acegi SecurityContext
21   */
22  
23  public class AcegiSecurityContext implements SecurityContext
24  {
25      private org.acegisecurity.context.SecurityContext delegate;
26      private AcegiAuthenticationAdapter authentication;
27  
28      public AcegiSecurityContext(org.acegisecurity.context.SecurityContext delegate)
29      {
30          this.delegate = delegate;
31          SecurityContextHolder.setContext(this.delegate);
32      }
33  
34      public void setAuthentication(Authentication authentication)
35      {
36          this.authentication = ((AcegiAuthenticationAdapter)authentication);
37          delegate.setAuthentication(this.authentication.getDelegate());
38          SecurityContextHolder.setContext(delegate);
39      }
40  
41      public Authentication getAuthentication()
42      {
43          return this.authentication;
44      }
45  }