Debian Codegraph @

ssl-proxies/src/main/java/org/globus/gsi/gridmap/GridMapLocal.java

raw
1 /*
2 * Copyright 1999-2010 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied.
12 *
13 * See the License for the specific language governing permissions and limitations under the License.
14 */
15 package org.globus.gsi.gridmap;
16
17 /**
18 * Gridmap implementation with a local username lookup feature.
19 * If the gridmap is uninitialized the <tt>getUserID</tt>, <tt>getUserIDs</tt>,
20 * and <tt>checkUser</tt> functions will effectively ignore their
21 * <tt>globusID</tt> parameter. For example, <tt>getUserID</tt> and
22 * <tt>getUserIDs</tt> will return the local user name for any
23 * <tt>globusID</tt>.
24 */
25 public class GridMapLocal extends GridMap {
26
27 public String[] getUserIDs(String globusID) {
28 String [] userIDs = super.getUserIDs(globusID);
29
30 if (userIDs == null && this.map == null) {
31 String user = getLocalUsername();
32 return (user == null) ? null : new String[] {user};
33 }
34
35 return userIDs;
36 }
37
38 public boolean checkUser(String globusID, String userID) {
39 boolean result = super.checkUser(globusID, userID);
40
41 if (!result && this.map == null) {
42 String user = getLocalUsername();
43 return (user == null) ? false : user.equalsIgnoreCase(userID);
44 }
45
46 return result;
47 }
48
49 private String getLocalUsername() {
50 String user = System.getProperty("user.name");
51 if (user == null) {
52 return null;
53 }
54 String tmpUser = user.toLowerCase();
55 return (tmpUser.equals("root") || tmpUser.equals("administrator"))
56 ? null : user;
57 }
58
59 }