public static Socket authenticate ( Socket simpleSocket , boolean isClientSocket , GSSCredential credential , int protection , DataChannelAuthentication dcau ) throws Exception { GSSContext gssContext = null ; GSSManager manager = ExtendedGSSManager . getInstance ( ) ; if ( isClientSocket ) { gssContext = manager . createContext ( null , GSSConstants . MECH_OID , credential , GSSContext . DEFAULT_LIFETIME ) ; } else { gssContext = manager . createContext ( credential ) ; } if ( protection != GridFTPSession . PROTECTION_CLEAR ) { ( ( ExtendedGSSContext ) gssContext ) . setOption ( GSSConstants . GSS_MODE , GSIConstants . MODE_SSL ) ; } gssContext . requestConf ( protection == GridFTPSession . PROTECTION_PRIVATE ) ; //Wrap the simple socket with GSI logger . debug ( "Creating secure socket" ) ; GssSocketFactory factory = GssSocketFactory . getDefault ( ) ; GssSocket secureSocket = ( GssSocket ) factory . createSocket ( simpleSocket , null , 0 , gssContext ) ; secureSocket . setUseClientMode ( isClientSocket ) ; if ( dcau == null ) { secureSocket . setAuthorization ( null ) ; } else if ( dcau == DataChannelAuthentication . SELF ) { secureSocket . setAuthorization ( SelfAuthorization . getInstance ( ) ) ; } else if ( dcau == DataChannelAuthentication . NONE ) { // this should never be } else if ( dcau instanceof DataChannelAuthentication ) { // dcau.toFtpCmdArgument() kinda hackish but it works secureSocket . setAuthorization ( new IdentityAuthorization ( dcau . toFtpCmdArgument ( ) ) ) ; } /* that will force handshake */ secureSocket . getOutputStream ( ) . flush ( ) ; if ( protection == GridFTPSession . PROTECTION_SAFE || protection == GridFTPSession . PROTECTION_PRIVATE ) { logger . debug ( "Data channel protection: on" ) ; return secureSocket ; } else { // PROTECTION_CLEAR logger . debug ( "Data channel protection: off" ) ; return simpleSocket ; } }
authenticate socket . if protection on return authenticated socket wrapped over the original simpleSocket else return original socket .