KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > security > ssl > iaik > ServerInvocationInterceptor


1 package org.jacorb.security.ssl.iaik;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 2000-2004 Nicolas Noffke, 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 java.io.*;
24 import org.omg.SecurityReplaceable.*;
25 import org.omg.Security.*;
26 import org.omg.SecurityLevel2.ReceivedCredentials;
27
28 import org.omg.PortableInterceptor.*;
29 import org.omg.CORBA.ORBPackage.*;
30 import org.omg.CORBA.Any JavaDoc;
31
32 import org.jacorb.orb.portableInterceptor.ServerRequestInfoImpl;
33 import org.jacorb.security.level2.*;
34 import org.jacorb.orb.dsi.ServerRequest;
35 import org.jacorb.orb.iiop.*;
36 import org.jacorb.orb.giop.*;
37
38 import iaik.security.ssl.SSLSocket;
39
40 /**
41  *
42  *
43  * @author Nicolas Noffke
44  * $Id: ServerInvocationInterceptor.java,v 1.12 2004/05/06 12:40:01 nicolas Exp $
45  */

46
47 public class ServerInvocationInterceptor
48     extends org.omg.CORBA.LocalObject JavaDoc
49     implements ServerRequestInterceptor
50 {
51     public static final String JavaDoc DEFAULT_NAME = "ServerInvocationInterceptor";
52
53     private String JavaDoc name = null;
54
55     private org.jacorb.security.level2.CurrentImpl current = null;
56     private SecAttributeManager attrib_mgr = null;
57     private AttributeType type = null;
58     
59     public ServerInvocationInterceptor(org.omg.SecurityLevel2.Current current)
60     {
61         this( current, DEFAULT_NAME );
62     }
63
64     public ServerInvocationInterceptor( org.omg.SecurityLevel2.Current current,
65                                         String JavaDoc name )
66     {
67         this.current = (CurrentImpl) current;
68         this.name = name;
69
70         attrib_mgr = SecAttributeManager.getInstance();
71
72         type = new AttributeType
73             ( new ExtensibleFamily( (short) 0,
74                                     (short) 1 ),
75               AccessId.value );
76     }
77
78     public String JavaDoc name()
79     {
80         return name;
81     }
82
83     public void destroy()
84     {
85     }
86
87     public void receive_request( ServerRequestInfo ri )
88         throws ForwardRequest
89     {
90     }
91
92
93     public void receive_request_service_contexts( ServerRequestInfo ri )
94         throws ForwardRequest
95     {
96         ServerRequest request = ((ServerRequestInfoImpl) ri).request;
97         
98         GIOPConnection connection = request.getConnection();
99         
100         // lookup for context
101
if (connection == null)
102         {
103             return;
104         }
105         
106         if( !connection.isSSL() )
107         {
108             return;
109         }
110             
111         ServerIIOPConnection transport =
112             (ServerIIOPConnection) connection.getTransport();
113         
114         SSLSocket sslSocket = (SSLSocket) transport.getSocket();
115         
116         KeyAndCert kac = new KeyAndCert( null,
117                                          sslSocket.getPeerCertificateChain() );
118         
119         if( kac.chain == null )
120         {
121             return;
122         }
123         
124         SecAttribute [] atts = new SecAttribute[] {
125             attrib_mgr.createAttribute( kac, type ) } ;
126         
127         current.set_received_credentials( new ReceivedCredentialsImpl( atts ) );
128     }
129
130     public void send_reply( ServerRequestInfo ri )
131     {
132         removeAttribute();
133         current.remove_received_credentials();
134     }
135
136     public void send_exception( ServerRequestInfo ri )
137         throws ForwardRequest
138     {
139         removeAttribute();
140         current.remove_received_credentials();
141     }
142
143     public void send_other( ServerRequestInfo ri )
144         throws ForwardRequest
145     {
146         removeAttribute();
147         current.remove_received_credentials();
148     }
149
150     private void removeAttribute()
151     {
152         ReceivedCredentials creds = current.received_credentials();
153
154         if (creds == null)
155         {
156             return;
157         }
158
159         SecAttribute[] attributes = creds.get_attributes(
160             new AttributeType[]{ type } );
161
162         if (attributes.length != 0)
163         {
164             attrib_mgr.removeAttribute(attributes[0]);
165         }
166     }
167
168 }
169
170
171
172
173
174
175
176
Popular Tags