Migrate aaa-shiro to utilize archetype setup
[aaa.git] / aaa-shiro / impl / src / main / java / org / opendaylight / aaa / impl / shiro / filters / AAAFilter.java
1 /*
2  * Copyright (c) 2015 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.filters;
10
11 import org.apache.shiro.web.servlet.ShiroFilter;
12 import org.opendaylight.aaa.shiro.ServiceProxy;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 /**
17  * The RESTCONF AAA JAX-RS 1.X Web Filter. This class is also responsible for
18  * delivering debug information; to enable these debug statements, please issue
19  * the following in the karaf shell:
20  *
21  * <code>log:set debug org.opendaylight.aaa.shiro.filters.AAAFilter</code>
22  *
23  * @author Ryan Goulding (ryandgoulding@gmail.com)
24  * @see <code>javax.servlet.Filter</code>
25  * @see <code>org.apache.shiro.web.servlet.ShiroFilter</code>
26  */
27 public class AAAFilter extends ShiroFilter {
28
29     private static final Logger LOG = LoggerFactory.getLogger(AAAFilter.class);
30
31     public AAAFilter() {
32         super();
33         final String DEBUG_MESSAGE = "Creating the AAAFilter";
34         LOG.debug(DEBUG_MESSAGE);
35     }
36
37     /*
38      * (non-Javadoc)
39      *
40      * Adds context clues that aid in debugging. Also initializes the enable
41      * status to correspond with
42      * <code>ServiceProxy.getInstance.getEnabled()</code>.
43      *
44      * @see org.apache.shiro.web.servlet.ShiroFilter#init()
45      */
46     @Override
47     public void init() throws Exception {
48         super.init();
49         final String DEBUG_MESSAGE = "Initializing the AAAFilter";
50         LOG.debug(DEBUG_MESSAGE);
51         // sets the filter to the startup value. Because of non-determinism in
52         // bundle loading, this passes an instance of itself along so that if
53         // the
54         // enable status changes, then AAAFilter enable status is changed.
55         setEnabled(ServiceProxy.getInstance().getEnabled(this));
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * Adds context clues to aid in debugging whether the filter is enabled.
62      *
63      * @see
64      * org.apache.shiro.web.servlet.OncePerRequestFilter#setEnabled(boolean)
65      */
66     @Override
67     public void setEnabled(boolean enabled) {
68         super.setEnabled(enabled);
69         final String DEBUG_MESSAGE = "Setting AAAFilter enabled to " + enabled;
70         LOG.debug(DEBUG_MESSAGE);
71     }
72 }