001: package org.jacorb.security.sas;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 2002-2004 Gerald Brose
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import org.apache.avalon.framework.logger.Logger;
024: import org.apache.avalon.framework.configuration.Configuration;
025: import org.apache.avalon.framework.configuration.ConfigurationException;
026:
027: import org.omg.CORBA.ORB;
028: import org.omg.CSIIOP.CompoundSecMechList;
029: import org.omg.GSSUP.GSSUPMechOID;
030: import org.omg.GSSUP.InitialContextToken;
031: import org.omg.IOP.Codec;
032:
033: public class GssUpContext implements ISASContext {
034: private Logger logger = null;
035: private static String username = "";
036: private static String password = "";
037: protected InitialContextToken initialContextToken = null;
038:
039: public void configure(Configuration configuration)
040: throws ConfigurationException {
041: logger = ((org.jacorb.config.Configuration) configuration)
042: .getNamedLogger("jacorb.security.sas.GSSUP");
043: }
044:
045: public static void setUsernamePassword(String username,
046: String password) {
047: GssUpContext.username = username;
048: GssUpContext.password = password;
049: }
050:
051: public String getMechOID() {
052: return GSSUPMechOID.value.substring(4);
053: }
054:
055: /* (non-Javadoc)
056: * @see org.jacorb.security.sas.ISASContext#createContext(org.omg.PortableInterceptor.ClientRequestInfo)
057: */
058: public byte[] createClientContext(ORB orb, Codec codec,
059: CompoundSecMechList csmList) {
060: byte[] contextToken = GSSUPNameSpi.encode(orb, codec, username,
061: password, new byte[0]);
062: initialContextToken = GSSUPNameSpi.decode(orb, codec,
063: contextToken);
064: return contextToken;
065: }
066:
067: /* (non-Javadoc)
068: * @see org.jacorb.security.sas.ISASContext#getCreatedPrincipal()
069: */
070: public String getClientPrincipal() {
071: return username;
072: }
073:
074: /* (non-Javadoc)
075: * @see org.jacorb.security.sas.ISASContext#validateContext(org.omg.PortableInterceptor.ServerRequestInfo, byte[])
076: */
077: public boolean validateContext(ORB orb, Codec codec,
078: byte[] contextToken) {
079: initialContextToken = GSSUPNameSpi.decode(orb, codec,
080: contextToken);
081: return (initialContextToken != null);
082: }
083:
084: /* (non-Javadoc)
085: * @see org.jacorb.security.sas.ISASContext#getValidatedPrincipal()
086: */
087: public String getValidatedPrincipal() {
088: if (initialContextToken == null)
089: return null;
090: return new String(initialContextToken.username);
091: }
092:
093: /* (non-Javadoc)
094: * @see org.jacorb.security.sas.ISASContext#initClient()
095: */
096: public void initClient() {
097: }
098:
099: /* (non-Javadoc)
100: * @see org.jacorb.security.sas.ISASContext#initTarget()
101: */
102: public void initTarget() {
103: }
104: }
|