Coverage Report - org.mule.impl.security.AbstractEndpointSecurityFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractEndpointSecurityFilter
0%
0/44
0%
0/18
1.867
 
 1  
 /*
 2  
  * $Id: AbstractEndpointSecurityFilter.java 7963 2007-08-21 08:53:15Z 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.impl.security;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.config.i18n.CoreMessages;
 15  
 import org.mule.umo.UMOEvent;
 16  
 import org.mule.umo.endpoint.UMOEndpoint;
 17  
 import org.mule.umo.endpoint.UMOImmutableEndpoint;
 18  
 import org.mule.umo.lifecycle.InitialisationException;
 19  
 import org.mule.umo.security.CryptoFailureException;
 20  
 import org.mule.umo.security.EncryptionStrategyNotFoundException;
 21  
 import org.mule.umo.security.SecurityException;
 22  
 import org.mule.umo.security.SecurityProviderNotFoundException;
 23  
 import org.mule.umo.security.UMOCredentialsAccessor;
 24  
 import org.mule.umo.security.UMOEndpointSecurityFilter;
 25  
 import org.mule.umo.security.UMOSecurityManager;
 26  
 import org.mule.umo.security.UMOSecurityProvider;
 27  
 import org.mule.umo.security.UnknownAuthenticationTypeException;
 28  
 import org.mule.util.StringUtils;
 29  
 
 30  
 import org.apache.commons.logging.Log;
 31  
 import org.apache.commons.logging.LogFactory;
 32  
 
 33  
 /**
 34  
  * <code>AbstractEndpointSecurityFilter</code> provides basic initialisation for
 35  
  * all security filters, namely configuring the SecurityManager for this instance
 36  
  */
 37  
 
 38  0
 public abstract class AbstractEndpointSecurityFilter implements UMOEndpointSecurityFilter
 39  
 {
 40  
     /**
 41  
      * logger used by this class
 42  
      */
 43  0
     protected transient Log logger = LogFactory.getLog(getClass());
 44  
 
 45  
     private UMOSecurityManager securityManager;
 46  
     private String securityProviders;
 47  
     private UMOImmutableEndpoint endpoint;
 48  0
     private boolean inbound = false;
 49  
     private boolean authenticate;
 50  
     private UMOCredentialsAccessor credentialsAccessor;
 51  
 
 52  
     public final void initialise() throws InitialisationException
 53  
     {
 54  0
         if (securityManager == null)
 55  
         {
 56  0
             securityManager = MuleManager.getInstance().getSecurityManager();
 57  
         }
 58  0
         if (securityManager == null)
 59  
         {
 60  0
             throw new InitialisationException(CoreMessages.authSecurityManagerNotSet(), this);
 61  
         }
 62  0
         if (endpoint == null)
 63  
         {
 64  0
             throw new InitialisationException(CoreMessages.objectIsNull("Endpoint"), this);
 65  
         }
 66  
         // This filter may only allow authentication on a subset of registered
 67  
         // security providers
 68  0
         if (securityProviders != null)
 69  
         {
 70  0
             UMOSecurityManager localManager = new MuleSecurityManager();
 71  0
             String[] sp = StringUtils.splitAndTrim(securityProviders, ",");
 72  0
             for (int i = 0; i < sp.length; i++)
 73  
             {
 74  0
                 UMOSecurityProvider provider = securityManager.getProvider(sp[i]);
 75  0
                 if (provider != null)
 76  
                 {
 77  0
                     localManager.addProvider(provider);
 78  
                 }
 79  
                 else
 80  
                 {
 81  0
                     throw new InitialisationException(
 82  
                         CoreMessages.objectNotRegisteredWithManager(
 83  
                             "Security Provider '" + sp[i] + "'"), this);
 84  
                 }
 85  
             }
 86  0
             securityManager = localManager;
 87  
         }
 88  0
         if (endpoint.getType().equals(UMOEndpoint.ENDPOINT_TYPE_RECEIVER))
 89  
         {
 90  0
             inbound = true;
 91  
         }
 92  0
         else if (endpoint.getType().equals(UMOEndpoint.ENDPOINT_TYPE_SENDER))
 93  
         {
 94  0
             inbound = false;
 95  
         }
 96  
         else
 97  
         {
 98  0
             throw new InitialisationException(
 99  
                 CoreMessages.authEndpointTypeForFilterMustBe(
 100  
                     UMOEndpoint.ENDPOINT_TYPE_SENDER + " or " + UMOEndpoint.ENDPOINT_TYPE_RECEIVER,
 101  
                     endpoint.getType()), this);
 102  
         }
 103  0
         doInitialise();
 104  0
     }
 105  
 
 106  
     public boolean isAuthenticate()
 107  
     {
 108  0
         return authenticate;
 109  
     }
 110  
 
 111  
     public void setAuthenticate(boolean authenticate)
 112  
     {
 113  0
         this.authenticate = authenticate;
 114  0
     }
 115  
 
 116  
     /**
 117  
      * @param manager
 118  
      */
 119  
     public void setSecurityManager(UMOSecurityManager manager)
 120  
     {
 121  0
         securityManager = manager;
 122  0
     }
 123  
 
 124  
     public UMOSecurityManager getSecurityManager()
 125  
     {
 126  0
         return securityManager;
 127  
     }
 128  
 
 129  
     public String getSecurityProviders()
 130  
     {
 131  0
         return securityProviders;
 132  
     }
 133  
 
 134  
     public void setSecurityProviders(String providers)
 135  
     {
 136  0
         securityProviders = providers;
 137  0
     }
 138  
 
 139  
     public UMOImmutableEndpoint getEndpoint()
 140  
     {
 141  0
         return endpoint;
 142  
     }
 143  
 
 144  
     public void setEndpoint(UMOImmutableEndpoint endpoint)
 145  
     {
 146  0
         this.endpoint = endpoint;
 147  0
     }
 148  
 
 149  
     public void authenticate(UMOEvent event)
 150  
         throws SecurityException, UnknownAuthenticationTypeException, CryptoFailureException,
 151  
         SecurityProviderNotFoundException, EncryptionStrategyNotFoundException
 152  
     {
 153  0
         if (inbound)
 154  
         {
 155  0
             authenticateInbound(event);
 156  
         }
 157  
         else
 158  
         {
 159  0
             authenticateOutbound(event);
 160  
         }
 161  0
     }
 162  
 
 163  
     public UMOCredentialsAccessor getCredentialsAccessor()
 164  
     {
 165  0
         return credentialsAccessor;
 166  
     }
 167  
 
 168  
     public void setCredentialsAccessor(UMOCredentialsAccessor credentialsAccessor)
 169  
     {
 170  0
         this.credentialsAccessor = credentialsAccessor;
 171  0
     }
 172  
 
 173  
     protected abstract void authenticateInbound(UMOEvent event)
 174  
         throws SecurityException, CryptoFailureException, SecurityProviderNotFoundException,
 175  
         EncryptionStrategyNotFoundException, UnknownAuthenticationTypeException;
 176  
 
 177  
     protected abstract void authenticateOutbound(UMOEvent event)
 178  
         throws SecurityException, SecurityProviderNotFoundException, CryptoFailureException;
 179  
 
 180  
     protected abstract void doInitialise() throws InitialisationException;
 181  
 
 182  
 }