Class: AnoubisSsoServer::System

Inherits:
ApplicationRecord show all
Defined in:
app/models/anoubis_sso_server/system.rb

Overview

Default System class

Instance Method Summary collapse

Instance Method Details

#after_destroy_sso_server_systemObject

Fires after System was destroyed. Clears all systems caches.



64
65
66
67
# File 'app/models/anoubis_sso_server/system.rb', line 64

def after_destroy_sso_server_system
  redis.del "#{redis_prefix}system:#{public}"
  redis.del "#{redis_prefix}jwks"
end

#after_save_sso_server_systemObject

Fires after System was saved to SQL database and setup system cache in Redis database for fast access.



57
58
59
60
# File 'app/models/anoubis_sso_server/system.rb', line 57

def after_save_sso_server_system
  redis.set("#{redis_prefix}system:#{public}", { uuid: uuid, public: public, request_uri: request_uri, jwk: jwk, ttl: ttl }.to_json )
  redis.del "#{redis_prefix}jwks"
end

#before_save_sso_server_systemObject

Fires before System was saved to SQL database. Delete old system cache if public identifier was changed.



51
52
53
# File 'app/models/anoubis_sso_server/system.rb', line 51

def before_save_sso_server_system
  redis.del "#{redis_prefix}system:#{public_was}" if public_was && public != public_was
end

#before_validation_sso_server_system_on_createObject

Fires before create system. Procedure generates public and private UUID and RSA keypair



19
20
21
22
23
24
25
26
# File 'app/models/anoubis_sso_server/system.rb', line 19

def before_validation_sso_server_system_on_create
  self.uuid = setup_private_system_id
  self.public = setup_public_system_id unless public
  self.request_uri = [] unless request_uri

  keys = JWT::JWK.new(OpenSSL::PKey::RSA.new(2048))
  self.jwk = keys.export include_private: true
end

#jwkHash

Returns JWK information

Returns:

  • (Hash)

    JWK information



45
46
47
# File 'app/models/anoubis_sso_server/system.rb', line 45

def jwk
  @jwk ||= super.deep_symbolize_keys!
end

#setup_private_system_idString

Procedure setup private user identifier. Procedure can be redefined.

Returns:

  • (String)

    public user identifier



31
32
33
# File 'app/models/anoubis_sso_server/system.rb', line 31

def setup_private_system_id
  SecureRandom.uuid
end

#setup_public_system_idString

Procedure setup public user identifier. Used for open API. Procedure can be redefined.

Returns:

  • (String)

    public user identifier



38
39
40
# File 'app/models/anoubis_sso_server/system.rb', line 38

def setup_public_system_id
  SecureRandom.uuid
end