Coverage Report - org.mule.tck.security.TestMultiuserSecurityProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
TestMultiuserSecurityProvider
0%
0/25
0%
0/2
0
 
 1  
 /*
 2  
  * $Id: TestMultiuserSecurityProvider.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.tck.security;
 12  
 
 13  
 import org.mule.api.lifecycle.InitialisationException;
 14  
 import org.mule.api.security.Authentication;
 15  
 import org.mule.api.security.SecurityException;
 16  
 
 17  
 import java.util.HashMap;
 18  
 import java.util.Map;
 19  
 
 20  
 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
 21  
 
 22  
 /**
 23  
  * A security provider which holds authentications for multiple users concurrently.
 24  
  */
 25  
 public class TestMultiuserSecurityProvider extends TestSingleUserSecurityProvider
 26  
 {
 27  
     private Map <String, Authentication> authentications;
 28  
     
 29  
     public TestMultiuserSecurityProvider()
 30  
     {
 31  0
         super("multi-user-test");
 32  0
     }
 33  
     
 34  
     protected void doInitialise() throws InitialisationException
 35  
     {
 36  0
         authentications = new ConcurrentHashMap();
 37  0
     }
 38  
     
 39  
     public Authentication authenticate(Authentication authentication) throws SecurityException
 40  
     {
 41  0
         String user = (String) authentication.getPrincipal();
 42  0
         logger.debug("Authenticating user: " + user);
 43  
         
 44  
         // Check to see if user has already been authenticated
 45  0
         Authentication oldAuth = authentications.get(user);
 46  0
         if (oldAuth != null)
 47  
         {
 48  0
             authentication = oldAuth;
 49  0
             Map props = authentication.getProperties();
 50  0
             int numberLogins = (Integer) props.get(PROPERTY_NUMBER_LOGINS);
 51  0
             String favoriteColor = (String) props.get(PROPERTY_FAVORITE_COLOR);
 52  0
             props.put(PROPERTY_NUMBER_LOGINS, numberLogins + 1);
 53  0
             authentication.setProperties(props);
 54  0
             authentications.put(user, authentication);
 55  0
             logger.info("Welcome back " + user + " (" + numberLogins+1 + " logins), we remembered your favorite color: " + favoriteColor);
 56  0
         }
 57  
         else
 58  
         {
 59  0
             String favoriteColor = getFavoriteColor(user);
 60  0
             logger.info("First login for user: " + user + ", favorite color is " + favoriteColor);
 61  0
             Map props = new HashMap();
 62  0
             props.put(PROPERTY_NUMBER_LOGINS, 1);
 63  0
             props.put(PROPERTY_FAVORITE_COLOR, favoriteColor);
 64  0
             authentication.setProperties(props);
 65  0
             authentications.put(user, authentication);
 66  
         }
 67  0
         return authentication;
 68  
     }
 69  
 }