2 * Copyright (c) 2015 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
8 package org.opendaylight.aaa.shiro.authorization;
10 import com.google.common.collect.Sets;
11 import java.util.Collection;
12 import java.util.HashSet;
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>
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.
27 * @author Ryan Goulding (ryandgoulding@gmail.com)
30 public class DefaultRBACRules {
32 private static DefaultRBACRules instance;
35 * a collection of the default security rules
37 private Collection<RBACRule> rbacRules = new HashSet<RBACRule>();
40 * protects the AAA MD-SAL store by preventing access to the leaf nodes to
43 private static final RBACRule PROTECT_AAA_MDSAL = RBACRule.createAuthorizationRule(
44 "*/authorization/*", Sets.newHashSet("admin"));
47 * private for singleton pattern
49 private DefaultRBACRules() {
50 // rbacRules.add(PROTECT_AAA_MDSAL);
55 * @return the container instance for the default RBAC Rules
57 public static final DefaultRBACRules getInstance() {
58 if (null == instance) {
59 instance = new DefaultRBACRules();
66 * @return a copy of the default rules, so any modifications to the returned
67 * reference do not affect the <code>DefaultRBACRules</code>.
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>.
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);