| 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.gridforum.jgss.ExtendedGSSManager; |
| 18 |
|
| 19 |
import org.ietf.jgss.GSSManager; |
| 20 |
import org.ietf.jgss.GSSContext; |
| 21 |
import org.ietf.jgss.GSSName; |
| 22 |
import org.ietf.jgss.GSSException; |
| 23 |
import org.ietf.jgss.GSSCredential; |
| 24 |
|
| 25 |
import org.apache.commons.logging.Log; |
| 26 |
import org.apache.commons.logging.LogFactory; |
| 27 |
|
| 28 |
/** |
| 29 |
* Performs the identity authorization check. The identity |
| 30 |
* is obtained from specified Globus credentials. |
| 31 |
*/ |
| 32 |
public class SelfAuthorization |
| 33 |
extends GSSAuthorization { |
| 34 |
|
| 35 |
private static Log logger = |
| 36 |
LogFactory.getLog(SelfAuthorization.class.getName()); |
| 37 |
|
| 38 |
private static SelfAuthorization authorization; |
| 39 |
|
| 40 |
/** |
| 41 |
* Returns a single instance of this class. |
| 42 |
* |
| 43 |
* @return the instance of this class. |
| 44 |
*/ |
| 45 |
public synchronized static SelfAuthorization getInstance() { |
| 46 |
if (authorization == null) { |
| 47 |
authorization = new SelfAuthorization(); |
| 48 |
} |
| 49 |
return authorization; |
| 50 |
} |
| 51 |
|
| 52 |
public GSSName getExpectedName(GSSCredential cred, String host) |
| 53 |
throws GSSException { |
| 54 |
if (cred == null) { |
| 55 |
GSSManager manager = ExtendedGSSManager.getInstance(); |
| 56 |
cred = manager.createCredential(GSSCredential.INITIATE_AND_ACCEPT); |
| 57 |
} |
| 58 |
return cred.getName(); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Performs self authorization. |
| 63 |
*/ |
| 64 |
public void authorize(GSSContext context, String host) |
| 65 |
throws AuthorizationException { |
| 66 |
logger.debug("Authorization: SELF"); |
| 67 |
|
| 68 |
try { |
| 69 |
if (!context.getSrcName().equals(context.getTargName())) { |
| 70 |
GSSName expected = null; |
| 71 |
GSSName target = null; |
| 72 |
if (context.isInitiator()) { |
| 73 |
expected = context.getSrcName(); |
| 74 |
target = context.getTargName(); |
| 75 |
} else { |
| 76 |
expected = context.getTargName(); |
| 77 |
target = context.getSrcName(); |
| 78 |
} |
| 79 |
generateAuthorizationException(expected, target); |
| 80 |
} |
| 81 |
} catch (GSSException e) { |
| 82 |
throw new AuthorizationException("Authorization failure", e); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
} |