blob: d3cc4233d9b436e2ab21d0972caf1dfb57666c43 [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;
18
19import org.onosproject.core.Permission;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090020
21/**
Changhoon Yoon541ef712015-05-23 17:18:34 +090022 * Aids SM-ONOS to perform API-level permission checking.
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090023 */
24public final class AppGuard {
25
26 private AppGuard() {
27 }
28
Changhoon Yoon541ef712015-05-23 17:18:34 +090029 /**
30 * Checks if the caller has the required permission only when security-mode is enabled.
31 * @param permission permission to be checked
32 */
33 public static void checkPermission(Permission permission) {
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090034 SecurityManager sm = System.getSecurityManager();
35 if (sm != null) {
Changhoon Yoon541ef712015-05-23 17:18:34 +090036 System.getSecurityManager().checkPermission(new AppPermission(permission.name()));
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090037 }
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090038 }
39}