View Javadoc

1   /*
2    * $Id: AcegiSecurityContextFactory.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.extras.acegi;
12  
13  import org.mule.umo.security.UMOAuthentication;
14  import org.mule.umo.security.UMOSecurityContext;
15  import org.mule.umo.security.UMOSecurityContextFactory;
16  
17  import org.acegisecurity.context.SecurityContext;
18  import org.acegisecurity.context.SecurityContextHolder;
19  import org.acegisecurity.context.SecurityContextImpl;
20  
21  /**
22   * <code>AcegiSecurityContextFactory</code> creates an AcegiSecurityContext for an
23   * UMOAuthentication object
24   */
25  public class AcegiSecurityContextFactory implements UMOSecurityContextFactory
26  {
27      public UMOSecurityContext create(UMOAuthentication authentication)
28      {
29          SecurityContext context = new SecurityContextImpl();
30          context.setAuthentication(((AcegiAuthenticationAdapter)authentication).getDelegate());
31  
32          if (authentication.getProperties() != null)
33          {
34              if ((authentication.getProperties().containsKey("securityMode")))
35              {
36                  SecurityContextHolder.setStrategyName((String)authentication.getProperties().get(
37                      "securityMode"));
38              }
39          }
40          SecurityContextHolder.setContext(context);
41          return new AcegiSecurityContext(context);
42      }
43  }