JCAProvider.java
01 /*
02  *
03  * Licensed to the Apache Software Foundation (ASF) under one
04  * or more contributor license agreements.  See the NOTICE file
05  * distributed with this work for additional information
06  * regarding copyright ownership.  The ASF licenses this file
07  * to you under the Apache License, Version 2.0 (the
08  * "License"); you may not use this file except in compliance
09  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  */
21 package org.apache.qpid.client.security;
22 
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 
26 import javax.security.sasl.SaslClientFactory;
27 
28 import java.security.Provider;
29 import java.security.Security;
30 import java.util.Map;
31 
32 /**
33  * JCAProvider is a security provider for SASL client factories that is configured from a map of SASL mechanism names
34  * to client factories implementation class names. It is intended that the map of client factories can be read from a
35  * configuration file or other application configuration mechanism.
36  *
37  <p><table id="crc"><caption>CRC Card</caption>
38  <tr><th> Responsibilities <th> Collaborations
39  <tr><td> Register SASL mechanism implementations.
40  </table>
41  */
42 public class JCAProvider extends Provider
43 {
44     private static final Logger log = LoggerFactory.getLogger(JCAProvider.class);
45 
46     /**
47      * Creates the security provider with a map from SASL mechanisms to implementing factories.
48      *
49      @param providerMap The map from SASL mechanims to implementing factory classes.
50      */
51     public JCAProvider(Map<String, Class<? extends SaslClientFactory>> providerMap)
52     {
53         super("AMQSASLProvider-Client"1.0"A JCA provider that registers all "
54             "AMQ SASL providers that want to be registered");
55         register(providerMap);
56 //        Security.addProvider(this);
57     }
58 
59     /**
60      * Registers client factory classes for a map of mechanism names to client factory classes.
61      *
62      @param providerMap The map from SASL mechanims to implementing factory classes.
63      */
64     private void register(Map<String, Class<? extends SaslClientFactory>> providerMap)
65     {
66         for (Map.Entry<String, Class<? extends SaslClientFactory>> me : providerMap.entrySet())
67         {
68             put"SaslClientFactory."+me.getKey(), me.getValue().getName());
69             log.debug("Registered SASL Client factory for " + me.getKey() " as " + me.getValue().getName());
70         }
71     }
72 }