idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
39,300
public static String getStatusAsString ( int status ) { if ( status == STATUS_PENDING ) { return "PENDING" ; } else if ( status == STATUS_ACTIVE ) { return "ACTIVE" ; } else if ( status == STATUS_DONE ) { return "DONE" ; } else if ( status == STATUS_FAILED ) { return "FAILED" ; } else if ( status == STATUS_SUSPENDED ) { return "SUSPENDED" ; } else if ( status == STATUS_UNSUBMITTED ) { return "UNSUBMITTED" ; } else if ( status == STATUS_STAGE_IN ) { return "STAGE_IN" ; } else if ( status == STATUS_STAGE_OUT ) { return "STAGE_OUT" ; } return "Unknown" ; }
Convert the status of a GramJob from an integer to a string . This method is not typically called by users .
39,301
public void registerJob ( GramJob job ) { String id = job . getIDAsString ( ) ; _jobs . put ( id , job ) ; }
Registers gram job to listen for status updates
39,302
public void unregisterJob ( GramJob job ) { String id = job . getIDAsString ( ) ; _jobs . remove ( id ) ; }
Unregisters gram job from listening to status updates
39,303
public void authorize ( GSSContext context , String host ) throws AuthorizationException { logger . debug ( "Authorization: HOST/SELF" ) ; try { GSSName expected = this . hostAuthz . getExpectedName ( null , host ) ; GSSName target = null ; if ( context . isInitiator ( ) ) { target = context . getTargName ( ) ; } else { target = context . getSrcName ( ) ; } if ( ! expected . equals ( target ) ) { logger . debug ( "Host authorization failed. Expected " + expected + " target is " + target ) ; if ( ! context . getSrcName ( ) . equals ( context . getTargName ( ) ) ) { if ( context . isInitiator ( ) ) { expected = context . getSrcName ( ) ; } else { expected = context . getTargName ( ) ; } generateAuthorizationException ( expected , target ) ; } } } catch ( GSSException e ) { throw new AuthorizationException ( "Authorization failure" , e ) ; } }
Performs host authorization . If that fails performs self authorization
39,304
public X509Extension add ( X509Extension extension ) { if ( extension == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "extensionNull" ) ) ; } return ( X509Extension ) this . extensions . put ( extension . getOid ( ) , extension ) ; }
Adds a X509Extension object to this set .
39,305
public X509Extension get ( String oid ) { if ( oid == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "oidNull" ) ) ; } return ( X509Extension ) this . extensions . get ( oid ) ; }
Retrieves X509Extension by given oid .
39,306
protected String getHostBasedServiceCN ( boolean last ) { if ( hostBasedServiceCN == null ) { String dn = name . getName ( ) ; int cnStart ; if ( last ) { cnStart = dn . lastIndexOf ( "CN=" ) + 3 ; } else { cnStart = dn . indexOf ( "CN=" ) + 3 ; } if ( cnStart == - 1 ) { return null ; } int cnEnd = dn . indexOf ( "," , cnStart ) ; if ( cnEnd == - 1 ) { int nextAtt = dn . indexOf ( "=" , cnStart ) ; if ( nextAtt == - 1 ) { cnEnd = dn . length ( ) ; } else { return null ; } } hostBasedServiceCN = name . getName ( ) . substring ( cnStart , cnEnd ) ; } return hostBasedServiceCN ; }
Returns the CN corresponding to the host part of the DN
39,307
public void concat ( Value value ) { if ( concatValue != null ) { concatValue . concat ( value ) ; } else { concatValue = value ; } }
Appends the specified value to the end of the chain of concatinated values . That is if this value has no concatinated value then set the specified value as the concatinated value . If this value already has a concatinated value then append the specified value to that concatinated value .
39,308
public String evaluate ( Map symbolTable ) throws RslEvaluationException { if ( concatValue == null ) { return value ; } else { StringBuffer buf = new StringBuffer ( value ) ; buf . append ( concatValue . evaluate ( symbolTable ) ) ; return buf . toString ( ) ; } }
Evaluates the value with the specified symbol table . In this case the function just returns the string representation of the actual value . No symbol table lookups are performed .
39,309
public void toRSL ( StringBuffer buf , boolean explicitConcat ) { if ( explicitConcat ) { buf . append ( quotify ( value ) ) ; } else { buf . append ( value ) ; } if ( concatValue == null ) { return ; } if ( explicitConcat ) { buf . append ( " # " ) ; } concatValue . toRSL ( buf , explicitConcat ) ; }
Produces a RSL representation of this value .
39,310
public static void ping ( GSSCredential cred , String resourceManagerContact ) throws GramException , GSSException { ResourceManagerContact rmc = new ResourceManagerContact ( resourceManagerContact ) ; Socket socket = gatekeeperConnect ( cred , rmc , false , false ) ; HttpResponse hd = null ; try { OutputStream out = socket . getOutputStream ( ) ; InputStream in = socket . getInputStream ( ) ; String msg = GRAMProtocol . PING ( rmc . getServiceName ( ) , rmc . getHostName ( ) ) ; out . write ( msg . getBytes ( ) ) ; out . flush ( ) ; debug ( "PG SENT:" , msg ) ; hd = new HttpResponse ( in ) ; } catch ( IOException e ) { throw new GramException ( GramException . ERROR_PROTOCOL_FAILED , e ) ; } finally { try { socket . close ( ) ; } catch ( Exception e ) { } } debug ( "PG RECEIVED:" , hd ) ; checkHttpReply ( hd . httpCode ) ; }
Performs ping operation on the gatekeeper with specified user credentials . Verifies if the user is authorized to submit a job to that gatekeeper .
39,311
public static void request ( String resourceManagerContact , GramJob job ) throws GramException , GSSException { request ( resourceManagerContact , job , false ) ; }
Submits a GramJob to specified gatekeeper as an interactive job . Performs limited delegation .
39,312
public static void request ( String resourceManagerContact , GramJob job , boolean batchJob ) throws GramException , GSSException { request ( resourceManagerContact , job , batchJob , true ) ; }
Submits a GramJob to specified gatekeeper as a interactive or batch job . Performs limited delegation .
39,313
public static void request ( String resourceManagerContact , GramJob job , boolean batchJob , boolean limitedDelegation ) throws GramException , GSSException { GSSCredential cred = getJobCredentials ( job ) ; String callbackURL = null ; CallbackHandler handler = null ; if ( ! batchJob ) { handler = initCallbackHandler ( cred ) ; callbackURL = handler . getURL ( ) ; logger . debug ( "Callback url: " + callbackURL ) ; } else { callbackURL = "\"\"" ; } ResourceManagerContact rmc = new ResourceManagerContact ( resourceManagerContact ) ; Socket socket = gatekeeperConnect ( cred , rmc , true , limitedDelegation ) ; GatekeeperReply hd = null ; try { OutputStream out = socket . getOutputStream ( ) ; InputStream in = socket . getInputStream ( ) ; String msg = GRAMProtocol . REQUEST ( rmc . getServiceName ( ) , rmc . getHostName ( ) , GRAMConstants . STATUS_ALL , callbackURL , job . getRSL ( ) ) ; out . write ( msg . getBytes ( ) ) ; out . flush ( ) ; debug ( "REQ SENT:" , msg ) ; hd = new GatekeeperReply ( in ) ; } catch ( IOException e ) { throw new GramException ( GramException . ERROR_PROTOCOL_FAILED , e ) ; } finally { try { socket . close ( ) ; } catch ( Exception e ) { } } debug ( "REQ RECEIVED:" , hd ) ; checkHttpReply ( hd . httpCode ) ; checkProtocolVersion ( hd . protocolVersion ) ; if ( hd . status == 0 || hd . status == GramException . WAITING_FOR_COMMIT ) { try { job . setID ( hd . jobManagerUrl ) ; } catch ( MalformedURLException ex ) { throw new GramException ( GramException . INVALID_JOB_CONTACT , ex ) ; } if ( ! batchJob ) handler . registerJob ( job ) ; if ( hd . status == GramException . WAITING_FOR_COMMIT ) { throw new WaitingForCommitException ( ) ; } } else { throw new GramException ( hd . status ) ; } }
Submits a GramJob to specified gatekeeper as a interactive or batch job .
39,314
public static void renew ( GramJob job , GSSCredential newCred ) throws GramException , GSSException { renew ( job , newCred , true ) ; }
Requests that a globus job manager accept newly delegated credentials . Uses limited delegation .
39,315
public static void cancel ( GramJob job ) throws GramException , GSSException { GlobusURL jobURL = job . getID ( ) ; if ( jobURL == null ) { throw new GramException ( GramException . ERROR_JOB_CONTACT_NOT_SET ) ; } GSSCredential cred = getJobCredentials ( job ) ; String msg = GRAMProtocol . CANCEL_JOB ( jobURL . getURL ( ) , jobURL . getHost ( ) ) ; GatekeeperReply reply = jmConnect ( cred , jobURL , msg ) ; if ( reply . failureCode != 0 ) { throw new GramException ( reply . failureCode ) ; } }
This function cancels an already running job .
39,316
public static int jobSignal ( GramJob job , int signal , String arg ) throws GramException , GSSException { GlobusURL jobURL = job . getID ( ) ; GSSCredential cred = getJobCredentials ( job ) ; String msg = GRAMProtocol . SIGNAL ( jobURL . getURL ( ) , jobURL . getHost ( ) , signal , arg ) ; GatekeeperReply hd = null ; hd = jmConnect ( cred , jobURL , msg ) ; switch ( signal ) { case GramJob . SIGNAL_PRIORITY : return hd . failureCode ; case GramJob . SIGNAL_STDIO_SIZE : case GramJob . SIGNAL_STDIO_UPDATE : case GramJob . SIGNAL_COMMIT_REQUEST : case GramJob . SIGNAL_COMMIT_EXTEND : case GramJob . SIGNAL_COMMIT_END : case GramJob . SIGNAL_STOP_MANAGER : if ( hd . failureCode != 0 && hd . status == GramJob . STATUS_FAILED ) { throw new GramException ( hd . failureCode ) ; } else if ( hd . failureCode == 0 && hd . jobFailureCode != 0 ) { job . setError ( hd . jobFailureCode ) ; job . setStatus ( GramJob . STATUS_FAILED ) ; return hd . failureCode ; } else { job . setStatus ( hd . status ) ; return 0 ; } default : job . setStatus ( hd . status ) ; job . setError ( hd . failureCode ) ; return 0 ; } }
This function sends a signal to a job .
39,317
public static void unregisterListener ( GramJob job ) throws GramException , GSSException { CallbackHandler handler ; GSSCredential cred = getJobCredentials ( job ) ; handler = initCallbackHandler ( cred ) ; unregisterListener ( job , handler ) ; }
This function unregisters the job from callback listener . The job status will not be updated .
39,318
public static void deactivateAllCallbackHandlers ( ) { synchronized ( callbackHandlers ) { Enumeration e = callbackHandlers . elements ( ) ; while ( e . hasMoreElements ( ) ) { CallbackHandler handler = ( CallbackHandler ) e . nextElement ( ) ; handler . shutdown ( ) ; } callbackHandlers . clear ( ) ; } }
Deactivates all callback handlers .
39,319
public static CallbackHandler deactivateCallbackHandler ( GSSCredential cred ) { if ( cred == null ) { return null ; } CallbackHandler handler = ( CallbackHandler ) callbackHandlers . remove ( cred ) ; if ( handler == null ) { return null ; } handler . shutdown ( ) ; return handler ; }
Deactivates a callback handler for a given credential .
39,320
private static void debug ( String header , GatekeeperReply reply ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( header ) ; logger . trace ( reply . toString ( ) ) ; } }
Debug function for displaying the gatekeeper reply .
39,321
private static void debug ( String header , HttpResponse response ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( header ) ; logger . trace ( response . toString ( ) ) ; } }
Debug function for displaying HTTP responses .
39,322
private static void debug ( String header , String msg ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( header ) ; logger . trace ( msg ) ; } }
A general debug message that prints the header and msg when the debug level is smaler than 3
39,323
public void decrypt ( byte [ ] password ) throws GeneralSecurityException { if ( ! isEncrypted ( ) ) { return ; } byte [ ] enc = Base64 . decode ( this . encodedKey ) ; SecretKeySpec key = getSecretKey ( password , this . initializationVector . getIV ( ) ) ; Cipher cipher = getCipher ( ) ; cipher . init ( Cipher . DECRYPT_MODE , key , this . initializationVector ) ; enc = cipher . doFinal ( enc ) ; this . intKey = getKey ( this . keyAlg , enc ) ; this . keyData = enc ; this . isEncrypted = false ; this . encodedKey = null ; }
Decrypts the private key with given password . Does nothing if the key is not encrypted .
39,324
public void encrypt ( byte [ ] password ) throws GeneralSecurityException { if ( isEncrypted ( ) ) { return ; } if ( this . encAlg == null ) { setEncryptionAlgorithm ( "DES-EDE3-CBC" ) ; } if ( this . ivData == null ) { generateIV ( ) ; } Key key = getSecretKey ( password , this . initializationVector . getIV ( ) ) ; Cipher cipher = getCipher ( ) ; cipher . init ( Cipher . ENCRYPT_MODE , key , this . initializationVector ) ; this . keyData = cipher . doFinal ( getEncoded ( this . intKey ) ) ; this . isEncrypted = true ; this . encodedKey = null ; }
Encrypts the private key with given password . Does nothing if the key is encrypted already .
39,325
public void writeTo ( String file ) throws IOException { File privateKey = FileUtil . createFile ( file ) ; try { privateKey . setReadable ( false , true ) ; privateKey . setWritable ( false , true ) ; } catch ( SecurityException e ) { } PrintWriter p = new PrintWriter ( new FileOutputStream ( privateKey ) ) ; try { p . write ( toPEM ( ) ) ; } finally { p . close ( ) ; } }
Writes the private key to the specified file in PEM format . If the key was encrypted it will be encoded as an encrypted RSA key . If not it will be encoded as a regular RSA key .
39,326
private static boolean objectsEquals ( Object a , Object b ) { return ( a == b ) || ( a != null && a . equals ( b ) ) ; }
Java 7 is adopted
39,327
public synchronized void add ( SocketBox sb ) { int status = ( ( ManagedSocketBox ) sb ) . getStatus ( ) ; if ( allSockets . containsKey ( sb ) ) { throw new IllegalArgumentException ( "This socket already exists in the socket pool." ) ; } allSockets . put ( sb , sb ) ; if ( status == ManagedSocketBox . FREE ) { if ( freeSockets . containsKey ( sb ) ) { throw new IllegalArgumentException ( "This socket already exists in the pool of free sockets." ) ; } logger . debug ( "adding a free socket" ) ; freeSockets . put ( sb , sb ) ; } else { if ( busySockets . containsKey ( sb ) ) { throw new IllegalArgumentException ( "This socket already exists in the pool of busy sockets." ) ; } logger . debug ( "adding a busy socket" ) ; busySockets . put ( sb , sb ) ; } }
add socketBox to the pool . Depending on its state it will be added to free or busy sockets .
39,328
public synchronized void remove ( SocketBox sb ) { int status = ( ( ManagedSocketBox ) sb ) . getStatus ( ) ; if ( ! allSockets . containsKey ( sb ) ) { throw new IllegalArgumentException ( "This socket does not seem to exist in the socket pool." ) ; } allSockets . remove ( sb ) ; if ( status == ManagedSocketBox . FREE ) { if ( ! freeSockets . containsKey ( sb ) ) { throw new IllegalArgumentException ( "This socket is marked free, but does not exist in the pool of free sockets." ) ; } freeSockets . remove ( sb ) ; } else { if ( ! busySockets . containsKey ( sb ) ) { throw new IllegalArgumentException ( "This socket is marked busy, but does not exist in the pool of busy sockets." ) ; } busySockets . remove ( sb ) ; } }
remove socketBox from the pool remove all references to it
39,329
public synchronized void applyToAll ( SocketOperator op ) throws Exception { Enumeration keys = allSockets . keys ( ) ; while ( keys . hasMoreElements ( ) ) { SocketBox myBox = ( SocketBox ) keys . nextElement ( ) ; op . operate ( myBox ) ; } }
Apply the suplied callback to all socketBoxes .
39,330
public synchronized void flush ( ) throws IOException { Enumeration keys = allSockets . keys ( ) ; while ( keys . hasMoreElements ( ) ) { SocketBox myBox = ( SocketBox ) keys . nextElement ( ) ; if ( myBox != null ) { myBox . setSocket ( null ) ; } } allSockets . clear ( ) ; freeSockets . clear ( ) ; busySockets . clear ( ) ; }
Forcibly close all sockets and remove them from the pool .
39,331
public boolean isDryRun ( ) { String run = getSingle ( "dryrun" ) ; if ( run == null ) return false ; if ( run . equalsIgnoreCase ( "yes" ) ) return true ; return false ; }
Checks if dryryn is enabled .
39,332
public void setJobType ( int jobType ) { String type = null ; switch ( jobType ) { case JOBTYPE_SINGLE : type = "single" ; break ; case JOBTYPE_MULTIPLE : type = "multiple" ; break ; case JOBTYPE_MPI : type = "mpi" ; break ; case JOBTYPE_CONDOR : type = "condor" ; break ; } if ( type != null ) { set ( "jobtype" , type ) ; } }
Sets a job type .
39,333
public int getJobType ( ) { String jobType = getSingle ( "jobtype" ) ; if ( jobType == null ) return - 1 ; if ( jobType . equalsIgnoreCase ( "single" ) ) { return JOBTYPE_SINGLE ; } else if ( jobType . equalsIgnoreCase ( "multiple" ) ) { return JOBTYPE_MULTIPLE ; } else if ( jobType . equalsIgnoreCase ( "mpi" ) ) { return JOBTYPE_MPI ; } else if ( jobType . equalsIgnoreCase ( "condor" ) ) { return JOBTYPE_CONDOR ; } else { return - 1 ; } }
Returns type of the job .
39,334
public boolean load ( File file ) throws IOException { InputStream in = null ; try { in = new FileInputStream ( file ) ; this . file = file ; this . lastModified = file . lastModified ( ) ; return load ( in ) ; } finally { if ( in != null ) { try { in . close ( ) ; } catch ( Exception e ) { } } } }
Loads grid map definition from a given file .
39,335
public boolean load ( InputStream input ) throws IOException { boolean success = true ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( input ) ) ; Map localMap = new HashMap ( ) ; GridMapEntry entry ; QuotedStringTokenizer tokenizer ; StringTokenizer idTokenizer ; String line ; while ( ( line = reader . readLine ( ) ) != null ) { line = line . trim ( ) ; if ( ( line . length ( ) == 0 ) || ( COMMENT_CHARS . indexOf ( line . charAt ( 0 ) ) != - 1 ) ) { continue ; } tokenizer = new QuotedStringTokenizer ( line ) ; String globusID = null ; if ( tokenizer . hasMoreTokens ( ) ) { globusID = tokenizer . nextToken ( ) ; } else { if ( this . ignoreErrors ) { success = false ; logger . warn ( "Globus ID missing: " + line ) ; continue ; } else { throw new IOException ( i18n . getMessage ( "globusIdErr" , line ) ) ; } } String userIDs = null ; if ( tokenizer . hasMoreTokens ( ) ) { userIDs = tokenizer . nextToken ( ) ; } else { if ( this . ignoreErrors ) { success = false ; logger . warn ( "User ID mapping missing: " + line ) ; continue ; } else { throw new IOException ( i18n . getMessage ( "userIdErr" , line ) ) ; } } idTokenizer = new StringTokenizer ( userIDs , "," ) ; String [ ] ids = new String [ idTokenizer . countTokens ( ) ] ; int i = 0 ; while ( idTokenizer . hasMoreTokens ( ) ) { ids [ i ++ ] = idTokenizer . nextToken ( ) ; } String normalizedDN = normalizeDN ( globusID ) ; entry = ( GridMapEntry ) localMap . get ( normalizedDN ) ; if ( entry == null ) { entry = new GridMapEntry ( ) ; entry . setGlobusID ( globusID ) ; entry . setUserIDs ( ids ) ; localMap . put ( normalizedDN , entry ) ; } else { entry . addUserIDs ( ids ) ; } } this . map = localMap ; return success ; }
Loads grid map file definition from a given input stream . The input stream is not closed in case of an error .
39,336
public String getUserID ( String globusID ) { String [ ] ids = getUserIDs ( globusID ) ; if ( ids != null && ids . length > 0 ) { return ids [ 0 ] ; } else { return null ; } }
Returns first local user name mapped to the specified globusID .
39,337
public String [ ] getUserIDs ( String globusID ) { if ( globusID == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "globusIdNull" ) ) ; } if ( this . map == null ) { return null ; } GridMapEntry entry = ( GridMapEntry ) this . map . get ( normalizeDN ( globusID ) ) ; return ( entry == null ) ? null : entry . getUserIDs ( ) ; }
Returns local user names mapped to the specified globusID .
39,338
public boolean checkUser ( String globusID , String userID ) { if ( globusID == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "glousIdNull" ) ) ; } if ( userID == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "userIdNull" ) ) ; } if ( this . map == null ) { return false ; } GridMapEntry entry = ( GridMapEntry ) this . map . get ( normalizeDN ( globusID ) ) ; return ( entry == null ) ? false : entry . containsUserID ( userID ) ; }
Checks if a given globus ID is associated with given local user account .
39,339
public String getGlobusID ( String userID ) { if ( userID == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "userIdNull" ) ) ; } if ( this . map == null ) { return null ; } Iterator iter = this . map . entrySet ( ) . iterator ( ) ; Map . Entry mapEntry ; GridMapEntry entry ; while ( iter . hasNext ( ) ) { mapEntry = ( Map . Entry ) iter . next ( ) ; entry = ( GridMapEntry ) mapEntry . getValue ( ) ; if ( entry . containsUserID ( userID ) ) { return entry . getGlobusID ( ) ; } } return null ; }
Returns globus ID associated with the specified local user name .
39,340
public String [ ] getAllGlobusID ( String userID ) { if ( userID == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "userIdNull" ) ) ; } if ( this . map == null ) { return null ; } Vector v = new Vector ( ) ; Iterator iter = this . map . entrySet ( ) . iterator ( ) ; Map . Entry mapEntry ; GridMapEntry entry ; while ( iter . hasNext ( ) ) { mapEntry = ( Map . Entry ) iter . next ( ) ; entry = ( GridMapEntry ) mapEntry . getValue ( ) ; if ( entry . containsUserID ( userID ) ) { v . add ( entry . getGlobusID ( ) ) ; } } if ( v . size ( ) == 0 ) { return null ; } String idS [ ] = new String [ v . size ( ) ] ; for ( int ctr = 0 ; ctr < v . size ( ) ; ctr ++ ) { idS [ ctr ] = ( String ) v . elementAt ( ctr ) ; } return idS ; }
Returns all globus IDs associated with the specified local user name .
39,341
public void invoke ( X509Certificate cert , GSIConstants . CertificateType certType ) throws CertPathValidatorException { try { cert . checkValidity ( ) ; } catch ( CertificateExpiredException e ) { throw new CertPathValidatorException ( "Certificate " + cert . getSubjectDN ( ) + " expired" , e ) ; } catch ( CertificateNotYetValidException e ) { throw new CertPathValidatorException ( "Certificate " + cert . getSubjectDN ( ) + " not yet valid." , e ) ; } }
Method that checks the time validity . Uses the standard Certificate . checkValidity method .
39,342
public CredentialInfo info ( GSSCredential credential , String username , String passphrase ) throws MyProxyException { InfoParams request = new InfoParams ( ) ; request . setUserName ( username ) ; request . setPassphrase ( passphrase ) ; return info ( credential , request ) [ 0 ] ; }
Retrieves credential information from MyProxy server . Only the information of the default credential is returned by this operation .
39,343
public void getTrustroots ( GSSCredential credential , GetTrustrootsParams params ) throws MyProxyException { if ( params == null ) { throw new IllegalArgumentException ( "params == null" ) ; } if ( credential == null ) { try { credential = getAnonymousCredential ( ) ; } catch ( GSSException e ) { throw new MyProxyException ( "Failed to create anonymous credentials" , e ) ; } } Socket gsiSocket = null ; OutputStream out = null ; InputStream in = null ; String msg = params . makeRequest ( ) ; try { gsiSocket = getSocket ( credential ) ; if ( credential . getName ( ) . isAnonymous ( ) ) { this . context . requestAnonymity ( true ) ; } out = gsiSocket . getOutputStream ( ) ; in = gsiSocket . getInputStream ( ) ; if ( ! ( ( GssSocket ) gsiSocket ) . getContext ( ) . getConfState ( ) ) throw new Exception ( "Confidentiality requested but not available" ) ; out . write ( msg . getBytes ( ) ) ; out . flush ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Req sent:" + params ) ; } handleReply ( in , out , null , true ) ; } catch ( Exception e ) { throw new MyProxyException ( "MyProxy get-trustroots failed." , e ) ; } finally { close ( out , in , gsiSocket ) ; } }
Retrieves trustroot information from the MyProxy server .
39,344
public boolean writeTrustRoots ( String directory ) throws IOException { if ( this . trustrootFilenames == null || this . trustrootData == null ) { return false ; } File rootDir = new File ( directory ) ; if ( ! rootDir . exists ( ) ) { rootDir . mkdirs ( ) ; } for ( int i = 0 ; i < trustrootFilenames . length ; i ++ ) { FileOutputStream out = new FileOutputStream ( directory + File . separator + this . trustrootFilenames [ i ] ) ; out . write ( this . trustrootData [ i ] . getBytes ( ) ) ; out . close ( ) ; } return true ; }
Writes the retrieved trust roots to a trusted certificates directory .
39,345
protected static String toHex ( final byte [ ] bin ) { if ( bin == null || bin . length == 0 ) return "" ; char [ ] buffer = new char [ bin . length * 2 ] ; final char [ ] hex = "0123456789abcdef" . toCharArray ( ) ; for ( int i = 0 , j = 0 ; i < bin . length ; i ++ ) { final byte b = bin [ i ] ; buffer [ j ++ ] = hex [ ( b >> 4 ) & 0x0F ] ; buffer [ j ++ ] = hex [ b & 0x0F ] ; } return new String ( buffer ) ; }
encode binary to hex
39,346
public Key engineGetKey ( String s , char [ ] chars ) throws NoSuchAlgorithmException , UnrecoverableKeyException { CredentialWrapper credential = getKeyEntry ( s ) ; Key key = null ; if ( credential != null ) { try { String password = null ; if ( chars != null ) { password = new String ( chars ) ; } key = credential . getCredential ( ) . getPrivateKey ( password ) ; } catch ( ResourceStoreException e ) { throw new UnrecoverableKeyException ( e . getMessage ( ) ) ; } catch ( CredentialException e ) { throw new UnrecoverableKeyException ( e . getMessage ( ) ) ; } } return key ; }
Get the key referenced by the specified alias .
39,347
public void engineStore ( OutputStream outputStream , char [ ] chars ) throws IOException , NoSuchAlgorithmException , CertificateException { for ( SecurityObjectWrapper < ? > object : this . aliasObjectMap . values ( ) ) { if ( object instanceof Storable ) { try { ( ( Storable ) object ) . store ( ) ; } catch ( ResourceStoreException e ) { throw new CertificateException ( e ) ; } } } }
Persist the security material in this keystore . If the object has a path associated with it the object will be persisted to that path . Otherwise it will be stored in the default certificate directory . As a result the parameters of this method are ignored .
39,348
public Date engineGetCreationDate ( String s ) { try { ResourceTrustAnchor trustAnchor = getCertificateEntry ( s ) ; if ( trustAnchor != null ) { return trustAnchor . getTrustAnchor ( ) . getTrustedCert ( ) . getNotBefore ( ) ; } else { CredentialWrapper credential = getKeyEntry ( s ) ; if ( credential != null ) { return credential . getCredential ( ) . getNotBefore ( ) ; } } } catch ( ResourceStoreException e ) { return null ; } return null ; }
Get the creation date for the object referenced by the alias .
39,349
public Certificate [ ] engineGetCertificateChain ( String s ) { CredentialWrapper credential = getKeyEntry ( s ) ; X509Certificate [ ] chain = new X509Certificate [ 0 ] ; if ( credential != null ) { try { chain = credential . getCredential ( ) . getCertificateChain ( ) ; } catch ( ResourceStoreException e ) { logger . warn ( e . getMessage ( ) , e ) ; chain = null ; } } return chain ; }
Get the certificateChain for the key referenced by the alias .
39,350
public Certificate engineGetCertificate ( String s ) { ResourceTrustAnchor trustAnchor = getCertificateEntry ( s ) ; if ( trustAnchor != null ) { try { return trustAnchor . getTrustAnchor ( ) . getTrustedCert ( ) ; } catch ( ResourceStoreException e ) { return null ; } } return null ; }
Get the certificate referenced by the supplied alias .
39,351
public void engineLoad ( KeyStore . LoadStoreParameter loadStoreParameter ) throws IOException , NoSuchAlgorithmException , CertificateException { if ( ! ( loadStoreParameter instanceof KeyStoreParametersFactory . FileStoreParameters ) ) { throw new IllegalArgumentException ( "Unable to process parameters: " + loadStoreParameter ) ; } KeyStoreParametersFactory . FileStoreParameters params = ( KeyStoreParametersFactory . FileStoreParameters ) loadStoreParameter ; String defaultDirectoryString = ( String ) params . getProperty ( DEFAULT_DIRECTORY_KEY ) ; String directoryListString = ( String ) params . getProperty ( DIRECTORY_LIST_KEY ) ; String certFilename = ( String ) params . getProperty ( CERTIFICATE_FILENAME ) ; String keyFilename = ( String ) params . getProperty ( KEY_FILENAME ) ; String proxyFilename = ( String ) params . getProperty ( PROXY_FILENAME ) ; initialize ( defaultDirectoryString , directoryListString , proxyFilename , certFilename , keyFilename ) ; }
Load the keystore based on parameters in the LoadStoreParameter . The parameter object must be an instance of FileBasedKeyStoreParameters .
39,352
private void initialize ( String defaultDirectoryString , String directoryListString , String proxyFilename , String certFilename , String keyFilename ) throws IOException , CertificateException { if ( defaultDirectoryString != null ) { defaultDirectory = new GlobusPathMatchingResourcePatternResolver ( ) . getResource ( defaultDirectoryString ) . getFile ( ) ; if ( ! defaultDirectory . exists ( ) ) { boolean directoryMade = defaultDirectory . mkdirs ( ) ; if ( ! directoryMade ) { throw new IOException ( "Unable to create default certificate directory" ) ; } } loadDirectories ( defaultDirectoryString ) ; } if ( directoryListString != null ) { loadDirectories ( directoryListString ) ; } try { if ( proxyFilename != null && proxyFilename . length ( ) > 0 ) { loadProxyCertificate ( proxyFilename ) ; } if ( ( certFilename != null && certFilename . length ( ) > 0 ) && ( keyFilename != null && keyFilename . length ( ) > 0 ) ) { loadCertificateKey ( certFilename , keyFilename ) ; } } catch ( ResourceStoreException e ) { throw new CertificateException ( e ) ; } catch ( CredentialException e ) { e . printStackTrace ( ) ; throw new CertificateException ( e ) ; } }
Initialize resources from filename proxyfile name
39,353
public void engineDeleteEntry ( String s ) throws KeyStoreException { SecurityObjectWrapper < ? > object = this . aliasObjectMap . remove ( s ) ; if ( object != null ) { if ( object instanceof ResourceTrustAnchor ) { ResourceTrustAnchor descriptor = ( ResourceTrustAnchor ) object ; Certificate cert ; try { cert = descriptor . getTrustAnchor ( ) . getTrustedCert ( ) ; } catch ( ResourceStoreException e ) { throw new KeyStoreException ( e ) ; } this . certFilenameMap . remove ( cert ) ; boolean success = descriptor . getFile ( ) . delete ( ) ; if ( ! success ) { logger . info ( "Unable to delete certificate" ) ; } } else if ( object instanceof ResourceProxyCredential ) { ResourceProxyCredential proxy = ( ResourceProxyCredential ) object ; try { proxy . getCredential ( ) ; } catch ( ResourceStoreException e ) { throw new KeyStoreException ( e ) ; } boolean success = proxy . getFile ( ) . delete ( ) ; if ( ! success ) { logger . info ( "Unable to delete credential" ) ; } } } }
Delete a security object from this keystore .
39,354
public void engineSetKeyEntry ( String s , Key key , char [ ] chars , Certificate [ ] certificates ) throws KeyStoreException { if ( ! ( key instanceof PrivateKey ) ) { throw new KeyStoreException ( "PrivateKey expected" ) ; } if ( ! ( certificates instanceof X509Certificate [ ] ) ) { throw new KeyStoreException ( "Certificate chain of X509Certificate expected" ) ; } CredentialWrapper wrapper ; X509Credential credential = new X509Credential ( ( PrivateKey ) key , ( X509Certificate [ ] ) certificates ) ; if ( credential . isEncryptedKey ( ) ) { wrapper = createCertKeyCredential ( s , credential ) ; } else { wrapper = createProxyCredential ( s , credential ) ; } storeWrapper ( wrapper ) ; this . aliasObjectMap . put ( wrapper . getAlias ( ) , wrapper ) ; }
Add a new private key to the keystore .
39,355
public void engineSetCertificateEntry ( String alias , Certificate certificate ) throws KeyStoreException { if ( ! ( certificate instanceof X509Certificate ) ) { throw new KeyStoreException ( "Certificate must be instance of X509Certificate" ) ; } File file ; ResourceTrustAnchor trustAnchor = getCertificateEntry ( alias ) ; if ( trustAnchor != null ) { file = trustAnchor . getFile ( ) ; } else { file = new File ( defaultDirectory , alias ) ; } X509Certificate x509Cert = ( X509Certificate ) certificate ; try { if ( ! inMemoryOnly ) { writeCertificate ( x509Cert , file ) ; } ResourceTrustAnchor anchor = new ResourceTrustAnchor ( inMemoryOnly , new GlobusResource ( file . getAbsolutePath ( ) ) , new TrustAnchor ( x509Cert , null ) ) ; this . aliasObjectMap . put ( alias , anchor ) ; this . certFilenameMap . put ( x509Cert , alias ) ; } catch ( ResourceStoreException e ) { throw new KeyStoreException ( e ) ; } catch ( IOException e ) { throw new KeyStoreException ( e ) ; } catch ( CertificateEncodingException e ) { throw new KeyStoreException ( e ) ; } }
Add a certificate to the keystore .
39,356
public static boolean isProxy ( GSIConstants . CertificateType certType ) { return isGsi2Proxy ( certType ) || isGsi3Proxy ( certType ) || isGsi4Proxy ( certType ) ; }
Determines if a specified certificate type indicates a GSI - 2 GSI - 3 or GSI - 4proxy certificate .
39,357
public static boolean isGsi4Proxy ( GSIConstants . CertificateType certType ) { return certType == GSIConstants . CertificateType . GSI_4_IMPERSONATION_PROXY || certType == GSIConstants . CertificateType . GSI_4_INDEPENDENT_PROXY || certType == GSIConstants . CertificateType . GSI_4_RESTRICTED_PROXY || certType == GSIConstants . CertificateType . GSI_4_LIMITED_PROXY ; }
Determines if a specified certificate type indicates a GSI - 4 proxy certificate .
39,358
public static boolean isGsi3Proxy ( GSIConstants . CertificateType certType ) { return certType == GSIConstants . CertificateType . GSI_3_IMPERSONATION_PROXY || certType == GSIConstants . CertificateType . GSI_3_INDEPENDENT_PROXY || certType == GSIConstants . CertificateType . GSI_3_RESTRICTED_PROXY || certType == GSIConstants . CertificateType . GSI_3_LIMITED_PROXY ; }
Determines if a specified certificate type indicates a GSI - 3 proxy certificate .
39,359
public static boolean isGsi2Proxy ( GSIConstants . CertificateType certType ) { return certType == GSIConstants . CertificateType . GSI_2_PROXY || certType == GSIConstants . CertificateType . GSI_2_LIMITED_PROXY ; }
Determines if a specified certificate type indicates a GSI - 2 proxy certificate .
39,360
public static boolean isLimitedProxy ( GSIConstants . CertificateType certType ) { return certType == GSIConstants . CertificateType . GSI_3_LIMITED_PROXY || certType == GSIConstants . CertificateType . GSI_2_LIMITED_PROXY || certType == GSIConstants . CertificateType . GSI_4_LIMITED_PROXY ; }
Determines if a specified certificate type indicates a GSI - 2 or GSI - 3 or GSI = 4 limited proxy certificate .
39,361
public static boolean isIndependentProxy ( GSIConstants . CertificateType certType ) { return certType == GSIConstants . CertificateType . GSI_3_INDEPENDENT_PROXY || certType == GSIConstants . CertificateType . GSI_4_INDEPENDENT_PROXY ; }
Determines if a specified certificate type indicates a GSI - 3 or GS - 4 limited proxy certificate .
39,362
public static boolean isImpersonationProxy ( GSIConstants . CertificateType certType ) { return certType == GSIConstants . CertificateType . GSI_3_IMPERSONATION_PROXY || certType == GSIConstants . CertificateType . GSI_3_LIMITED_PROXY || certType == GSIConstants . CertificateType . GSI_4_IMPERSONATION_PROXY || certType == GSIConstants . CertificateType . GSI_4_LIMITED_PROXY || certType == GSIConstants . CertificateType . GSI_2_LIMITED_PROXY || certType == GSIConstants . CertificateType . GSI_2_PROXY ; }
Determines if a specified certificate type indicates a GSI - 2 or GSI - 3 or GSI - 4 impersonation proxy certificate .
39,363
public static String getProxyTypeAsString ( GSIConstants . CertificateType proxyType ) { switch ( proxyType ) { case GSI_4_IMPERSONATION_PROXY : return "RFC 3820 compliant impersonation proxy" ; case GSI_4_INDEPENDENT_PROXY : return "RFC 3820 compliant independent proxy" ; case GSI_4_LIMITED_PROXY : return "RFC 3820 compliant limited proxy" ; case GSI_4_RESTRICTED_PROXY : return "RFC 3820 compliant restricted proxy" ; case GSI_3_IMPERSONATION_PROXY : return "Proxy draft compliant impersonation proxy" ; case GSI_3_INDEPENDENT_PROXY : return "Proxy draft compliant independent proxy" ; case GSI_3_LIMITED_PROXY : return "Proxy draft compliant limited proxy" ; case GSI_3_RESTRICTED_PROXY : return "Proxy draft compliant restricted proxy" ; case GSI_2_PROXY : return "full legacy globus proxy" ; case GSI_2_LIMITED_PROXY : return "limited legacy globus proxy" ; default : return "not a proxy" ; } }
Returns a string description of a specified proxy type .
39,364
public Map < X500Principal , SigningPolicy > parse ( String fileName ) throws FileNotFoundException , SigningPolicyException { if ( ( fileName == null ) || ( fileName . trim ( ) . isEmpty ( ) ) ) { throw new IllegalArgumentException ( ) ; } logger . debug ( "Signing policy file name " + fileName ) ; FileReader fileReader = null ; try { fileReader = new FileReader ( fileName ) ; return parse ( fileReader ) ; } catch ( Exception e ) { throw new SigningPolicyException ( e ) ; } finally { if ( fileReader != null ) { try { fileReader . close ( ) ; } catch ( Exception exp ) { logger . debug ( "Error closing file reader" , exp ) ; } } } }
Parses the file to extract signing policy defined for CA with the specified DN . If the policy file does not exist a SigningPolicy object with only CA DN is created . If policy path exists but no relevant policy exisit SigningPolicy object with CA DN and file path is created .
39,365
public Map < X500Principal , SigningPolicy > parse ( Reader reader ) throws SigningPolicyException { Map < X500Principal , SigningPolicy > policies = new HashMap < X500Principal , SigningPolicy > ( ) ; BufferedReader bufferedReader = new BufferedReader ( reader ) ; try { String line ; while ( ( line = bufferedReader . readLine ( ) ) != null ) { line = line . trim ( ) ; if ( ! isValidLine ( line ) ) { continue ; } logger . debug ( "Line to parse: " + line ) ; String caDN = null ; if ( line . startsWith ( ACCESS_ID_PREFIX ) ) { logger . debug ( "Check if it is CA and get the DN " + line ) ; caDN = getCaDN ( line , caDN ) ; boolean usefulEntry = true ; Boolean posNegRights = null ; checkRights ( policies , bufferedReader , caDN , usefulEntry , posNegRights ) ; } } } catch ( IOException exp ) { throw new SigningPolicyException ( "" , exp ) ; } finally { cleanupReaders ( reader , bufferedReader ) ; } return policies ; }
Parses input stream to extract signing policy defined for CA with the specified DN .
39,366
private int findIndex ( String line ) { int index = - 1 ; if ( line == null ) { return index ; } String trimmedLine = line . trim ( ) ; int spaceIndex = trimmedLine . indexOf ( " " ) ; int tabIndex = trimmedLine . indexOf ( "\t" ) ; if ( spaceIndex != - 1 ) { if ( tabIndex != - 1 ) { if ( spaceIndex < tabIndex ) { index = spaceIndex ; } else { index = tabIndex ; } } else { index = spaceIndex ; } } else { index = tabIndex ; } return index ; }
find first space or tab as separator .
39,367
public static CertStore createCertStore ( TrustedCertificates tc ) throws Exception { CertStore store = null ; if ( tc == null ) { String caCertPattern = "file:" + CoGProperties . getDefault ( ) . getCaCertLocations ( ) + "/*.0" ; store = Stores . getCACertStore ( caCertPattern ) ; } else { SimpleMemoryCertStoreParams params = new SimpleMemoryCertStoreParams ( tc . getCertificates ( ) , null ) ; params . setCerts ( tc . getCertificates ( ) ) ; store = CertStore . getInstance ( SimpleMemoryProvider . CERTSTORE_TYPE , params , SimpleMemoryProvider . PROVIDER_NAME ) ; } return store ; }
Create a CertStore object from TrustedCertificates . The store only loads trusted certificates no signing policies
39,368
public ProxyPolicyHandler removeProxyPolicyHandler ( String id ) { return ( id != null && this . proxyPolicyHandlers != null ) ? ( ProxyPolicyHandler ) this . proxyPolicyHandlers . remove ( id ) : null ; }
Removes a restricted proxy policy handler .
39,369
public ProxyPolicyHandler setProxyPolicyHandler ( String id , ProxyPolicyHandler handler ) { if ( id == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "proxyPolicyId" ) ) ; } if ( handler == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "proxyPolicyHandler" ) ) ; } if ( this . proxyPolicyHandlers == null ) { this . proxyPolicyHandlers = new Hashtable ( ) ; } return ( ProxyPolicyHandler ) this . proxyPolicyHandlers . put ( id , handler ) ; }
Sets a restricted proxy policy handler .
39,370
public ProxyPolicyHandler getProxyPolicyHandler ( String id ) { return ( id != null && this . proxyPolicyHandlers != null ) ? ( ProxyPolicyHandler ) this . proxyPolicyHandlers . get ( id ) : null ; }
Retrieves a restricted proxy policy handler for a given policy id .
39,371
public void activeConnect ( HostPort hp , int connections ) { for ( int i = 0 ; i < connections ; i ++ ) { SocketBox sbox = new ManagedSocketBox ( ) ; logger . debug ( "adding new empty socketBox to the socket pool" ) ; socketPool . add ( sbox ) ; logger . debug ( "connecting active socket " + i + "; total cached sockets = " + socketPool . count ( ) ) ; Task task = new GridFTPActiveConnectTask ( hp , localControlChannel , sbox , gSession ) ; runTask ( task ) ; } }
Act as the active side . Connect to the server and store the newly connected sockets in the socketPool .
39,372
public void activeClose ( TransferContext context , int connections ) { try { for ( int i = 0 ; i < connections ; i ++ ) { SocketBox sbox = socketPool . checkOut ( ) ; try { GridFTPDataChannel dc = new GridFTPDataChannel ( gSession , sbox ) ; EBlockImageDCWriter writer = ( EBlockImageDCWriter ) dc . getDataChannelSink ( context ) ; writer . setDataStream ( sbox . getSocket ( ) . getOutputStream ( ) ) ; writer . close ( ) ; } finally { socketPool . remove ( sbox ) ; sbox . setSocket ( null ) ; } } } catch ( Exception e ) { FTPServerFacade . exceptionToControlChannel ( e , "closing of a reused connection failed" , localControlChannel ) ; } }
use only in mode E
39,373
public synchronized void startTransfer ( DataSource source , TransferContext context , int connections , boolean reusable ) throws ServerException { if ( transferThreadCount != 0 ) { throw new ServerException ( ServerException . PREVIOUS_TRANSFER_ACTIVE ) ; } for ( int i = 0 ; i < connections ; i ++ ) { logger . debug ( "checking out a socket; total cached sockets = " + socketPool . count ( ) + "; free = " + socketPool . countFree ( ) + "; busy = " + socketPool . countBusy ( ) ) ; SocketBox sbox = socketPool . checkOut ( ) ; if ( sbox == null ) { logger . debug ( "No free sockets available, aborting." ) ; return ; } ( ( ManagedSocketBox ) sbox ) . setReusable ( reusable ) ; Task task = new ActiveStartTransferTask ( source , localControlChannel , sbox , gSession , dataChannelFactory , context ) ; runTask ( task ) ; } }
This should be used once the remote active server connected to us . This method starts transfer threads that will read data from the source and send .
39,374
public synchronized void passiveConnect ( DataSink sink , TransferContext context , int connections , ServerSocket serverSocket ) throws ServerException { if ( transferThreadCount != 0 ) { throw new ServerException ( ServerException . PREVIOUS_TRANSFER_ACTIVE ) ; } for ( int i = 0 ; i < connections ; i ++ ) { Task task = new GridFTPPassiveConnectTask ( serverSocket , sink , localControlChannel , gSession , dataChannelFactory , ( EBlockParallelTransferContext ) context ) ; runTask ( task ) ; } }
Accept connections from the remote server and start transfer threads that will read incoming data and store in the sink .
39,375
public synchronized void passiveConnect ( DataSource source , TransferContext context , ServerSocket serverSocket ) throws ServerException { if ( transferThreadCount != 0 ) { throw new ServerException ( ServerException . PREVIOUS_TRANSFER_ACTIVE ) ; } Task task = new GridFTPPassiveConnectTask ( serverSocket , source , localControlChannel , gSession , dataChannelFactory , ( EBlockParallelTransferContext ) context ) ; runTask ( task ) ; }
Accept connection from the remote server and start transfer thread that will read incoming data and store in the sink . This method because of direction of transfer cannot be used with EBlock . Therefore it is fixed to create only 1 connection .
39,376
public static KeyStore buildTrustStore ( String provider , String trustAnchorStoreType , String trustAnchorStoreLocation , String trustAnchorStorePassword ) throws GlobusSSLConfigurationException { try { KeyStore trustAnchorStore ; if ( provider == null ) { trustAnchorStore = KeyStore . getInstance ( trustAnchorStoreType ) ; } else { trustAnchorStore = KeyStore . getInstance ( trustAnchorStoreType , provider ) ; } InputStream keyStoreInput = getStream ( trustAnchorStoreLocation ) ; try { trustAnchorStore . load ( new BufferedInputStream ( keyStoreInput ) , trustAnchorStorePassword == null ? null : trustAnchorStorePassword . toCharArray ( ) ) ; } finally { keyStoreInput . close ( ) ; } return trustAnchorStore ; } catch ( KeyStoreException e ) { throw new GlobusSSLConfigurationException ( e ) ; } catch ( IOException e ) { throw new GlobusSSLConfigurationException ( e ) ; } catch ( NoSuchAlgorithmException e ) { throw new GlobusSSLConfigurationException ( e ) ; } catch ( CertificateException e ) { throw new GlobusSSLConfigurationException ( e ) ; } catch ( NoSuchProviderException e ) { throw new GlobusSSLConfigurationException ( e ) ; } }
Create a trust store using the supplied details . Java SSL requires the trust store to be supplied as a java . security . KeyStore so this will create a KeyStore containing all of the Trust Anchors .
39,377
public static KeyStore findCredentialStore ( String provider , String credentialStoreType , String credentialStoreLocation , String credentialStorePassword ) throws GlobusSSLConfigurationException { try { KeyStore credentialStore ; if ( provider == null ) { credentialStore = KeyStore . getInstance ( credentialStoreType ) ; } else { credentialStore = KeyStore . getInstance ( credentialStoreType , provider ) ; } InputStream keyStoreInput = getStream ( credentialStoreLocation ) ; try { credentialStore . load ( new BufferedInputStream ( keyStoreInput ) , credentialStorePassword == null ? null : credentialStorePassword . toCharArray ( ) ) ; } finally { keyStoreInput . close ( ) ; } return credentialStore ; } catch ( KeyStoreException e ) { throw new GlobusSSLConfigurationException ( e ) ; } catch ( IOException e ) { throw new GlobusSSLConfigurationException ( e ) ; } catch ( NoSuchAlgorithmException e ) { throw new GlobusSSLConfigurationException ( e ) ; } catch ( CertificateException e ) { throw new GlobusSSLConfigurationException ( e ) ; } catch ( NoSuchProviderException e ) { throw new GlobusSSLConfigurationException ( e ) ; } }
Create a configured CredentialStore using the supplied parameters . The credential store is a java . security . KeyStore .
39,378
public static CertStore findCRLStore ( String crlPattern ) throws GlobusSSLConfigurationException { try { return Stores . getCRLStore ( crlPattern ) ; } catch ( InvalidAlgorithmParameterException e ) { throw new GlobusSSLConfigurationException ( e ) ; } catch ( NoSuchAlgorithmException e ) { Log logger = LogFactory . getLog ( GlobusSSLHelper . class . getCanonicalName ( ) ) ; logger . warn ( "Error Loading CRL store" , e ) ; throw new GlobusSSLConfigurationException ( e ) ; } catch ( GeneralSecurityException e ) { Log logger = LogFactory . getLog ( GlobusSSLHelper . class . getCanonicalName ( ) ) ; logger . warn ( "Error Loading CRL store" , e ) ; throw new GlobusSSLConfigurationException ( e ) ; } }
Create a store of Certificate Revocation Lists . Java requires that this be a java . security . certificates . CertStore . As such the store can hold both CRL s and non - trusted certs . For the purposes of this method we assume that only crl s will be loaded . This can only be used with the Globus provided Certificate Store .
39,379
private String readLine ( InputStream in ) throws IOException { StringBuffer buf = new StringBuffer ( ) ; int c , length = 0 ; while ( true ) { c = in . read ( ) ; if ( c == - 1 || c == '\n' || length > 512 ) { break ; } else if ( c == '\r' ) { in . read ( ) ; return buf . toString ( ) ; } else { buf . append ( ( char ) c ) ; length ++ ; } } return buf . toString ( ) ; }
Read a line of text from the given Stream and return it as a String . Assumes lines end in CRLF .
39,380
private static String getUsefulMessage ( Throwable throwable ) { while ( isBoring ( throwable ) ) { throwable = throwable . getCause ( ) ; } String message = throwable . getMessage ( ) ; if ( message == null ) { message = throwable . getClass ( ) . getName ( ) ; } return message ; }
Wrapper around getMessage method that tries to provide a meaningful message . This is needed because many GSSException objects provide no useful information and the actual useful information is in the Throwable that caused the exception .
39,381
public List < Feature > getFeature ( String label ) { if ( label == null ) { throw new IllegalArgumentException ( "feature label is null" ) ; } label = label . toUpperCase ( ) ; List < Feature > foundFeatures = new ArrayList ( ) ; for ( Feature feature : features ) { if ( feature . getLabel ( ) . equals ( label ) ) { foundFeatures . add ( feature ) ; } } return foundFeatures ; }
Get all features that have label equal to the argument Note that RFC 2389 does not require a feature with a given label to appear only once
39,382
public static String getOperatorAsString ( int op ) { switch ( op ) { case EQ : return "=" ; case NEQ : return "!=" ; case GT : return ">" ; case GTEQ : return ">=" ; case LT : return "<" ; case LTEQ : return "<=" ; default : return "??" ; } }
Returns a string representation of the specified relation operator .
39,383
public void add ( String [ ] strValues ) { if ( strValues == null ) return ; if ( values == null ) values = new LinkedList ( ) ; for ( int i = 0 ; i < strValues . length ; i ++ ) { values . add ( new Value ( strValues [ i ] ) ) ; } }
Adds an array of values to the list of values . Each element in the array is converted into a Value object and inserted as a separate value into the list of values .
39,384
public void add ( List list ) { if ( values == null ) values = new LinkedList ( ) ; values . add ( list ) ; }
Adds a list to the list of values . It is inserted as a single element .
39,385
public NameOpValue evaluate ( Map symbolTable ) throws RslEvaluationException { List list = evaluateSub ( values , symbolTable ) ; NameOpValue newNV = new NameOpValue ( getAttribute ( ) , getOperator ( ) ) ; newNV . setValues ( list ) ; return newNV ; }
Evaluates the relation against the symbol table .
39,386
protected static String ignoreLeading0 ( String line ) { if ( line . length ( ) > 0 && line . charAt ( 0 ) == 0 ) { logger . debug ( "WARNING: The first character of the reply is 0. Ignoring the character." ) ; return line . substring ( 1 , line . length ( ) ) ; } return line ; }
GT2 . 0 wuftp server incorrectly inserts \ 0 between lines . We have to deal with that .
39,387
protected Socket openSocket ( String host , int port ) throws IOException { return SocketFactory . getDefault ( ) . createSocket ( host , port ) ; }
subclasses should overwrite this function
39,388
public void verify ( ) throws Exception { Map < String , ProxyPolicyHandler > handlers = null ; if ( proxyCertInfo != null ) { String oid = proxyCertInfo . getProxyPolicy ( ) . getPolicyLanguage ( ) . getId ( ) ; handlers = new HashMap < String , ProxyPolicyHandler > ( ) ; handlers . put ( oid , new ProxyPolicyHandler ( ) { public void validate ( ProxyCertInfo proxyCertInfo , CertPath certPath , int index ) throws CertPathValidatorException { System . out . println ( "Proxy verify: Ignoring proxy policy" ) ; if ( debug ) { String policy = new String ( proxyCertInfo . getProxyPolicy ( ) . getPolicy ( ) ) ; System . out . println ( "Policy:" ) ; System . out . println ( policy ) ; } } } ) ; } KeyStore keyStore = Stores . getDefaultTrustStore ( ) ; CertStore crlStore = Stores . getDefaultCRLStore ( ) ; ResourceSigningPolicyStore sigPolStore = Stores . getDefaultSigningPolicyStore ( ) ; X509ProxyCertPathParameters parameters = new X509ProxyCertPathParameters ( keyStore , crlStore , sigPolStore , false , handlers ) ; X509ProxyCertPathValidator validator = new X509ProxyCertPathValidator ( ) ; validator . engineValidate ( CertificateUtil . getCertPath ( proxy . getCertificateChain ( ) ) , parameters ) ; }
verifies the proxy credential
39,389
protected List < CertificateChecker > getCertificateCheckers ( ) { List < CertificateChecker > checkers = new ArrayList < CertificateChecker > ( ) ; checkers . add ( new DateValidityChecker ( ) ) ; checkers . add ( new UnsupportedCriticalExtensionChecker ( ) ) ; checkers . add ( new IdentityChecker ( this ) ) ; CertificateRevocationLists crlsList = CertificateRevocationLists . getDefaultCertificateRevocationLists ( ) ; checkers . add ( new CRLChecker ( crlsList , this . keyStore , true ) ) ; checkers . add ( new SigningPolicyChecker ( this . policyStore ) ) ; return checkers ; }
COMMENT enable the checkers again when ProxyPathValidator starts working!
39,390
public GSSCredential createCredential ( byte [ ] buff , int option , int lifetime , Oid mech , int usage ) throws GSSException { checkMechanism ( mech ) ; if ( buff == null || buff . length < 1 ) { throw new GlobusGSSException ( GSSException . FAILURE , GlobusGSSException . BAD_ARGUMENT , "invalidBuf" ) ; } if ( lifetime == GSSCredential . INDEFINITE_LIFETIME || lifetime > 0 ) { throw new GlobusGSSException ( GSSException . FAILURE , GlobusGSSException . BAD_ARGUMENT , "badLifetime01" ) ; } InputStream input = null ; switch ( option ) { case ExtendedGSSCredential . IMPEXP_OPAQUE : input = new ByteArrayInputStream ( buff ) ; break ; case ExtendedGSSCredential . IMPEXP_MECH_SPECIFIC : String s = new String ( buff ) ; int pos = s . indexOf ( '=' ) ; if ( pos == - 1 ) { throw new GSSException ( GSSException . FAILURE ) ; } String filename = s . substring ( pos + 1 ) . trim ( ) ; try { input = new FileInputStream ( filename ) ; } catch ( IOException e ) { throw new GlobusGSSException ( GSSException . FAILURE , e ) ; } break ; default : throw new GlobusGSSException ( GSSException . FAILURE , GlobusGSSException . BAD_ARGUMENT , "unknownOption" , new Object [ ] { new Integer ( option ) } ) ; } X509Credential cred = null ; try { cred = new X509Credential ( input ) ; } catch ( CredentialException e ) { throw new GlobusGSSException ( GSSException . DEFECTIVE_CREDENTIAL , e ) ; } catch ( Exception e ) { throw new GlobusGSSException ( GSSException . DEFECTIVE_CREDENTIAL , e ) ; } return new GlobusGSSCredentialImpl ( cred , usage ) ; }
Imports a credential .
39,391
public static void checkMechanism ( Oid mech ) throws GSSException { if ( mech != null && ! mech . equals ( GSSConstants . MECH_OID ) ) { throw new GSSException ( GSSException . BAD_MECH ) ; } }
Checks if the specified mechanism matches the mechanism supported by this implementation .
39,392
public boolean add ( AbstractRslNode node ) { if ( _specifications == null ) _specifications = new LinkedList ( ) ; return _specifications . add ( node ) ; }
Adds a rsl parse tree to this node .
39,393
public boolean removeSpecification ( AbstractRslNode node ) { if ( _specifications == null || node == null ) return false ; return _specifications . remove ( node ) ; }
Removes a specific sub - specification tree from the sub - specification list .
39,394
public static String canonicalize ( String str ) { if ( str == null ) return null ; int length = str . length ( ) ; char ch ; StringBuffer buf = new StringBuffer ( length ) ; for ( int i = 0 ; i < length ; i ++ ) { ch = str . charAt ( i ) ; if ( ch == '_' ) continue ; buf . append ( Character . toLowerCase ( ch ) ) ; } return buf . toString ( ) ; }
Canonicalizes a string by removing any underscores and moving all characters to lowercase .
39,395
public void waitFor ( Flag flag , int waitDelay ) throws ServerException , IOException , InterruptedException { waitFor ( flag , waitDelay , WAIT_FOREVER ) ; }
Return when reply is waiting
39,396
public void setupMessageContextImpl ( MessageContext mc , Call call , AxisEngine engine ) throws AxisFault { if ( action != null ) { mc . setUseSOAPAction ( true ) ; mc . setSOAPActionURI ( action ) ; } if ( cookie != null ) mc . setProperty ( HTTPConstants . HEADER_COOKIE , cookie ) ; if ( cookie2 != null ) mc . setProperty ( HTTPConstants . HEADER_COOKIE2 , cookie2 ) ; if ( mc . getService ( ) == null ) { mc . setTargetService ( ( String ) mc . getSOAPActionURI ( ) ) ; } }
Set up any transport - specific derived properties in the message context .
39,397
public ASN1Primitive toASN1Primitive ( ) { ASN1EncodableVector vec = new ASN1EncodableVector ( ) ; vec . add ( this . policyLanguage ) ; if ( this . policy != null ) { vec . add ( this . policy ) ; } return new DERSequence ( vec ) ; }
Returns the DER - encoded ASN . 1 representation of proxy policy .
39,398
public String toFtpCmdArgument ( ) { StringBuffer msg = new StringBuffer ( ) ; msg . append ( "|" ) ; if ( this . version != null ) { msg . append ( this . version ) ; } msg . append ( "|" ) ; if ( this . host != null ) { msg . append ( this . host ) ; } msg . append ( "|" ) ; msg . append ( String . valueOf ( this . port ) ) ; msg . append ( "|" ) ; return msg . toString ( ) ; }
Returns the host - port information in the format used by EPRT command . &lt ; d&gt ; &lt ; net - prt&gt ; &lt ; d&gt ; &lt ; net - addr&gt ; &lt ; d&gt ; &lt ; tcp - port&gt ; &lt ; d&gt ;
39,399
public static void shutdown ( GSSCredential cred , GlobusURL gassURL ) throws IOException , GSSException { OutputStream output = null ; InputStream input = null ; Socket socket = null ; try { if ( gassURL . getProtocol ( ) . equalsIgnoreCase ( "https" ) ) { GSSManager manager = ExtendedGSSManager . getInstance ( ) ; ExtendedGSSContext context = ( ExtendedGSSContext ) manager . createContext ( null , GSSConstants . MECH_OID , cred , GSSContext . DEFAULT_LIFETIME ) ; context . setOption ( GSSConstants . GSS_MODE , GSIConstants . MODE_SSL ) ; GssSocketFactory factory = GssSocketFactory . getDefault ( ) ; socket = factory . createSocket ( gassURL . getHost ( ) , gassURL . getPort ( ) , context ) ; ( ( GssSocket ) socket ) . setAuthorization ( SelfAuthorization . getInstance ( ) ) ; } else { SocketFactory factory = SocketFactory . getDefault ( ) ; socket = factory . createSocket ( gassURL . getHost ( ) , gassURL . getPort ( ) ) ; } output = socket . getOutputStream ( ) ; input = socket . getInputStream ( ) ; String msg = GASSProtocol . SHUTDOWN ( SHUTDOWN_STR , gassURL . getHost ( ) ) ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Shutdown msg: " + msg ) ; } output . write ( msg . getBytes ( ) ) ; output . flush ( ) ; HttpResponse rp = new HttpResponse ( input ) ; if ( rp . httpCode == - 1 && rp . httpMsg == null ) { } else if ( rp . httpCode != 200 ) { throw new IOException ( "Remote shutdown failed (" + rp . httpCode + " " + rp . httpMsg + ")" ) ; } } finally { try { if ( output != null ) output . close ( ) ; if ( input != null ) input . close ( ) ; if ( socket != null ) socket . close ( ) ; } catch ( Exception e ) { } } }
Shutdowns a remote gass server . The server must have the CLIENT_SHUTDOWN option enabled for this to work .