Class: Yus::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/yus/server.rb,
lib/yus/persistence/odba.rb

Instance Method Summary collapse

Constructor Details

#initialize(persistence, config, logger) ⇒ Server

Returns a new instance of Server.



13
14
15
16
17
18
19
20
# File 'lib/yus/server.rb', line 13

def initialize(persistence, config, logger)
  @needle = Needle::Registry.new
  @needle.register(:persistence) { persistence }
  @needle.register(:config) { config }
  @needle.register(:logger) { logger }
  @sessions = []
  run_cleaner
end

Instance Method Details

#autosession(domain, &block) ⇒ Object



21
22
23
24
# File 'lib/yus/server.rb', line 21

def autosession(domain, &block)
  session = AutoSession.new(@needle, domain)
  block.call(session)
end

#login(name, password, domain) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/yus/server.rb', line 25

def (name, password, domain)
  @needle.logger.info(self.class) { 
    sprintf('Login attempt for %s from %s', name, domain)
  }
  hash = @needle.config.digest.hexdigest(password.to_s)
  session = (name, hash, domain) \
    || (name, hash, domain) # raises YusError
  @sessions.push(session)
  session
end

#login_entity(*args) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/yus/server.rb', line 90

def (name, passhash, domain)
  entity = authenticate(name, passhash)
  entity.(domain)
  @needle.persistence.save_entity(entity)
  timeout = entity.get_preference("session_timeout", domain) \
    || @needle.config.session_timeout
  EntitySession.new(@needle, entity, domain)
end

#login_root(*args) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/yus/server.rb', line 98

def (name, passhash, domain)
  if(name == @needle.config.root_name \
     && passhash == @needle.config.root_pass)
    @needle.logger.info(self.class) { 
      sprintf('Authentication succeeded for root: %s', name)
    }
    RootSession.new(@needle)
  end
end

#login_token(name, token, domain) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/yus/server.rb', line 35

def (name, token, domain)
  entity = authenticate_token(name, token)
  entity.(domain)
  @needle.persistence.save_entity(entity)
  timeout = entity.get_preference("session_timeout", domain) \
    || @needle.config.session_timeout
  TokenSession.new(@needle, entity, domain)
end

#logout(session) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/yus/server.rb', line 43

def logout(session)
  @needle.logger.info(self.class) { 
    sprintf('Logout for %s', session)
  }
  @sessions.delete(session)
  if(session.respond_to?(:destroy!))
    session.destroy! 
  end
end

#odba_login_entityObject



64
65
66
67
68
69
70
71
# File 'lib/yus/persistence/odba.rb', line 64

def (name, passhash, domain)
  entity = authenticate(name, passhash)
  entity.(domain)
  @needle.persistence.save_entity(entity)
  timeout = entity.get_preference("session_timeout", domain) \
    || @needle.config.session_timeout
  EntitySession.new(@needle, entity, domain)
end

#odba_login_rootObject



65
66
67
68
69
70
71
72
73
# File 'lib/yus/persistence/odba.rb', line 65

def (name, passhash, domain)
  if(name == @needle.config.root_name \
     && passhash == @needle.config.root_pass)
    @needle.logger.info(self.class) { 
      sprintf('Authentication succeeded for root: %s', name)
    }
    RootSession.new(@needle)
  end
end

#pingObject



52
53
54
# File 'lib/yus/server.rb', line 52

def ping
  true
end