[CLAMP-1] Initial ONAP CLAMP seed code commit
[clamp.git] / src / main / java / org / onap / clamp / clds / service / SecureServicePermission.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
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
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
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.
22  */
23
24 package org.onap.clamp.clds.service;
25
26 /**
27  * Permission class that can be instantiated easily using constructor or factory methods.
28  */
29 public class SecureServicePermission {
30     public final static String ALL = "*";
31
32     private String type;
33     private String instance;
34     private String action;
35
36     /**
37      * Factory method to create permission given type, instance, and action.
38      *
39      * @param type
40      * @param instance
41      * @param action
42      * @return
43      */
44     public static SecureServicePermission create(String type, String instance, String action) {
45         return new SecureServicePermission(type, instance, action);
46     }
47
48     /**
49      * Factory method to create permission given type and instance.  Default action to ALL/*.
50      *
51      * @param type
52      * @param instance
53      * @return
54      */
55     public static SecureServicePermission create(String type, String instance) {
56         return new SecureServicePermission(type, instance);
57     }
58
59     /**
60      * Factory method to create permission given type.  Default instance and action to ALL/*.
61      *
62      * @param type
63      * @return
64      */
65     public static SecureServicePermission create(String type) {
66         return new SecureServicePermission(type);
67     }
68
69     /**
70      * Instantiate permission given type, instance, and action.
71      *
72      * @param type
73      * @param instance
74      * @param action
75      */
76     public SecureServicePermission(String type, String instance, String action) {
77         this.type = type;
78         this.instance = instance;
79         this.action = action;
80     }
81
82     /**
83      * Instantiate permission given type and instance.  Default action to ALL/*.
84      *
85      * @param type
86      * @param instance
87      */
88     public SecureServicePermission(String type, String instance) {
89         this.type = type;
90         this.instance = instance;
91         this.action = ALL;
92     }
93
94     /**
95      * Instantiate permission given type.  Default instance and action to ALL/*.
96      *
97      * @param type
98      */
99     public SecureServicePermission(String type) {
100         this.type = type;
101         this.instance = ALL;
102         this.action = ALL;
103     }
104
105     /**
106      * Override toString - return permission in key format
107      */
108     public String toString() {
109         return getKey();
110     }
111
112     /**
113      * Return Permission in Key format = type, instance, and action separate by pipe character.
114      *
115      * @return
116      */
117     public String getKey() {
118         return type + "|" + instance + "|" + action;
119     }
120
121     /**
122      * Return Permission in Key format = type, all instance, and action separate by pipe character.
123      *
124      * @return
125      */
126     public String getKeyAllInstance() {
127         return type + "|" + ALL + "|" + action;
128     }
129
130     /**
131      * Return Permission in Key format = type, all instance, and all action separate by pipe character.
132      *
133      * @return
134      */
135     public String getKeyAllInstanceAction() {
136         return type + "|" + ALL + "|" + ALL;
137     }
138
139     /**
140      * Return Permission in Key format = type, instance, and all action separate by pipe character.
141      *
142      * @return
143      */
144     public String getKeyAllAction() {
145         return type + "|" + instance + "|" + ALL;
146     }
147
148     /**
149      * @return the type
150      */
151     public String getType() {
152         return type;
153     }
154
155     /**
156      * @param type the type to set
157      */
158     public void setType(String type) {
159         this.type = type;
160     }
161
162     /**
163      * @return the instance
164      */
165     public String getInstance() {
166         return instance;
167     }
168
169     /**
170      * @param instance the instance to set
171      */
172     public void setInstance(String instance) {
173         this.instance = instance;
174     }
175
176     /**
177      * @return the action
178      */
179     public String getAction() {
180         return action;
181     }
182
183     /**
184      * @param action the action to set
185      */
186     public void setAction(String action) {
187         this.action = action;
188     }
189
190 }