1 package org.jacorb.security.ssl.iaik; 2 3 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 ; 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 46 47 public class ServerInvocationInterceptor 48 extends org.omg.CORBA.LocalObject 49 implements ServerRequestInterceptor 50 { 51 public static final String DEFAULT_NAME = "ServerInvocationInterceptor"; 52 53 private String 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 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 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 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 |