Coverage Report - org.mule.example.notifications.DummySecurityFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
DummySecurityFilter
0%
0/16
0%
0/4
0
 
 1  
 /*
 2  
  * $Id: DummySecurityFilter.java 20321 2010-11-24 15:21:24Z dfeist $
 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  
 package org.mule.example.notifications;
 11  
 
 12  
 import org.mule.api.MuleEvent;
 13  
 import org.mule.api.lifecycle.InitialisationException;
 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.UnauthorisedException;
 19  
 import org.mule.api.security.UnknownAuthenticationTypeException;
 20  
 import org.mule.config.i18n.CoreMessages;
 21  
 import org.mule.security.AbstractEndpointSecurityFilter;
 22  
 import org.mule.transformer.types.DataTypeFactory;
 23  
 
 24  
 import java.util.Map;
 25  
 
 26  
 /**
 27  
  * TODO
 28  
  */
 29  0
 public class DummySecurityFilter extends AbstractEndpointSecurityFilter
 30  
 {
 31  
     @Override
 32  
     protected void authenticateInbound(MuleEvent event) throws org.mule.api.security.SecurityException, CryptoFailureException, SecurityProviderNotFoundException, EncryptionStrategyNotFoundException, UnknownAuthenticationTypeException
 33  
     {
 34  0
         doAuthenticate(event);
 35  0
     }
 36  
 
 37  
     @Override
 38  
     protected void authenticateOutbound(MuleEvent event) throws SecurityException, SecurityProviderNotFoundException, CryptoFailureException
 39  
     {
 40  0
         doAuthenticate(event);
 41  0
     }
 42  
 
 43  
     protected void doAuthenticate(MuleEvent event) throws UnauthorisedException
 44  
     {
 45  
         try
 46  
         {
 47  0
             Map<?, ?> payload = event.getMessage().getPayload(DataTypeFactory.create(Map.class));
 48  0
             String user = (String) payload.get("user");
 49  0
             if (user == null)
 50  
             {
 51  0
                 throw new UnauthorisedException(CoreMessages.authNoCredentials());
 52  
             }
 53  0
             if ("anonymous".equals(user))
 54  
             {
 55  0
                 throw new UnauthorisedException(CoreMessages.authFailedForUser("anonymous"));
 56  
             }
 57  
         }
 58  0
         catch (Exception e)
 59  
         {
 60  0
             throw new UnauthorisedException(CoreMessages.authFailedForUser("anonymous"), e);
 61  0
         }
 62  
 
 63  0
     }
 64  
 
 65  
     @Override
 66  
     protected void doInitialise() throws InitialisationException
 67  
     {
 68  
         // nothing to do
 69  0
     }
 70  
 }