KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > security > JaasAuthenticationPlugin


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.security;
19
20 import org.apache.activemq.broker.Broker;
21 import org.apache.activemq.broker.BrokerPlugin;
22
23 import java.net.URL JavaDoc;
24
25 /**
26  * Adds a JAAS based authentication security plugin
27  *
28  * @org.apache.xbean.XBean description="Provides a JAAS based authentication plugin"
29  *
30  * @version $Revision: 447607 $
31  */

32 public class JaasAuthenticationPlugin implements BrokerPlugin {
33     protected String JavaDoc configuration = "activemq-domain";
34     protected boolean discoverLoginConfig = true;
35
36     public Broker installPlugin(Broker broker) {
37         initialiseJaas();
38         return new JaasAuthenticationBroker(broker, configuration);
39     }
40
41
42     // Properties
43
// -------------------------------------------------------------------------
44
public String JavaDoc getConfiguration() {
45         return configuration;
46     }
47
48     /**
49      * Sets the JAAS configuration domain name used
50      */

51     public void setConfiguration(String JavaDoc jaasConfiguration) {
52         this.configuration = jaasConfiguration;
53     }
54
55
56     public boolean isDiscoverLoginConfig() {
57         return discoverLoginConfig;
58     }
59
60     /**
61      * Enables or disables the auto-discovery of the login.config file for JAAS to initialize itself.
62      * This flag is enabled by default such that if the <b>java.security.auth.login.config</b> system property
63      * is not defined then it is set to the location of the <b>login.config</b> file on the classpath.
64      */

65     public void setDiscoverLoginConfig(boolean discoverLoginConfig) {
66         this.discoverLoginConfig = discoverLoginConfig;
67     }
68
69     // Implementation methods
70
// -------------------------------------------------------------------------
71
protected void initialiseJaas() {
72         if (discoverLoginConfig) {
73             String JavaDoc path = System.getProperty("java.security.auth.login.config");
74             if (path == null) {
75                 //URL resource = Thread.currentThread().getContextClassLoader().getResource("login.config");
76
URL JavaDoc resource = null;
77                 if (resource == null) {
78                     resource = getClass().getClassLoader().getResource("login.config");
79                 }
80                 if (resource != null) {
81                     path = resource.getFile();
82                     System.setProperty("java.security.auth.login.config", path);
83                 }
84             }
85         }
86     }
87 }
88
Popular Tags