1 package org.jacorb.security.level2; 2 3 22 23 24 import org.omg.Security.*; 25 import org.omg.SecurityLevel2.*; 26 27 import java.io.*; 28 import java.util.*; 29 import java.math.BigInteger ; 30 31 32 38 39 public class CredentialsImpl 40 extends org.omg.CORBA.LocalObject 41 implements org.omg.SecurityLevel2.Credentials, 42 Serializable { 44 private SecAttribute[] my_attributes; 45 46 private short accepting_options_supported; 47 private short accepting_options_required; 48 private short invocation_options_supported; 49 private short invocation_options_required; 50 51 private AuthenticationStatus authStatus = null; 52 private InvocationCredentialsType type = null; 53 54 55 private boolean [] securityFeaturesForRequests; 56 private boolean [] securityFeaturesForReplies; 57 58 59 61 private SecAttributeManager attrib_mgr = null; 62 63 private boolean dirty = true; 64 65 public CredentialsImpl( SecAttribute[] attributes, 66 AuthenticationStatus status, 67 InvocationCredentialsType type ) 68 { 69 this.authStatus = status; 70 this.my_attributes = attributes; 71 this.type = type; 72 73 attrib_mgr = SecAttributeManager.getInstance(); 74 } 75 76 81 85 90 93 96 public Credentials copy() 97 { 98 try 99 { 100 PipedOutputStream pipe_out = new PipedOutputStream(); 101 PipedInputStream pipe_in = new PipedInputStream(pipe_out); 102 103 ObjectOutputStream out = new ObjectOutputStream(pipe_out); 104 out.writeObject(this); 105 out.flush(); 106 out.close(); 107 108 ObjectInputStream in = new ObjectInputStream(pipe_in); 109 CredentialsImpl creds = (CredentialsImpl) in.readObject(); 110 in.close(); 111 112 pipe_in.close(); 113 pipe_out.close(); 114 115 return creds; 117 } 118 catch (Exception e) 119 { 120 } 121 return null; 122 } 123 124 public InvocationCredentialsType credentials_type() 125 { 126 return type; 127 } 128 129 public AuthenticationStatus authentication_state() 130 { 131 return authStatus; 132 } 133 134 public String mechanism() 135 { 136 return null; 137 } 138 139 public short accepting_options_supported() 140 { 141 return accepting_options_supported; 142 } 143 144 public void accepting_options_supported(short arg) 145 { 146 accepting_options_supported = arg; 147 } 148 149 public short accepting_options_required() 150 { 151 return accepting_options_required; 152 } 153 154 public void accepting_options_required(short arg) 155 { 156 accepting_options_required = arg; 157 } 158 159 public short invocation_options_supported() 160 { 161 return invocation_options_supported; 162 } 163 164 public void invocation_options_supported(short arg) 165 { 166 invocation_options_supported = arg; 167 } 168 169 public short invocation_options_required() 170 { 171 return invocation_options_required; 172 } 173 174 public void invocation_options_required(short arg) 175 { 176 invocation_options_required = arg; 177 } 178 179 188 public SecAttribute[] get_attributes(AttributeType[] types) 189 { 190 if( types == null || types.length == 0 ) 191 return my_attributes; 192 193 194 Vector v = new Vector(); 195 for( int i = 0; i < types.length; i++ ) 196 { 197 for( int j = 0; j < my_attributes.length; j++ ) 198 { 199 200 if(( my_attributes[j].attribute_type.attribute_family.family == 201 types[i].attribute_family.family) && 202 ( my_attributes[j].attribute_type.attribute_type == 203 types[i].attribute_type )) 204 { 205 v.addElement(my_attributes[j]); 206 } 207 } 208 } 209 210 SecAttribute[] result = new SecAttribute[ v.size() ]; 211 v.copyInto( result ); 212 213 return result; 214 } 215 216 public void destroy() 217 { 218 } 219 220 public void set_security_feature(CommunicationDirection direction, 221 SecurityFeature[] security_features) 222 { 223 switch( direction.value() ) 224 { 225 case CommunicationDirection._SecDirectionRequest: 226 setFeatures( securityFeaturesForRequests, security_features); 227 228 case CommunicationDirection._SecDirectionReply: 229 setFeatures( securityFeaturesForReplies, security_features); 230 231 case CommunicationDirection._SecDirectionBoth: 232 setFeatures( securityFeaturesForRequests, security_features); 233 setFeatures( securityFeaturesForReplies, security_features); 234 } 235 } 236 237 private void setFeatures( boolean[] target, SecurityFeature[] features ) 238 { 239 if( features.length > target.length ) 240 throw new IllegalArgumentException ("Too many features"); 241 242 for( int i = 0; i < features.length; i++ ) 243 { 244 int value = features[i].value(); 245 if( value > target.length || value < 0) 246 { 247 throw new IllegalArgumentException ("SecurityFeatureValue out of range"); 248 } 249 target[ value ] = true; 250 } 251 } 252 253 254 public boolean get_security_feature(CommunicationDirection direction, 255 org.omg.Security.SecurityFeature feature) 256 { 257 switch( direction.value() ) 258 { 259 case CommunicationDirection._SecDirectionRequest: 260 return securityFeaturesForRequests[feature.value()]; 261 262 case CommunicationDirection._SecDirectionReply: 263 return securityFeaturesForReplies[feature.value()]; 264 265 default: return securityFeaturesForRequests[feature.value()] && 267 securityFeaturesForReplies[feature.value()]; 268 269 } 270 } 271 272 277 public boolean set_privileges(boolean force_commit, 278 SecAttribute[] requested_privileges, 279 AttributeListHolder actual_privileges) 280 { 281 for( int i = 0; i < requested_privileges.length; i++ ) 283 { 284 if( attrib_mgr.getAttributeValue( requested_privileges[i] ) 285 == null ) 286 { 287 throw new RuntimeException ( "SecAttribute not created by Manager" ); 288 } 289 } 290 291 Vector additional_privileges = new Vector(); 293 294 for (int i = 0; i < requested_privileges.length; i++) 295 if ( requested_privileges[i].attribute_type.attribute_family.family == 296 (short) 1 ) { 298 additional_privileges.addElement( requested_privileges[i] ); 299 } 300 301 if (additional_privileges.size() > 0) 302 { 303 SecAttribute[] tmp = new SecAttribute[my_attributes.length + 304 additional_privileges.size()]; 305 306 System.arraycopy( my_attributes, 0, 308 tmp, 0, 309 my_attributes.length ); 310 311 for ( int i = 0; i < additional_privileges.size(); i++ ) 313 { 314 SecAttribute attrib = (SecAttribute) 315 additional_privileges.elementAt( i ); 316 317 tmp[my_attributes.length + i] = attrib; 318 } 319 320 my_attributes = tmp; 321 actual_privileges.value = tmp; 322 323 dirty = true; 324 325 return true; 326 } 327 else 328 return false; 329 } 330 331 public boolean is_valid(org.omg.TimeBase.UtcTHolder expiry_time) 332 { 333 return false; 334 } 335 336 public boolean refresh(byte[] refresh_data) 337 { 338 return false; 339 } 340 341 344 345 public boolean isDirty() 346 { 347 return dirty; 348 } 349 350 public void clearDirtyFlag() 351 { 352 dirty = false; 353 } 354 } 355 | Popular Tags |