Changhoon Yoon
Committed by Gerrit Code Review

ONOS-1896 : enum Permission added, DefaultPermission removed

Change-Id: Ie75313acc9adeaee9c5a55978b5ec8e8fb5bf9b6
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 -
17 -package org.onosproject.core;
18 -
19 -import java.security.BasicPermission;
20 -
21 -/**
22 - * Default implementation of ONOS application permissions for API-level access control.
23 - */
24 -public class DefaultPermission extends BasicPermission implements Permission {
25 -
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 - /**
66 - * Creates a new DefaultPermission.
67 - * @param name name of the permission
68 - * @param actions optional action field
69 - */
70 - public DefaultPermission(String name, String actions) {
71 - super(name, actions);
72 - }
73 -
74 - /**
75 - * Creates a new DefaultPermission.
76 - * @param name name of the permission
77 - */
78 - public DefaultPermission(String name) {
79 - super(name, "");
80 - }
81 -
82 - public DefaultPermission(Type permtype) {
83 - super(permtype.name(), "");
84 - }
85 -
86 - @Override
87 - public String name() {
88 - return super.getName();
89 - }
90 -
91 - @Override
92 - public String actions() {
93 - return super.getActions();
94 - }
95 -}
...@@ -18,17 +18,41 @@ package org.onosproject.core; ...@@ -18,17 +18,41 @@ package org.onosproject.core;
18 /** 18 /**
19 * Representation of an application permission. 19 * Representation of an application permission.
20 */ 20 */
21 -public interface Permission { 21 +public enum Permission {
22 - 22 + APP_READ,
23 - /** 23 + APP_EVENT,
24 - * Returns the name of the permission. 24 + CONFIG_READ,
25 - * @return a string value 25 + CONFIG_WRITE,
26 - */ 26 + CLUSTER_READ,
27 - String name(); 27 + CLUSTER_WRITE,
28 - 28 + CLUSTER_EVENT,
29 - /** 29 + DEVICE_READ,
30 - * Returns the actions string of the permission if specified. 30 + DEVICE_EVENT,
31 - * @return a string value 31 + DRIVER_READ,
32 - */ 32 + DRIVER_WRITE,
33 - String actions(); 33 + FLOWRULE_READ,
34 + FLOWRULE_WRITE,
35 + FLOWRULE_EVENT,
36 + GROUP_READ,
37 + GROUP_WRITE,
38 + GROUP_EVENT,
39 + HOST_READ,
40 + HOST_WRITE,
41 + HOST_EVENT,
42 + INTENT_READ,
43 + INTENT_WRITE,
44 + INTENT_EVENT,
45 + LINK_READ,
46 + LINK_WRITE,
47 + LINK_EVENT,
48 + PACKET_READ,
49 + PACKET_WRITE,
50 + PACKET_EVENT,
51 + STATISTIC_READ,
52 + TOPOLOGY_READ,
53 + TOPOLOGY_EVENT,
54 + TUNNEL_READ,
55 + TUNNEL_WRITE,
56 + TUNNEL_EVENT,
57 + STORAGE_WRITE
34 } 58 }
......
...@@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableList; ...@@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.ImmutableSet; 19 import com.google.common.collect.ImmutableSet;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.onosproject.core.ApplicationRole; 21 import org.onosproject.core.ApplicationRole;
22 -import org.onosproject.core.DefaultPermission;
23 import org.onosproject.core.Permission; 22 import org.onosproject.core.Permission;
24 import org.onosproject.core.Version; 23 import org.onosproject.core.Version;
25 24
...@@ -29,8 +28,6 @@ import java.util.Set; ...@@ -29,8 +28,6 @@ import java.util.Set;
29 28
30 import static org.junit.Assert.assertEquals; 29 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertTrue; 30 import static org.junit.Assert.assertTrue;
32 -import static org.onosproject.core.DefaultPermission.Type.FLOWRULE_WRITE;
33 -import static org.onosproject.core.DefaultPermission.Type.FLOWRULE_READ;
34 31
35 32
36 /** 33 /**
...@@ -43,8 +40,7 @@ public class DefaultApplicationDescriptionTest { ...@@ -43,8 +40,7 @@ public class DefaultApplicationDescriptionTest {
43 public static final String DESC = "Awesome application from Circus"; 40 public static final String DESC = "Awesome application from Circus";
44 public static final String ORIGIN = "Circus"; 41 public static final String ORIGIN = "Circus";
45 public static final ApplicationRole ROLE = ApplicationRole.ADMIN; 42 public static final ApplicationRole ROLE = ApplicationRole.ADMIN;
46 - public static final Set<Permission> PERMS = ImmutableSet.of(new DefaultPermission(FLOWRULE_WRITE), 43 + public static final Set<Permission> PERMS = ImmutableSet.of(Permission.FLOWRULE_WRITE, Permission.FLOWRULE_READ);
47 - new DefaultPermission(FLOWRULE_READ));
48 public static final URI FURL = URI.create("mvn:org.foo-features/1.2a/xml/features"); 44 public static final URI FURL = URI.create("mvn:org.foo-features/1.2a/xml/features");
49 public static final List<String> FEATURES = ImmutableList.of("foo", "bar"); 45 public static final List<String> FEATURES = ImmutableList.of("foo", "bar");
50 46
......
...@@ -28,7 +28,6 @@ import org.onosproject.app.ApplicationException; ...@@ -28,7 +28,6 @@ import org.onosproject.app.ApplicationException;
28 import org.onosproject.app.ApplicationStoreDelegate; 28 import org.onosproject.app.ApplicationStoreDelegate;
29 import org.onosproject.app.DefaultApplicationDescription; 29 import org.onosproject.app.DefaultApplicationDescription;
30 import org.onosproject.core.ApplicationRole; 30 import org.onosproject.core.ApplicationRole;
31 -import org.onosproject.core.DefaultPermission;
32 import org.onosproject.core.Permission; 31 import org.onosproject.core.Permission;
33 import org.onosproject.core.Version; 32 import org.onosproject.core.Version;
34 import org.onosproject.store.AbstractStore; 33 import org.onosproject.store.AbstractStore;
...@@ -378,21 +377,20 @@ public class ApplicationArchive ...@@ -378,21 +377,20 @@ public class ApplicationArchive
378 377
379 // Returns the set of Permissions specified in the app.xml file 378 // Returns the set of Permissions specified in the app.xml file
380 private ImmutableSet<Permission> getPermissions(XMLConfiguration cfg) { 379 private ImmutableSet<Permission> getPermissions(XMLConfiguration cfg) {
381 - List<Permission> perms = new ArrayList(); 380 + List<Permission> permissionList = new ArrayList();
382 for (Object o : cfg.getList(PERMISSIONS)) { 381 for (Object o : cfg.getList(PERMISSIONS)) {
383 - DefaultPermission perm = null; 382 + String name = (String) o;
384 - if (o != null) { 383 + try {
385 - String permStr = (String) o; 384 + Permission perm = Permission.valueOf(name);
386 - perm = new DefaultPermission(permStr); 385 + permissionList.add(perm);
387 - } 386 + } catch (IllegalArgumentException e) {
388 - if (perm != null) { 387 + log.debug("Unknown permission specified: %s", name);
389 - perms.add(perm);
390 } 388 }
391 } 389 }
392 - 390 + return ImmutableSet.copyOf(permissionList);
393 - return ImmutableSet.copyOf(perms);
394 } 391 }
395 392
393 + //
396 // Returns application role type 394 // Returns application role type
397 public ApplicationRole getRole(String value) { 395 public ApplicationRole getRole(String value) {
398 if (value == null) { 396 if (value == null) {
......
...@@ -25,11 +25,9 @@ import org.onosproject.common.app.ApplicationArchive; ...@@ -25,11 +25,9 @@ import org.onosproject.common.app.ApplicationArchive;
25 import org.onosproject.core.Application; 25 import org.onosproject.core.Application;
26 import org.onosproject.core.ApplicationId; 26 import org.onosproject.core.ApplicationId;
27 import org.onosproject.core.Permission; 27 import org.onosproject.core.Permission;
28 -import org.onosproject.core.DefaultPermission;
29 import org.onosproject.core.ApplicationIdStoreAdapter; 28 import org.onosproject.core.ApplicationIdStoreAdapter;
30 import org.onosproject.core.DefaultApplicationId; 29 import org.onosproject.core.DefaultApplicationId;
31 30
32 -import static org.onosproject.core.DefaultPermission.Type.FLOWRULE_WRITE;
33 import static org.junit.Assert.assertEquals; 31 import static org.junit.Assert.assertEquals;
34 import static org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED; 32 import static org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED;
35 import static org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED; 33 import static org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED;
...@@ -106,7 +104,7 @@ public class SimpleApplicationStoreTest { ...@@ -106,7 +104,7 @@ public class SimpleApplicationStoreTest {
106 @Test 104 @Test
107 public void permissions() { 105 public void permissions() {
108 Application app = createTestApp(); 106 Application app = createTestApp();
109 - ImmutableSet<Permission> permissions = ImmutableSet.of(new DefaultPermission(FLOWRULE_WRITE)); 107 + ImmutableSet<Permission> permissions = ImmutableSet.of(Permission.FLOWRULE_WRITE);
110 store.setPermissions(app.id(), permissions); 108 store.setPermissions(app.id(), permissions);
111 assertEquals("incorrect app perms", 1, store.getPermissions(app.id()).size()); 109 assertEquals("incorrect app perms", 1, store.getPermissions(app.id()).size());
112 assertEquals("incorrect app state", INSTALLED, store.getState(app.id())); 110 assertEquals("incorrect app state", INSTALLED, store.getState(app.id()));
......