Class: Net::TTI::Client
- Inherits:
-
Object
- Object
- Net::TTI::Client
- Defined in:
- lib/net/tti/client.rb
Instance Method Summary collapse
- #authenticate(username, password) ⇒ Object
- #connect(opts = {}) ⇒ Object
- #disconnect ⇒ Object
- #get_auth_request(username, password, pre_auth_response) ⇒ Object
- #get_pre_auth_request(username) ⇒ Object
Instance Method Details
#authenticate(username, password) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/net/tti/client.rb', line 30 def authenticate( username, password ) begin pre_auth_request = get_pre_auth_request( username ) pre_auth_response_raw = @tti_conn.send_and_receive(pre_auth_request) pre_auth_response = PreAuthenticationResponse.read(pre_auth_response_raw) auth_request = get_auth_request(username, password, pre_auth_response) @tti_conn.send_and_receive(auth_request) rescue Exceptions::ErrorMessageReceived => error case error.error_code when 1017, 9275 raise Exceptions::InvalidCredentialsError.new( error. ) when 28000 raise Exceptions::AccountLockedOutError.new( error. ) when 28001 raise Exceptions::PasswordExpiredError.new( error. ) when 28002 # This is "password will expire in 7 days," i.e. a successful login else raise end end return true end |
#connect(opts = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/net/tti/client.rb', line 7 def connect(opts={}) socket_opts = {} socket_opts_keys = [:host, :port, :new_socket_proc] socket_opts_keys.each {|key| socket_opts[key] = opts.delete(key) if opts.has_key?(key)} connect_opts = {} connect_opts_keys = [:sid, :service_name] connect_opts_keys.each {|key| connect_opts[key] = opts.delete(key) if opts.has_key?(key)} unless opts.empty? raise ArgumentError.new("Unrecognized #connect options: #{opts.keys.join(",")}") end begin @tti_conn = Net::TTI::Connection.new(socket_opts) @tti_conn.connect(connect_opts) rescue (@tti_conn.disconnect rescue nil) unless @tti_conn.nil? raise end Net::TTI.logger.info("TTI connection established. #{@tti_conn.conn_params}") end |
#disconnect ⇒ Object
93 94 95 |
# File 'lib/net/tti/client.rb', line 93 def disconnect @tti_conn.disconnect() unless @tti_conn.nil? end |
#get_auth_request(username, password, pre_auth_response) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/net/tti/client.rb', line 65 def get_auth_request(username, password, pre_auth_response) auth_sesskey = pre_auth_response.auth_sesskey case @tti_conn.conn_params.tns_version when Net::TNS::Version::VERSION_10G enc_password, enc_client_session_key = Net::TTI::Crypto.get_10g_auth_values( username, password, auth_sesskey ) when Net::TNS::Version::VERSION_11G case auth_sesskey.length when 32 enc_password, enc_client_session_key = Net::TTI::Crypto.get_10g_auth_values( username, password, auth_sesskey ) when 48 auth_vfr_data = pre_auth_response.auth_vfr_data enc_password, enc_client_session_key = Net::TTI::Crypto.get_11g_auth_values( password, auth_sesskey, auth_vfr_data ) else raise Exceptions::ProtocolException.new("Unexpected AUTH_SESSKEY length #{auth_sesskey.length}") end else raise Exceptions::UnsupportedTNSVersion.new( @tti_conn.conn_params.tns_version ) end auth_request = Authentication.create_auth_request() auth_request.username = username auth_request.enc_password = enc_password auth_request.enc_client_session_key = enc_client_session_key auth_request.add_parameter("AUTH_TERMINAL", "unknown") return auth_request end |
#get_pre_auth_request(username) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/net/tti/client.rb', line 58 def get_pre_auth_request(username) pre_auth_request = Authentication.create_pre_auth_request() pre_auth_request.username = username pre_auth_request.add_parameter("AUTH_TERMINAL", "unknown") return pre_auth_request end |