2 * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.aaa.shiro;
11 import org.opendaylight.aaa.shiro.filters.AAAFilter;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
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>.
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
28 * ServiceProxy is a singleton; access to the ServiceProxy is granted through
29 * the <code>getInstance()</code> function.
31 * @author Ryan Goulding (ryandgoulding@gmail.com)
33 * href="https://github.com/opendaylight/netconf/blob/master/opendaylight/restconf/sal-rest-connector/src/main/resources/WEB-INF/web.xml">resconf
35 * @see <code>org.opendaylight.aaa.shiro.Activator</code>
36 * @see <code>org.opendaylight.aaa.shiro.filters.AAAFilter</code>
38 public class ServiceProxy {
39 private static final Logger LOG = LoggerFactory.getLogger(ServiceProxy.class);
42 * AuthN and AuthZ are disabled by default to support workflows included in
43 * features such as <code>odl-restconf-noauth</code>
45 public static final boolean DEFAULT_AA_ENABLE_STATUS = false;
47 private static ServiceProxy instance = new ServiceProxy();
48 private volatile boolean enabled = false;
49 private AAAFilter filter;
52 * private for singleton pattern
54 private ServiceProxy() {
55 final String INFO_MESSAGE = "Creating the ServiceProxy";
56 LOG.info(INFO_MESSAGE);
60 * @return ServiceProxy, a feature level singleton
62 public static ServiceProxy getInstance() {
67 * Enables/disables the feature, cascading the state information to the
70 * @param enabled A flag indicating whether to enable the Service.
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
77 filter.setEnabled(enabled);
82 * Extract whether the service is enabled.
85 * register an optional Filter for callback if enable state
87 * @return Whether the service is enabled
89 public synchronized boolean getEnabled(final AAAFilter filter) {