1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.aaf;
\r
25 import org.onap.aaf.cadi.Permission;
\r
28 * A Class that understands the AAF format of Permission (name/type/action)
\r
29 * or String "name|type|action"
\r
33 public class AAFPermission implements Permission {
\r
34 protected String type,instance,action,key;
\r
36 protected AAFPermission() {}
\r
38 public AAFPermission(String type, String instance, String action) {
\r
40 this.instance = instance;
\r
41 this.action = action;
\r
42 key = type + '|' + instance + '|' + action;
\r
46 * Match a Permission
\r
47 * if Permission is Fielded type "Permission", we use the fields
\r
48 * otherwise, we split the Permission with '|'
\r
50 * when the type or action starts with REGEX indicator character ( ! ),
\r
51 * then it is evaluated as a regular expression.
\r
53 * If you want a simple field comparison, it is faster without REGEX
\r
55 public boolean match(Permission p) {
\r
56 if(p instanceof AAFPermission) {
\r
57 AAFPermission ap = (AAFPermission)p;
\r
58 // Note: In AAF > 1.0, Accepting "*" from name would violate multi-tenancy
\r
59 // Current solution is only allow direct match on Type.
\r
60 // 8/28/2014 - added REGEX ability
\r
61 if(type.equals(ap.getName()))
\r
62 if(PermEval.evalInstance(instance,ap.getInstance()))
\r
63 if(PermEval.evalAction(action,ap.getAction()))
\r
66 // Permission is concatenated together: separated by |
\r
67 String[] aaf = p.getKey().split("[\\s]*\\|[\\s]*",3);
\r
68 if(aaf.length>0 && type.equals(aaf[0]))
\r
69 if(PermEval.evalInstance(instance,aaf.length>1?aaf[1]:"*"))
\r
70 if(PermEval.evalAction(action,aaf.length>2?aaf[2]:"*"))
\r
76 public String getName() {
\r
80 public String getInstance() {
\r
84 public String getAction() {
\r
88 public String getKey() {
\r
93 * @see com.att.cadi.Permission#permType()
\r
95 public String permType() {
\r
99 public String toString() {
\r
100 return "AAFPermission:\n\tType: " + type +
\r
101 "\n\tInstance: " + instance +
\r
102 "\n\tAction: " + action +
\r