Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 1 | /* |
| 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 Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 17 | package org.onosproject.security; |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 18 | |
Thomas Vachuska | 4c571ae | 2015-09-10 16:31:59 -0700 | [diff] [blame] | 19 | import com.google.common.annotations.Beta; |
| 20 | |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 21 | import java.security.BasicPermission; |
| 22 | |
| 23 | /** |
| 24 | * Implementation of API access permission. |
| 25 | */ |
Thomas Vachuska | 4c571ae | 2015-09-10 16:31:59 -0700 | [diff] [blame] | 26 | @Beta |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 27 | public class AppPermission extends BasicPermission { |
| 28 | |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 29 | public enum Type { |
| 30 | APP_READ, |
| 31 | APP_EVENT, |
| 32 | CONFIG_READ, |
| 33 | CONFIG_WRITE, |
| 34 | CLUSTER_READ, |
| 35 | CLUSTER_WRITE, |
| 36 | CLUSTER_EVENT, |
Brian Stanke | ca93d9a | 2016-02-10 09:17:35 -0500 | [diff] [blame] | 37 | DEVICE_KEY_EVENT, |
| 38 | DEVICE_KEY_READ, |
| 39 | DEVICE_KEY_WRITE, |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 40 | DEVICE_READ, |
| 41 | DEVICE_EVENT, |
| 42 | DRIVER_READ, |
| 43 | DRIVER_WRITE, |
| 44 | FLOWRULE_READ, |
| 45 | FLOWRULE_WRITE, |
| 46 | FLOWRULE_EVENT, |
| 47 | GROUP_READ, |
| 48 | GROUP_WRITE, |
| 49 | GROUP_EVENT, |
| 50 | HOST_READ, |
| 51 | HOST_WRITE, |
| 52 | HOST_EVENT, |
| 53 | INTENT_READ, |
| 54 | INTENT_WRITE, |
| 55 | INTENT_EVENT, |
| 56 | LINK_READ, |
| 57 | LINK_WRITE, |
| 58 | LINK_EVENT, |
| 59 | PACKET_READ, |
| 60 | PACKET_WRITE, |
| 61 | PACKET_EVENT, |
| 62 | STATISTIC_READ, |
| 63 | TOPOLOGY_READ, |
| 64 | TOPOLOGY_EVENT, |
| 65 | TUNNEL_READ, |
| 66 | TUNNEL_WRITE, |
| 67 | TUNNEL_EVENT, |
| 68 | STORAGE_WRITE |
| 69 | } |
| 70 | |
| 71 | protected Type type; |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 72 | /** |
| 73 | * Creates new application permission using the supplied data. |
| 74 | * @param name permission name |
| 75 | */ |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 76 | public AppPermission(String name) { |
| 77 | super(name.toUpperCase(), ""); |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 78 | try { |
| 79 | type = Type.valueOf(name); |
| 80 | } catch (IllegalArgumentException e) { |
| 81 | type = null; |
| 82 | } |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 83 | } |
| 84 | |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 85 | /** |
| 86 | * Creates new application permission using the supplied data. |
| 87 | * @param name permission name |
| 88 | * @param actions permission action |
| 89 | */ |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 90 | public AppPermission(String name, String actions) { |
| 91 | super(name.toUpperCase(), actions); |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 92 | try { |
| 93 | type = Type.valueOf(name); |
| 94 | } catch (IllegalArgumentException e) { |
| 95 | type = null; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Crates new application permission using the supplied data. |
| 101 | * @param type permission type |
| 102 | */ |
| 103 | public AppPermission(Type type) { |
| 104 | super(type.name(), ""); |
| 105 | this.type = type; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns type of permission. |
| 110 | * @return application permission type |
| 111 | */ |
| 112 | public Type getType() { |
| 113 | return this.type; |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | } |