Debian Codegraph @

gss/src/main/java/org/globus/gsi/gssapi/auth/Authorization.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
20 /**
21 * Interface for authorization mechanisms.
22 * The authorization is performed once the connection was authenticated.
23 */
24 public abstract class Authorization {
25
26 /**
27 * Performes authorization checks. Throws
28 * <code>AuthorizationException</code> if the authorization fails.
29 * Otherwise, the function completes normally.
30 *
31 * @param context the securit context
32 * @param host host address of the peer.
33 * @exception AuthorizationException if the peer is
34 * not authorized to access/use the resource.
35 */
36 public abstract void authorize(GSSContext context, String host)
37 throws AuthorizationException;
38
39 protected void generateAuthorizationException(GSSName expected,
40 GSSName target)
41 throws AuthorizationException {
42
43 String lineSep = System.getProperty("line.separator");
44 StringBuffer msg = new StringBuffer();
45 msg.append("Mutual authentication failed").append(lineSep)
46 .append(" Expected target subject name=\"")
47 .append(expected.toString()).append("\"")
48 .append(lineSep)
49 .append(" Target returned subject name=\"")
50 .append(target.toString())
51 .append("\"");
52
53 throw new AuthorizationException(msg.toString());
54 }
55 }