1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package java.security;
19
20/**
21 * {@code AccessControlException} is thrown if the access control infrastructure
22 * denies protected access due to missing permissions.
23 */
24public class AccessControlException extends SecurityException {
25
26    private static final long serialVersionUID = 5138225684096988535L;
27
28    private Permission perm; // Named as demanded by Serialized Form.
29
30    /**
31     * Constructs a new instance of {@code AccessControlException} with the
32     * given message.
33     *
34     * @param message
35     *            the detail message for this exception.
36     */
37    public AccessControlException(String message) {
38        super(message);
39    }
40
41    /**
42     * Constructs a new instance of {@code AccessControlException} with the
43     * given message and the requested {@code Permission} which was not granted.
44     *
45     * @param message
46     *            the detail message for the exception.
47     * @param perm
48     *            the requested {@code Permission} which was not granted.
49     */
50    public AccessControlException(String message, Permission perm) {
51        super(message);
52        this.perm = perm;
53    }
54
55    /**
56     * Returns the requested permission that caused this Exception or {@code
57     * null} if there is no corresponding {@code Permission}.
58     *
59     * @return the requested permission that caused this Exception, maybe {@code null}.
60     */
61    public Permission getPermission() {
62        return perm;
63    }
64}
65