1 /*
2  * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package java.nio.file.attribute;
27 
28 import java.io.IOException;
29 
30 /**
31  * An object to lookup user and group principals by name. A {@link UserPrincipal}
32  * represents an identity that may be used to determine access rights to objects
33  * in a file system. A {@link GroupPrincipal} represents a <em>group identity</em>.
34  * A {@code UserPrincipalLookupService} defines methods to lookup identities by
35  * name or group name (which are typically user or account names). Whether names
36  * and group names are case sensitive or not depends on the implementation.
37  * The exact definition of a group is implementation specific but typically a
38  * group represents an identity created for administrative purposes so as to
39  * determine the access rights for the members of the group. In particular it is
40  * implementation specific if the <em>namespace</em> for names and groups is the
41  * same or is distinct. To ensure consistent and correct behavior across
42  * platforms it is recommended that this API be used as if the namespaces are
43  * distinct. In other words, the {@link #lookupPrincipalByName
44  * lookupPrincipalByName} should be used to lookup users, and {@link
45  * #lookupPrincipalByGroupName lookupPrincipalByGroupName} should be used to
46  * lookup groups.
47  *
48  * @since 1.7
49  *
50  * @see java.nio.file.FileSystem#getUserPrincipalLookupService
51  */
52 
53 public abstract class UserPrincipalLookupService {
54 
55     /**
56      * Initializes a new instance of this class.
57      */
UserPrincipalLookupService()58     protected UserPrincipalLookupService() {
59     }
60 
61     /**
62      * Lookup a user principal by name.
63      *
64      * @param   name
65      *          the string representation of the user principal to lookup
66      *
67      * @return  a user principal
68      *
69      * @throws  UserPrincipalNotFoundException
70      *          the principal does not exist
71      * @throws  IOException
72      *          if an I/O error occurs
73      * @throws  SecurityException
74      *          In the case of the default provider, and a security manager is
75      *          installed, it checks {@link RuntimePermission}<tt>("lookupUserInformation")</tt>
76      */
lookupPrincipalByName(String name)77     public abstract UserPrincipal lookupPrincipalByName(String name)
78         throws IOException;
79 
80     /**
81      * Lookup a group principal by group name.
82      *
83      * <p> Where an implementation does not support any notion of group then
84      * this method always throws {@link UserPrincipalNotFoundException}. Where
85      * the namespace for user accounts and groups is the same, then this method
86      * is identical to invoking {@link #lookupPrincipalByName
87      * lookupPrincipalByName}.
88      *
89      * @param   group
90      *          the string representation of the group to lookup
91      *
92      * @return  a group principal
93      *
94      * @throws  UserPrincipalNotFoundException
95      *          the principal does not exist or is not a group
96      * @throws  IOException
97      *          if an I/O error occurs
98      * @throws  SecurityException
99      *          In the case of the default provider, and a security manager is
100      *          installed, it checks {@link RuntimePermission}<tt>("lookupUserInformation")</tt>
101      */
lookupPrincipalByGroupName(String group)102     public abstract GroupPrincipal lookupPrincipalByGroupName(String group)
103         throws IOException;
104 }
105