Coverage Report - org.mule.util.DebugUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
DebugUtils
0%
0/28
0%
0/14
3.333
 
 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.util;
 8  
 
 9  
 import java.security.Provider;
 10  
 import java.security.Security;
 11  
 import java.util.HashSet;
 12  
 import java.util.Iterator;
 13  
 import java.util.Set;
 14  
 
 15  
 /**
 16  
  * Useful for enumerating debug information about the current Java environment
 17  
  */
 18  
 // @ThreadSafe
 19  
 public final class DebugUtils
 20  
 {
 21  
 
 22  
     /** Do not instanciate. */
 23  
     private DebugUtils ()
 24  0
     {
 25  
         // no-op
 26  0
     }
 27  
 
 28  
     /**
 29  
      * @return all available services types
 30  
      */
 31  
     public static String[] listSecurityServiceTypes()
 32  
     {
 33  0
         Set result = new HashSet();
 34  
 
 35  
         // All all providers
 36  0
         Provider[] providers = Security.getProviders();
 37  0
         for (int i = 0; i < providers.length; i++)
 38  
         {
 39  
             // Get services provided by each provider
 40  0
             Set keys = providers[i].keySet();
 41  0
             for (Iterator it = keys.iterator(); it.hasNext();)
 42  
             {
 43  0
                 String key = (String) it.next();
 44  0
                 key = key.split(" ")[0];
 45  
 
 46  0
                 if (key.startsWith("Alg.Alias."))
 47  
                 {
 48  
                     // Strip the alias
 49  0
                     key = key.substring(10);
 50  
                 }
 51  0
                 int ix = key.indexOf('.');
 52  0
                 result.add(key.substring(0, ix));
 53  0
             }
 54  
         }
 55  0
         return (String[]) result.toArray(new String[result.size()]);
 56  
     }
 57  
 
 58  
     /**
 59  
      * @return the available implementations for a service type
 60  
      */
 61  
     public static String[] listCryptoImplementations(String serviceType)
 62  
     {
 63  0
         Set result = new HashSet();
 64  
 
 65  
         // All all providers
 66  0
         Provider[] providers = Security.getProviders();
 67  0
         for (int i = 0; i < providers.length; i++)
 68  
         {
 69  
             // Get services provided by each provider
 70  0
             Set keys = providers[i].keySet();
 71  0
             for (Iterator it = keys.iterator(); it.hasNext();)
 72  
             {
 73  0
                 String key = (String) it.next();
 74  0
                 key = key.split(" ")[0];
 75  
 
 76  0
                 if (key.startsWith(serviceType + "."))
 77  
                 {
 78  0
                     result.add(key.substring(serviceType.length() + 1));
 79  
                 }
 80  0
                 else if (key.startsWith("Alg.Alias." + serviceType + "."))
 81  
                 {
 82  
                     // This is an alias
 83  0
                     result.add(key.substring(serviceType.length() + 11));
 84  
                 }
 85  0
             }
 86  
         }
 87  0
         return (String[]) result.toArray(new String[result.size()]);
 88  
     }
 89  
 }