• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 package org.apache.harmony.javax.security.auth;
19 
20 import java.security.BasicPermission;
21 
22 
23 
24 /**
25  * Governs the use of methods in this package and also its subpackages. A
26  * <i>target name</i> of the permission specifies which methods are allowed
27  * without specifying the concrete action lists. Possible target names and
28  * associated authentication permissions are:
29  *
30  * <pre>
31  *    doAs                      invoke Subject.doAs methods.
32  *    doAsPrivileged            invoke the Subject.doAsPrivileged methods.
33  *    getSubject                invoke Subject.getSubject().
34  *    getSubjectFromDomainCombiner    invoke SubjectDomainCombiner.getSubject().
35  *    setReadOnly               invoke Subject.setReadonly().
36  *    modifyPrincipals          modify the set of principals
37  *                              associated with a Subject.
38  *    modifyPublicCredentials   modify the set of public credentials
39  *                              associated with a Subject.
40  *    modifyPrivateCredentials  modify the set of private credentials
41  *                              associated with a Subject.
42  *    refreshCredential         invoke the refresh method on a credential of a
43  *                              refreshable credential class.
44  *    destroyCredential         invoke the destroy method on a credential of a
45  *                              destroyable credential class.
46  *    createLoginContext.<i>name</i>   instantiate a LoginContext with the
47  *                              specified name. The wildcard name ('*')
48  *                              allows to a LoginContext of any name.
49  *    getLoginConfiguration     invoke the getConfiguration method of
50  *                              javax.security.auth.login.Configuration.
51  *    refreshLoginConfiguration Invoke the refresh method of
52  *                              javax.security.auth.login.Configuration.
53  * </pre>
54  */
55 public final class AuthPermission extends BasicPermission {
56 
57     private static final long serialVersionUID = 5806031445061587174L;
58 
59     private static final String CREATE_LOGIN_CONTEXT = "createLoginContext"; //$NON-NLS-1$
60 
61     private static final String CREATE_LOGIN_CONTEXT_ANY = "createLoginContext.*"; //$NON-NLS-1$
62 
63     // inits permission name.
init(String name)64     private static String init(String name) {
65 
66         if (name == null) {
67             throw new NullPointerException("auth.13"); //$NON-NLS-1$
68         }
69 
70         if (CREATE_LOGIN_CONTEXT.equals(name)) {
71             return CREATE_LOGIN_CONTEXT_ANY;
72         }
73         return name;
74     }
75 
76     /**
77      * Creates an authentication permission with the specified target name.
78      *
79      * @param name
80      *            the target name of this authentication permission.
81      */
AuthPermission(String name)82     public AuthPermission(String name) {
83         super(init(name));
84     }
85 
86     /**
87      * Creates an authentication permission with the specified target name.
88      *
89      * @param name
90      *            the target name of this authentication permission.
91      * @param actions
92      *            this parameter is ignored and should be {@code null}.
93      */
AuthPermission(String name, String actions)94     public AuthPermission(String name, String actions) {
95         super(init(name), actions);
96     }
97 }