2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.service;
27 * Permission class that can be instantiated easily using constructor or factory
30 public class SecureServicePermission {
31 public final static String ALL = "*";
34 private String instance;
35 private String action;
38 * Factory method to create permission given type, instance, and action.
45 public static SecureServicePermission create(String type, String instance, String action) {
46 return new SecureServicePermission(type, instance, action);
50 * Factory method to create permission given type and instance. Default
57 public static SecureServicePermission create(String type, String instance) {
58 return new SecureServicePermission(type, instance, ALL);
62 * Factory method to create permission given type. Default instance and
68 public static SecureServicePermission create(String type) {
69 return new SecureServicePermission(type, ALL, ALL);
73 * Instantiate permission given type, instance, and action.
79 public SecureServicePermission(String type, String instance, String action) {
81 this.instance = instance;
86 * Instantiate permission given type from concatenated string
88 * @param concatenatedString
89 * the string type|instance|action, less than 3 params can be
90 * provided (e.g. "permission-type-cl", "permission-type-cl|dev",
91 * "permission-type-cl|dev|update" )
93 public SecureServicePermission(String concatenatedString) {
94 String[] userInfo = concatenatedString.split("[|]");
95 // We should have at least 1 string
96 this.type = userInfo[0];
97 this.instance = (userInfo.length > 1 ? userInfo[1] : ALL);
98 this.action = (userInfo.length > 2 ? userInfo[2] : ALL);
102 * Override toString - return permission in key format
105 public String toString() {
110 * Return Permission in Key format = type, instance, and action separate by
115 public String getKey() {
116 return type + "|" + instance + "|" + action;
120 * Return Permission in Key format = type, all instance, and action separate
125 public String getKeyAllInstance() {
126 return type + "|" + ALL + "|" + action;
130 * Return Permission in Key format = type, all instance, and all action
131 * separate by pipe character.
135 public String getKeyAllInstanceAction() {
136 return type + "|" + ALL + "|" + ALL;
140 * Return Permission in Key format = type, instance, and all action separate
145 public String getKeyAllAction() {
146 return type + "|" + instance + "|" + ALL;
152 public String getType() {
160 public void setType(String type) {
165 * @return the instance
167 public String getInstance() {
173 * the instance to set
175 public void setInstance(String instance) {
176 this.instance = instance;
182 public String getAction() {
190 public void setAction(String action) {
191 this.action = action;