Class: Wampus::Servers::WampCra

Inherits:
Wamp
  • Object
show all
Includes:
Protocols::WampCra, Rpc::ServerExt
Defined in:
lib/wampus/servers/wamp_cra.rb

Constant Summary

Constants included from Protocols::WampCra

Protocols::WampCra::URI_PROCEDURE

Constants included from Protocols::Wamp

Protocols::Wamp::CALL_ERROR_MSG_ID, Protocols::Wamp::CALL_MSG_ID, Protocols::Wamp::CALL_RESULT_MSG_ID, Protocols::Wamp::EVENT_MSG_ID, Protocols::Wamp::PREFIX_MSG_ID, Protocols::Wamp::PROTOCOL_VERSION, Protocols::Wamp::PUBLISH_MSG_ID, Protocols::Wamp::SUBSCRIBE_MSG_ID, Protocols::Wamp::UNSUBSCRIBE_MSG_ID, Protocols::Wamp::URI_BASE, Protocols::Wamp::URI_ERROR, Protocols::Wamp::URI_RPC, Protocols::Wamp::URI_TOPIC, Protocols::Wamp::WELCOME_MSG_ID

Instance Attribute Summary

Attributes included from Rpc::ServerExt

#rpcs

Attributes inherited from Wamp

#connections

Instance Method Summary collapse

Methods included from Rpc::ServerExt

#handle_call_msg, #initialize, #on_after_call_error, #on_after_call_success, #on_after_send_call_error, #on_before_call

Methods included from Protocols::WampCra

#auth_signature, #derive_key

Methods included from Protocols::Wamp

#call_error_msg, #call_msg, #call_result_msg, #event_msg, #prefix_msg, #publish_msg, #subscribe_msg, #unsubscribe_msg, #welcome_msg

Methods inherited from Wamp

#handle_call_msg, #handle_prefix_msg, #handle_publish_msg, #handle_subscribe_msg, #handle_unsubscribe_msg, #initialize, #on_connection_close, #on_connection_error, #on_connection_message, #on_connection_open, #run, #server_ident

Methods included from AfterInit

#exec_after_init, #initialize

Instance Method Details

#auth(connection, signature = nil) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/wampus/servers/wamp_cra.rb', line 79

def auth(connection, signature = nil)
  if connection.authenticated
    raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'already-authenticated', 'Already Authenticated')
  end

  if connection.pending_auth.nil?
    raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'no-authentication-requested', 'No Authentication Requested')
  end

  if connection.pending_auth[1] != signature
    connection.pending_auth = nil

    return EventMachine.add_timer(expo(1.25)) {
      raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'invalid-signature', 'Signature for authentication request is invalid')
    }
  end

  permissions = connection.pending_auth[2]
  auth_key = connection.pending_auth[0][:auth_key]
  connection.authenticated = true
  connection.pending_auth = nil
  unless connection.auth_timeout_call.nil?
    connection.auth_timeout_call.cancel
    connection.auth_timeout_call = nil
  end

  on_authenticated connection, auth_key, permissions

  permissions[:permissions]
end

#auth_request(connection, auth_key = nil, extra = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/wampus/servers/wamp_cra.rb', line 45

def auth_request(connection, auth_key = nil, extra = {})
  if connection.authenticated
    raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'already-authenticated', 'Already Authenticated')
  end

  unless connection.pending_auth.nil?
    raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'authentication-already-requested', 'Authentication Already Requested')
  end

  extra = {} if extra.nil?
  unless extra.is_a? Hash
    raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'invalid-argument', 'Extra is not a Dictionary/Hash')
  end

  if auth_key.nil? && !client_auth_allow_anonymous
    raise Wampus::Errors::CallError.new(Wampus::Protocols::Wamp::URI_ERROR+'anonymous-auth-forbidden', 'Anonymous Auth Forbidden')
  end

  auth_secret = get_auth_secret connection, auth_key
  on_get_auth_secret_ok connection, auth_secret, auth_key, extra
end

#auth_status(connection) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/wampus/servers/wamp_cra.rb', line 67

def auth_status(connection)
  if connection.authenticated
    return :authenticated
  end

  unless connection.pending_auth.nil?
    return :pending
  end

  :unauthenticated
end

#get_auth_permissions(connection, auth_key, auth_extra) ⇒ Object

Implement in your server



18
19
20
# File 'lib/wampus/servers/wamp_cra.rb', line 18

def get_auth_permissions(connection, auth_key, auth_extra)
  {:permissions => { :pubsub => [], :rpc => [] } }
end

#get_auth_secret(connection, auth_key) ⇒ Object

Implement in your server



23
24
25
# File 'lib/wampus/servers/wamp_cra.rb', line 23

def get_auth_secret(connection, auth_key)
  nil
end

#on_auth_timeout(connection) ⇒ Object

Implement in your server



28
29
30
# File 'lib/wampus/servers/wamp_cra.rb', line 28

def on_auth_timeout(connection)
  # Nothing
end

#on_authenticated(connection, auth_key, permissions) ⇒ Object

Implement in your server



33
34
35
# File 'lib/wampus/servers/wamp_cra.rb', line 33

def on_authenticated(connection, auth_key, permissions)
  # Nothing
end

#on_session_open(connection) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/wampus/servers/wamp_cra.rb', line 37

def on_session_open(connection)
  if client_auth_timeout > 0
    connection.auth_timeout_call = EventMachine.add_timer(client_auth_timeout) {
      on_auth_timeout(connection)
    }
  end
end