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