KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > security > sas > GssUpContext


1 package org.jacorb.security.sas;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 2002-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import org.apache.avalon.framework.logger.Logger;
24 import org.apache.avalon.framework.configuration.Configuration;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26
27 import org.omg.CORBA.ORB JavaDoc;
28 import org.omg.CSIIOP.CompoundSecMechList;
29 import org.omg.GSSUP.GSSUPMechOID;
30 import org.omg.GSSUP.InitialContextToken;
31 import org.omg.IOP.Codec JavaDoc;
32
33 public class GssUpContext
34     implements ISASContext
35 {
36     private Logger logger = null;
37     private static String JavaDoc username = "";
38     private static String JavaDoc password = "";
39     protected InitialContextToken initialContextToken = null;
40
41     public void configure(Configuration configuration)
42         throws ConfigurationException
43     {
44         logger =
45             ((org.jacorb.config.Configuration)configuration).getNamedLogger("jacorb.security.sas.GSSUP");
46     }
47
48     public static void setUsernamePassword(String JavaDoc username, String JavaDoc password) {
49         GssUpContext.username = username;
50         GssUpContext.password = password;
51     }
52
53     public String JavaDoc getMechOID()
54     {
55         return GSSUPMechOID.value.substring(4);
56     }
57
58     /* (non-Javadoc)
59      * @see org.jacorb.security.sas.ISASContext#createContext(org.omg.PortableInterceptor.ClientRequestInfo)
60      */

61     public byte[] createClientContext(ORB JavaDoc orb, Codec JavaDoc codec, CompoundSecMechList csmList)
62     {
63         byte[] contextToken = GSSUPNameSpi.encode(orb, codec, username, password, new byte[0]);
64         initialContextToken = GSSUPNameSpi.decode(orb, codec, contextToken);
65         return contextToken;
66     }
67
68     /* (non-Javadoc)
69      * @see org.jacorb.security.sas.ISASContext#getCreatedPrincipal()
70      */

71     public String JavaDoc getClientPrincipal()
72     {
73         return username;
74     }
75
76     /* (non-Javadoc)
77      * @see org.jacorb.security.sas.ISASContext#validateContext(org.omg.PortableInterceptor.ServerRequestInfo, byte[])
78      */

79     public boolean validateContext(ORB JavaDoc orb, Codec JavaDoc codec, byte[] contextToken)
80     {
81         initialContextToken = GSSUPNameSpi.decode(orb, codec, contextToken);
82         return (initialContextToken != null);
83     }
84
85     /* (non-Javadoc)
86      * @see org.jacorb.security.sas.ISASContext#getValidatedPrincipal()
87      */

88     public String JavaDoc getValidatedPrincipal() {
89         if (initialContextToken == null) return null;
90         return new String JavaDoc(initialContextToken.username);
91     }
92
93     /* (non-Javadoc)
94      * @see org.jacorb.security.sas.ISASContext#initClient()
95      */

96     public void initClient() {
97     }
98
99     /* (non-Javadoc)
100      * @see org.jacorb.security.sas.ISASContext#initTarget()
101      */

102     public void initTarget() {
103     }
104 }
105
Popular Tags