blob: 4b80dfcdc9a40b705649435b318e26af484d1761 [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
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090019
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070020import com.google.common.annotations.Beta;
21
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090022/**
Changhoon Yoon541ef712015-05-23 17:18:34 +090023 * Aids SM-ONOS to perform API-level permission checking.
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090024 */
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070025@Beta
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090026public final class AppGuard {
27
28 private AppGuard() {
29 }
30
Changhoon Yoon541ef712015-05-23 17:18:34 +090031 /**
32 * Checks if the caller has the required permission only when security-mode is enabled.
33 * @param permission permission to be checked
34 */
Changhoon Yoonb856b812015-08-10 03:47:19 +090035 public static void checkPermission(AppPermission.Type permission) {
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090036 SecurityManager sm = System.getSecurityManager();
37 if (sm != null) {
Changhoon Yoonb856b812015-08-10 03:47:19 +090038 System.getSecurityManager().checkPermission(new AppPermission(permission));
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090039 }
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090040 }
41}