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.



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

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



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

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

#login(name, password, domain) ⇒ Object



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

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



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

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



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

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



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

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



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

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



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

def ping
  true
end