blob: 09fe17a81766d3b7e190cc8505a1225ed3890543 [file] [log] [blame]
Changhoon Yoon23dee8f2015-05-18 22:19:49 +09001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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,
32 CONFIG_READ,
33 CONFIG_WRITE,
34 CLUSTER_READ,
35 CLUSTER_WRITE,
36 CLUSTER_EVENT,
37 DEVICE_READ,
38 DEVICE_EVENT,
39 DRIVER_READ,
40 DRIVER_WRITE,
41 FLOWRULE_READ,
42 FLOWRULE_WRITE,
43 FLOWRULE_EVENT,
44 GROUP_READ,
45 GROUP_WRITE,
46 GROUP_EVENT,
47 HOST_READ,
48 HOST_WRITE,
49 HOST_EVENT,
50 INTENT_READ,
51 INTENT_WRITE,
52 INTENT_EVENT,
53 LINK_READ,
54 LINK_WRITE,
55 LINK_EVENT,
56 PACKET_READ,
57 PACKET_WRITE,
58 PACKET_EVENT,
59 STATISTIC_READ,
60 TOPOLOGY_READ,
61 TOPOLOGY_EVENT,
62 TUNNEL_READ,
63 TUNNEL_WRITE,
64 TUNNEL_EVENT,
65 STORAGE_WRITE
66 }
67
68 protected Type type;
Changhoon Yoon541ef712015-05-23 17:18:34 +090069 /**
70 * Creates new application permission using the supplied data.
71 * @param name permission name
72 */
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090073 public AppPermission(String name) {
74 super(name.toUpperCase(), "");
Changhoon Yoonb856b812015-08-10 03:47:19 +090075 try {
76 type = Type.valueOf(name);
77 } catch (IllegalArgumentException e) {
78 type = null;
79 }
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090080 }
81
Changhoon Yoon541ef712015-05-23 17:18:34 +090082 /**
83 * Creates new application permission using the supplied data.
84 * @param name permission name
85 * @param actions permission action
86 */
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090087 public AppPermission(String name, String actions) {
88 super(name.toUpperCase(), actions);
Changhoon Yoonb856b812015-08-10 03:47:19 +090089 try {
90 type = Type.valueOf(name);
91 } catch (IllegalArgumentException e) {
92 type = null;
93 }
94 }
95
96 /**
97 * Crates new application permission using the supplied data.
98 * @param type permission type
99 */
100 public AppPermission(Type type) {
101 super(type.name(), "");
102 this.type = type;
103 }
104
105 /**
106 * Returns type of permission.
107 * @return application permission type
108 */
109 public Type getType() {
110 return this.type;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +0900111 }
112
113}