Debian Codegraph @

gss/src/main/java/org/globus/gsi/gssapi/auth/HostOrSelfAuthorization.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.gssapi.auth;
16
17 import org.ietf.jgss.GSSContext;
18 import org.ietf.jgss.GSSName;
19 import org.ietf.jgss.GSSException;
20 import org.ietf.jgss.GSSCredential;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 public class HostOrSelfAuthorization extends GSSAuthorization {
26
27 private static Log logger =
28 LogFactory.getLog(HostOrSelfAuthorization.class.getName());
29
30 private static HostOrSelfAuthorization authorization;
31
32 private HostAuthorization hostAuthz;
33 /**
34 * Returns a single instance of this class.
35 *
36 * @return the instance of this class.
37 */
38 public synchronized static HostOrSelfAuthorization getInstance() {
39 if (authorization == null) {
40 authorization = new HostOrSelfAuthorization("host");
41 }
42 return authorization;
43 }
44
45 public HostOrSelfAuthorization(String service) {
46 if (service == null) {
47 service = "host";
48 }
49 this.hostAuthz = new HostAuthorization(service);
50 }
51
52 // returning null for now.
53 public GSSName getExpectedName(GSSCredential cred, String host)
54 throws GSSException {
55 return null;
56 }
57
58 /**
59 * Performs host authorization. If that fails, performs self authorization
60 */
61 public void authorize(GSSContext context, String host)
62 throws AuthorizationException {
63 logger.debug("Authorization: HOST/SELF");
64
65 try {
66
67 GSSName expected = this.hostAuthz.getExpectedName(null, host);
68
69 GSSName target = null;
70 if (context.isInitiator()) {
71 target = context.getTargName();
72 } else {
73 target = context.getSrcName();
74 }
75
76 if (!expected.equals(target)) {
77 logger.debug("Host authorization failed. Expected "
78 + expected + " target is " + target);
79
80 if (!context.getSrcName().equals(context.getTargName())) {
81 if (context.isInitiator()) {
82 expected = context.getSrcName();
83 } else {
84 expected = context.getTargName();
85 }
86 generateAuthorizationException(expected, target);
87 }
88 }
89 } catch (GSSException e) {
90 throw new AuthorizationException("Authorization failure", e);
91 }
92 }
93
94 }