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.spring.security;
8   
9   import org.mule.api.security.Authentication;
10  import org.mule.api.security.SecurityContext;
11  
12  import org.springframework.security.core.context.SecurityContextHolder;
13  
14  
15  /**
16   * <code>AcegiSecurityContext</code> is a SecurityContext wrapper used to
17   * interface with an Acegi SecurityContext
18   */
19  
20  public class SpringSecurityContext implements SecurityContext
21  {
22      private org.springframework.security.core.context.SecurityContext delegate;
23      private SpringAuthenticationAdapter authentication;
24  
25      public SpringSecurityContext(org.springframework.security.core.context.SecurityContext delegate)
26      
27      {
28          this.delegate = delegate;
29          SecurityContextHolder.setContext(this.delegate);
30      }
31  
32      public void setAuthentication(Authentication authentication)
33      {
34          this.authentication = ((SpringAuthenticationAdapter)authentication);
35          delegate.setAuthentication(this.authentication.getDelegate());
36          SecurityContextHolder.setContext(delegate);
37      }
38  
39      public Authentication getAuthentication()
40      {
41          return this.authentication;
42      }
43  }