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, |
| 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 Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 69 | /** |
| 70 | * Creates new application permission using the supplied data. |
| 71 | * @param name permission name |
| 72 | */ |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 73 | public AppPermission(String name) { |
| 74 | super(name.toUpperCase(), ""); |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 75 | try { |
| 76 | type = Type.valueOf(name); |
| 77 | } catch (IllegalArgumentException e) { |
| 78 | type = null; |
| 79 | } |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 80 | } |
| 81 | |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 82 | /** |
| 83 | * Creates new application permission using the supplied data. |
| 84 | * @param name permission name |
| 85 | * @param actions permission action |
| 86 | */ |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 87 | public AppPermission(String name, String actions) { |
| 88 | super(name.toUpperCase(), actions); |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 89 | 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 Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | } |