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.security;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.endpoint.InboundEndpoint;
11  import org.mule.api.lifecycle.InitialisationException;
12  import org.mule.api.security.AuthenticationFilter;
13  import org.mule.api.security.CredentialsAccessor;
14  import org.mule.api.security.CryptoFailureException;
15  import org.mule.api.security.EncryptionStrategyNotFoundException;
16  import org.mule.api.security.SecurityException;
17  import org.mule.api.security.SecurityProviderNotFoundException;
18  import org.mule.api.security.UnknownAuthenticationTypeException;
19  
20  /**
21   * <code>AbstractEndpointSecurityFilter</code> provides a framework to perform inbound
22   * or outbound authentication for messages.
23   */
24  public abstract class AbstractAuthenticationFilter extends AbstractSecurityFilter implements AuthenticationFilter
25  {
26      private boolean authenticate;
27      private CredentialsAccessor credentialsAccessor;
28  
29      public CredentialsAccessor getCredentialsAccessor()
30      {
31          return credentialsAccessor;
32      }
33  
34      public void setCredentialsAccessor(CredentialsAccessor credentialsAccessor)
35      {
36          this.credentialsAccessor = credentialsAccessor;
37      }
38      public boolean isAuthenticate()
39      {
40          return authenticate;
41      }
42  
43      public void setAuthenticate(boolean authenticate)
44      {
45          this.authenticate = authenticate;
46      }
47  
48      @Override
49      public void doFilter(MuleEvent event)
50          throws SecurityException, UnknownAuthenticationTypeException, CryptoFailureException,
51          SecurityProviderNotFoundException, EncryptionStrategyNotFoundException, InitialisationException
52      {
53          authenticate(event);
54      }
55  
56      public void authenticate(MuleEvent event)
57              throws SecurityException, UnknownAuthenticationTypeException, CryptoFailureException,
58              SecurityProviderNotFoundException, EncryptionStrategyNotFoundException,
59              InitialisationException
60      {
61          if (event.getEndpoint() instanceof InboundEndpoint)
62          {
63              authenticateInbound(event);
64          }
65          else
66          {
67              authenticateOutbound(event);
68          }
69      }
70  
71      protected abstract void authenticateInbound(MuleEvent event)
72              throws SecurityException, CryptoFailureException, SecurityProviderNotFoundException,
73              EncryptionStrategyNotFoundException, UnknownAuthenticationTypeException;
74  
75      protected abstract void authenticateOutbound(MuleEvent event)
76              throws SecurityException, SecurityProviderNotFoundException, CryptoFailureException;
77  
78  }