blob: c0ab697fc4ce064d2f1c3665ac1bfaaf68061ec6 [file] [log] [blame]
Changhoon Yoon23dee8f2015-05-18 22:19:49 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Changhoon Yoon23dee8f2015-05-18 22:19:49 +09003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Changhoon Yoon541ef712015-05-23 17:18:34 +090017package org.onosproject.security;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090018
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070019import com.google.common.annotations.Beta;
20
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090021import java.security.BasicPermission;
22
23/**
24 * Implementation of API access permission.
25 */
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070026@Beta
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090027public class AppPermission extends BasicPermission {
28
Changhoon Yoonb856b812015-08-10 03:47:19 +090029 public enum Type {
30 APP_READ,
31 APP_EVENT,
Heedo Kang4a47a302016-02-29 17:40:23 +090032 APP_WRITE,
Changhoon Yoonb856b812015-08-10 03:47:19 +090033 CONFIG_READ,
34 CONFIG_WRITE,
Heedo Kang4a47a302016-02-29 17:40:23 +090035 CONFIG_EVENT,
Changhoon Yoonb856b812015-08-10 03:47:19 +090036 CLUSTER_READ,
37 CLUSTER_WRITE,
38 CLUSTER_EVENT,
Heedo Kang4a47a302016-02-29 17:40:23 +090039 CODEC_READ,
40 CODEC_WRITE,
41 CLOCK_WRITE,
Brian Stankeca93d9a2016-02-10 09:17:35 -050042 DEVICE_KEY_EVENT,
43 DEVICE_KEY_READ,
44 DEVICE_KEY_WRITE,
Changhoon Yoonb856b812015-08-10 03:47:19 +090045 DEVICE_READ,
46 DEVICE_EVENT,
47 DRIVER_READ,
48 DRIVER_WRITE,
Heedo Kang4a47a302016-02-29 17:40:23 +090049 EVENT_READ,
50 EVENT_WRITE,
Changhoon Yoonb856b812015-08-10 03:47:19 +090051 FLOWRULE_READ,
52 FLOWRULE_WRITE,
53 FLOWRULE_EVENT,
54 GROUP_READ,
55 GROUP_WRITE,
56 GROUP_EVENT,
57 HOST_READ,
58 HOST_WRITE,
59 HOST_EVENT,
60 INTENT_READ,
61 INTENT_WRITE,
62 INTENT_EVENT,
63 LINK_READ,
64 LINK_WRITE,
65 LINK_EVENT,
Heedo Kang4a47a302016-02-29 17:40:23 +090066 MUTEX_WRITE,
Changhoon Yoonb856b812015-08-10 03:47:19 +090067 PACKET_READ,
68 PACKET_WRITE,
69 PACKET_EVENT,
Heedo Kang4a47a302016-02-29 17:40:23 +090070 PERSISTENCE_WRITE,
71 PARTITION_READ,
72 PARTITION_EVENT,
73 RESOURCE_READ,
74 RESOURCE_WRITE,
75 RESOURCE_EVENT,
76 REGION_READ,
Changhoon Yoonb856b812015-08-10 03:47:19 +090077 STATISTIC_READ,
Heedo Kang4a47a302016-02-29 17:40:23 +090078 STORAGE_WRITE,
Changhoon Yoonb856b812015-08-10 03:47:19 +090079 TOPOLOGY_READ,
80 TOPOLOGY_EVENT,
81 TUNNEL_READ,
82 TUNNEL_WRITE,
83 TUNNEL_EVENT,
Heedo Kang4a47a302016-02-29 17:40:23 +090084 UI_READ,
slowr0a44fde2017-10-09 14:48:53 -070085 UI_WRITE,
86 UPGRADE_READ,
87 UPGRADE_WRITE,
Laszlo Papp759f0d32018-03-05 13:24:30 +000088 UPGRADE_EVENT,
89 GLYPH_READ,
90 GLYPH_WRITE
Changhoon Yoonb856b812015-08-10 03:47:19 +090091 }
92
93 protected Type type;
Changhoon Yoon541ef712015-05-23 17:18:34 +090094 /**
95 * Creates new application permission using the supplied data.
96 * @param name permission name
97 */
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090098 public AppPermission(String name) {
99 super(name.toUpperCase(), "");
Changhoon Yoonb856b812015-08-10 03:47:19 +0900100 try {
101 type = Type.valueOf(name);
102 } catch (IllegalArgumentException e) {
103 type = null;
104 }
Changhoon Yoon23dee8f2015-05-18 22:19:49 +0900105 }
106
Changhoon Yoon541ef712015-05-23 17:18:34 +0900107 /**
108 * Creates new application permission using the supplied data.
109 * @param name permission name
110 * @param actions permission action
111 */
Changhoon Yoon23dee8f2015-05-18 22:19:49 +0900112 public AppPermission(String name, String actions) {
113 super(name.toUpperCase(), actions);
Changhoon Yoonb856b812015-08-10 03:47:19 +0900114 try {
115 type = Type.valueOf(name);
116 } catch (IllegalArgumentException e) {
117 type = null;
118 }
119 }
120
121 /**
122 * Crates new application permission using the supplied data.
123 * @param type permission type
124 */
125 public AppPermission(Type type) {
126 super(type.name(), "");
127 this.type = type;
128 }
129
130 /**
131 * Returns type of permission.
132 * @return application permission type
133 */
134 public Type getType() {
135 return this.type;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +0900136 }
137
138}