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 * ===================================================================
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 static final String ALL = "*";
34 private String instance;
35 private String action;
38 * Factory method to create permission given type, instance, and action.
40 * @param type type of the permission
41 * @param instance instance of the permission
42 * @param action action of the permission
43 * @return instance of SecureServicePermission with 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
53 * @param type type of the permission
54 * @param instance instance of the permission
55 * @return instance of SecureServicePermission with type, instance and default action
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
65 * @param type type of the permission
66 * @return instance of SecureServicePermission with type and default instance and action
68 public static SecureServicePermission create(String type) {
69 return new SecureServicePermission(type, ALL, ALL);
73 * Instantiate permission given type, instance, and action.
75 * @param type type of the permission
76 * @param instance instance of the permission
77 * @param action action of the permission
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
113 * @return permission in key format
115 public String getKey() {
116 return type + "|" + instance + "|" + action;
120 * Return Permission in Key format = type, all instance, and action separate
123 * @return permission in key format
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.
133 * @return permission in key format
135 public String getKeyAllInstanceAction() {
136 return type + "|" + ALL + "|" + ALL;
140 * Return Permission in Key format = type, instance, and all action separate
143 * @return permission in key format
145 public String getKeyAllAction() {
146 return type + "|" + instance + "|" + ALL;
150 * Returns the permission type.
154 public String getType() {
159 * Sets the type of permission.
161 * @param type the type to set
163 public void setType(String type) {
168 * Returns the instance of permission.
170 * @return the instance
172 public String getInstance() {
177 * Sets the instance of permission.
179 * @param instance the instance to set
181 public void setInstance(String instance) {
182 this.instance = instance;
186 * Returns the action of permission.
190 public String getAction() {
195 * Sets the action of permission.
197 * @param action the action to set
199 public void setAction(String action) {
200 this.action = action;