Just clean up some log messages and remove unnecessary code
[aaa.git] / aaa-shiro / impl / src / main / java / org / opendaylight / aaa / impl / shiro / ServiceProxy.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.aaa.shiro;
10
11 import org.opendaylight.aaa.shiro.filters.AAAFilter;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 /**
16  * Responsible for enabling and disabling the AAA service. By default, the
17  * service is disabled; the AAAFilter will not require AuthN or AuthZ. The
18  * service is enabled through calling
19  * <code>ServiceProxy.getInstance().setEnabled(true)</code>. AuthN and AuthZ are
20  * disabled by default in order to support workflows such as the feature
21  * <code>odl-restconf-noauth</code>.
22  *
23  * The AAA service is enabled through installing the <code>odl-aaa-shiro</code>
24  * feature. The <code>org.opendaylight.aaa.shiroact.Activator()</code>
25  * constructor calls enables AAA through the ServiceProxy, which in turn enables
26  * the AAAFilter.
27  *
28  * ServiceProxy is a singleton; access to the ServiceProxy is granted through
29  * the <code>getInstance()</code> function.
30  *
31  * @author Ryan Goulding (ryandgoulding@gmail.com)
32  * @see <a
33  *      href="https://github.com/opendaylight/netconf/blob/master/opendaylight/restconf/sal-rest-connector/src/main/resources/WEB-INF/web.xml">resconf
34  *      web,xml</a>
35  * @see <code>org.opendaylight.aaa.shiro.Activator</code>
36  * @see <code>org.opendaylight.aaa.shiro.filters.AAAFilter</code>
37  */
38 public class ServiceProxy {
39     private static final Logger LOG = LoggerFactory.getLogger(ServiceProxy.class);
40
41     /**
42      * AuthN and AuthZ are disabled by default to support workflows included in
43      * features such as <code>odl-restconf-noauth</code>
44      */
45     public static final boolean DEFAULT_AA_ENABLE_STATUS = false;
46
47     private static ServiceProxy instance = new ServiceProxy();
48     private volatile boolean enabled = false;
49     private AAAFilter filter;
50
51     /**
52      * private for singleton pattern
53      */
54     private ServiceProxy() {
55         final String INFO_MESSAGE = "Creating the ServiceProxy";
56         LOG.info(INFO_MESSAGE);
57     }
58
59     /**
60      * @return ServiceProxy, a feature level singleton
61      */
62     public static ServiceProxy getInstance() {
63         return instance;
64     }
65
66     /**
67      * Enables/disables the feature, cascading the state information to the
68      * AAAFilter.
69      *
70      * @param enabled A flag indicating whether to enable the Service.
71      */
72     public synchronized void setEnabled(final boolean enabled) {
73         this.enabled = enabled;
74         LOG.info("Setting ServiceProxy enabled to {}", enabled);
75         // check for null because of non-determinism in bundle load
76         if (filter != null) {
77             filter.setEnabled(enabled);
78         }
79     }
80
81     /**
82      * Extract whether the service is enabled.
83      *
84      * @param filter
85      *            register an optional Filter for callback if enable state
86      *            changes
87      * @return Whether the service is enabled
88      */
89     public synchronized boolean getEnabled(final AAAFilter filter) {
90         this.filter = filter;
91         return enabled;
92     }
93 }