View Javadoc

1   /*
2    * $Id: AbstractSecurityProvider.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.security;
12  
13  import org.mule.api.NamedObject;
14  import org.mule.api.lifecycle.InitialisationException;
15  import org.mule.api.security.Authentication;
16  import org.mule.api.security.SecurityContext;
17  import org.mule.api.security.SecurityContextFactory;
18  import org.mule.api.security.SecurityProvider;
19  import org.mule.api.security.UnknownAuthenticationTypeException;
20  
21  
22  public abstract class AbstractSecurityProvider implements SecurityProvider, NamedObject
23  {
24      private String name;
25      private SecurityContextFactory securityContextFactory;
26  
27      public AbstractSecurityProvider(String name)
28      {
29          this.name = name;
30      }
31  
32      public final void initialise() throws InitialisationException
33      {
34          doInitialise();
35          
36          if (securityContextFactory == null)
37          {
38              securityContextFactory = new DefaultSecurityContextFactory();
39          }
40      }
41  
42      protected void doInitialise() throws InitialisationException
43      {
44          // do nothing by default
45      }
46      
47      public boolean supports(Class aClass)
48      {
49          return Authentication.class.isAssignableFrom(aClass);
50      }
51  
52      public SecurityContext createSecurityContext(Authentication authentication)
53          throws UnknownAuthenticationTypeException
54      {
55          return securityContextFactory.create(authentication);
56      }
57  
58      public String getName()
59      {
60          return name;
61      }
62  
63      public void setName(String name)
64      {
65          this.name = name;
66      }
67  
68      public SecurityContextFactory getSecurityContextFactory()
69      {
70          return securityContextFactory;
71      }
72  
73      public void setSecurityContextFactory(SecurityContextFactory securityContextFactory)
74      {
75          this.securityContextFactory = securityContextFactory;
76      }
77  }