9e84c9887826a786335390922ca4dd8dafdbf256
[moon.git] /
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 package org.opendaylight.aaa.shiro.authorization;
9
10 import com.google.common.collect.Sets;
11 import java.util.Collection;
12 import java.util.HashSet;
13
14 /**
15  * A singleton container of default authorization rules that are installed as
16  * part of Shiro initialization. This class defines an immutable set of rules
17  * that are needed to provide system-wide security. These include protecting
18  * certain MD-SAL leaf nodes that contain AAA data from random access. This is
19  * not a place to define your custom rule set; additional RBAC rules are
20  * configured through the shiro initialization file:
21  * <code>$KARAF_HOME/shiro.ini</code>
22  *
23  * An important distinction to consider is that Shiro URL rules work to protect
24  * the system at the Web layer, and <code>AuthzDomDataBroker</code> works to
25  * protect the system down further at the DOM layer.
26  *
27  * @author Ryan Goulding (ryandgoulding@gmail.com)
28  *
29  */
30 public class DefaultRBACRules {
31
32     private static DefaultRBACRules instance;
33
34     /**
35      * a collection of the default security rules
36      */
37     private Collection<RBACRule> rbacRules = new HashSet<RBACRule>();
38
39     /**
40      * protects the AAA MD-SAL store by preventing access to the leaf nodes to
41      * non-admin users.
42      */
43     private static final RBACRule PROTECT_AAA_MDSAL = RBACRule.createAuthorizationRule(
44             "*/authorization/*", Sets.newHashSet("admin"));
45
46     /*
47      * private for singleton pattern
48      */
49     private DefaultRBACRules() {
50         // rbacRules.add(PROTECT_AAA_MDSAL);
51     }
52
53     /**
54      *
55      * @return the container instance for the default RBAC Rules
56      */
57     public static final DefaultRBACRules getInstance() {
58         if (null == instance) {
59             instance = new DefaultRBACRules();
60         }
61         return instance;
62     }
63
64     /**
65      *
66      * @return a copy of the default rules, so any modifications to the returned
67      *         reference do not affect the <code>DefaultRBACRules</code>.
68      */
69     public final Collection<RBACRule> getRBACRules() {
70         // Returns a copy of the rbacRules set such that the original set keeps
71         // its contract of remaining immutable. Calls to rbacRules.add() are
72         // encapsulated solely in <code>DefaultRBACRules</code>.
73         //
74         // Since this method is only called at shiro initialiation time,
75         // memory consumption of creating a new set is a non-issue.
76         return Sets.newHashSet(rbacRules);
77     }
78 }