Catalog alignment
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / aaf / AafPermission.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.impl.aaf;
22
23 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
24 import org.openecomp.sdc.be.config.ConfigurationManager;
25 import org.openecomp.sdc.be.dao.api.ActionStatus;
26
27 public enum AafPermission {
28
29     READ(PermNames.READ_VALUE),
30     WRITE(PermNames.WRITE_VALUE),
31     DELETE(PermNames.DELETE_VALUE),
32     INTERNAL_ALL(PermNames.INTERNAL_ALL_VALUE);
33
34     private String permission;
35     private String permissionSuffix;
36
37     AafPermission(String permissionSuffix) {
38         this.permissionSuffix = permissionSuffix;
39         this.permission = String.format("%s.%s",
40                 ConfigurationManager.getConfigurationManager().getConfiguration().getAafNamespace(),
41                 permissionSuffix);
42     }
43
44     public String getFullPermission() {
45         return permission;
46     }
47
48     public static AafPermission getEnumByString(String perm) {
49         for (AafPermission e : AafPermission.values()) {
50             if (perm.equals(e.getPermissionSuffix()))
51                 return e;
52         }
53         throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY, perm);
54     }
55
56     public String getPermissionSuffix() {
57         return this.permissionSuffix;
58     }
59
60     public static class PermNames {
61         public static final String READ_VALUE = "endpoint.api.access|*|read";
62         public static final String WRITE_VALUE = "endpoint.api.access|*|write";
63         public static final String DELETE_VALUE = "endpoint.api.access|*|delete";
64         public static final String INTERNAL_ALL_VALUE = "endpoint.api.internal.access|*|all";
65     }
66 }