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  import org.mule.api.security.SecurityContextFactory;
12  
13  import org.springframework.security.core.context.SecurityContextHolder;
14  import org.springframework.security.core.context.SecurityContextImpl;
15  
16  
17  /**
18   * <code>AcegiSecurityContextFactory</code> creates an AcegiSecurityContext for an
19   * Authentication object
20   */
21  public class SpringSecurityContextFactory implements SecurityContextFactory
22  {
23      public SecurityContext create(Authentication authentication)
24      {
25          org.springframework.security.core.context.SecurityContext context = new SecurityContextImpl();        
26          context.setAuthentication(((SpringAuthenticationAdapter)authentication).getDelegate());
27  
28          if (authentication.getProperties() != null)
29          {
30              if ((authentication.getProperties().containsKey("securityMode")))
31              {
32                  SecurityContextHolder.setStrategyName((String)authentication.getProperties().get(
33                      "securityMode"));
34              }
35          }
36          SecurityContextHolder.setContext(context);
37          return new SpringSecurityContext(context);
38      }
39  }