View Javadoc

1   /*
2    * $Id: DummySecurityFilter.java 22366 2011-07-11 05:40:27Z dirk.olmes $
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.security.UnauthorisedException;
14  import org.mule.api.transformer.TransformerException;
15  import org.mule.config.i18n.CoreMessages;
16  import org.mule.security.AbstractAuthenticationFilter;
17  import org.mule.transformer.types.DataTypeFactory;
18  
19  import java.util.Map;
20  
21  /**
22   * TODO
23   */
24  public class DummySecurityFilter extends AbstractAuthenticationFilter
25  {
26      @Override
27      public void authenticate(MuleEvent event) throws UnauthorisedException
28      {
29          try
30          {
31              Map<?, ?> payload = event.getMessage().getPayload(DataTypeFactory.create(Map.class));
32              String user = (String) payload.get("user");
33              if (user == null)
34              {
35                  throw new UnauthorisedException(CoreMessages.authNoCredentials(), event);
36              }
37              if ("anonymous".equals(user))
38              {
39                  throw new UnauthorisedException(CoreMessages.authFailedForUser("anonymous"), event);
40              }
41          }
42          catch (TransformerException te)
43          {
44              throw new UnauthorisedException(CoreMessages.transformFailed("Object", "Map"), event, te);
45          }
46      }
47  }