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