casino_core 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/casino_core.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "casino_core"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nils Caspar"]
@@ -50,6 +50,7 @@ Gem::Specification.new do |s|
50
50
  "lib/casino_core/helper/logger.rb",
51
51
  "lib/casino_core/helper/login_tickets.rb",
52
52
  "lib/casino_core/helper/service_tickets.rb",
53
+ "lib/casino_core/helper/ticket_granting_tickets.rb",
53
54
  "lib/casino_core/helper/tickets.rb",
54
55
  "lib/casino_core/model.rb",
55
56
  "lib/casino_core/model/login_ticket.rb",
@@ -63,6 +64,7 @@ Gem::Specification.new do |s|
63
64
  "lib/casino_core/processor/login_credential_requestor.rb",
64
65
  "lib/casino_core/processor/logout.rb",
65
66
  "lib/casino_core/processor/session_destroyer.rb",
67
+ "lib/casino_core/processor/session_overview.rb",
66
68
  "lib/casino_core/railtie.rb",
67
69
  "lib/casino_core/rake_tasks.rb",
68
70
  "lib/casino_core/settings.rb",
@@ -76,6 +78,7 @@ Gem::Specification.new do |s|
76
78
  "spec/processor/login_credential_requestor_spec.rb",
77
79
  "spec/processor/logout_spec.rb",
78
80
  "spec/processor/session_destroyer_spec.rb",
81
+ "spec/processor/session_overview_spec.rb",
79
82
  "spec/spec_helper.rb"
80
83
  ]
81
84
  s.homepage = "http://github.com/pencil/CASinoCore"
@@ -0,0 +1,24 @@
1
+ require 'addressable/uri'
2
+
3
+ module CASinoCore
4
+ module Helper
5
+ module TicketGrantingTickets
6
+ include CASinoCore::Helper::Browser
7
+ include CASinoCore::Helper::Logger
8
+
9
+ def find_valid_ticket_granting_ticket(tgt, user_agent)
10
+ ticket_granting_ticket = CASinoCore::Model::TicketGrantingTicket.where(ticket: tgt).first
11
+ unless ticket_granting_ticket.nil?
12
+ if same_browser?(ticket_granting_ticket.user_agent, user_agent)
13
+ ticket_granting_ticket.user_agent = user_agent
14
+ ticket_granting_ticket.save!
15
+ ticket_granting_ticket
16
+ else
17
+ logger.info 'User-Agent changed: ticket-granting ticket not valid for this browser'
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -8,5 +8,6 @@ module CASinoCore
8
8
  autoload :LoginTickets, 'casino_core/helper/login_tickets.rb'
9
9
  autoload :ServiceTickets, 'casino_core/helper/service_tickets.rb'
10
10
  autoload :Tickets, 'casino_core/helper/tickets.rb'
11
+ autoload :TicketGrantingTickets, 'casino_core/helper/ticket_granting_tickets.rb'
11
12
  end
12
13
  end
@@ -6,4 +6,9 @@ class CASinoCore::Model::TicketGrantingTicket < ActiveRecord::Base
6
6
  validates :ticket, uniqueness: true
7
7
  has_many :service_tickets
8
8
  has_many :proxy_granting_tickets
9
+
10
+ def browser_info
11
+ user_agent = UserAgent.parse(self.user_agent)
12
+ "#{user_agent.browser} (#{user_agent.platform})"
13
+ end
9
14
  end
@@ -6,6 +6,7 @@ class CASinoCore::Processor::LoginCredentialRequestor < CASinoCore::Processor
6
6
  include CASinoCore::Helper::Logger
7
7
  include CASinoCore::Helper::LoginTickets
8
8
  include CASinoCore::Helper::ServiceTickets
9
+ include CASinoCore::Helper::TicketGrantingTickets
9
10
 
10
11
  def process(params = nil, cookies = nil, user_agent = nil)
11
12
  params ||= {}
@@ -21,19 +22,4 @@ class CASinoCore::Processor::LoginCredentialRequestor < CASinoCore::Processor
21
22
  @listener.user_not_logged_in(login_ticket)
22
23
  end
23
24
  end
24
-
25
- private
26
- def find_valid_ticket_granting_ticket(tgt, user_agent)
27
- ticket_granting_ticket = CASinoCore::Model::TicketGrantingTicket.where(ticket: tgt).first
28
- unless ticket_granting_ticket.nil?
29
- if same_browser?(ticket_granting_ticket.user_agent, user_agent)
30
- ticket_granting_ticket.user_agent = user_agent
31
- ticket_granting_ticket.save!
32
- ticket_granting_ticket
33
- else
34
- logger.info 'User-Agent changed: ticket-granting ticket not valid for this browser'
35
- nil
36
- end
37
- end
38
- end
39
25
  end
@@ -0,0 +1,25 @@
1
+ require 'casino_core/processor'
2
+ require 'casino_core/helper'
3
+ require 'casino_core/model'
4
+
5
+ # The SessionOverview processor to list all open session for the currently signed in user.
6
+ #
7
+ # This feature is not described in the CAS specification so it's completly optional
8
+ # to implement this on the web application side.
9
+ class CASinoCore::Processor::SessionOverview < CASinoCore::Processor
10
+ include CASinoCore::Helper::TicketGrantingTickets
11
+
12
+ # This method will call `#user_not_logged_in` or `#ticket_granting_tickets_found(Enumerable)` on the listener.
13
+ # @param [Hash] cookies cookies delivered by the client
14
+ # @param [String] user_agent user-agent delivered by the client
15
+ def process(cookies = nil, user_agent = nil)
16
+ cookies ||= {}
17
+ tgt = find_valid_ticket_granting_ticket(cookies[:tgt], user_agent)
18
+ if tgt.nil?
19
+ @listener.user_not_logged_in
20
+ else
21
+ ticket_granting_tickets = CASinoCore::Model::TicketGrantingTicket.where(username: tgt.username).order('updated_at DESC')
22
+ @listener.ticket_granting_tickets_found(ticket_granting_tickets)
23
+ end
24
+ end
25
+ end
@@ -7,6 +7,7 @@ module CASinoCore
7
7
  autoload :LoginCredentialRequestor, 'casino_core/processor/login_credential_requestor.rb'
8
8
  autoload :Logout, 'casino_core/processor/logout.rb'
9
9
  autoload :SessionDestroyer, 'casino_core/processor/session_destroyer.rb'
10
+ autoload :SessionOverview, 'casino_core/processor/session_overview.rb'
10
11
 
11
12
  def initialize(listener)
12
13
  @listener = listener
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe CASinoCore::Processor::SessionOverview do
4
+ describe '#process' do
5
+ let(:listener) { Object.new }
6
+ let(:processor) { described_class.new(listener) }
7
+ let(:user_agent) { 'TestBrowser 1.0' }
8
+ let(:other_ticket_granting_ticket) {
9
+ CASinoCore::Model::TicketGrantingTicket.create!({
10
+ ticket: 'TGC-ocCudGzZjJtrvOXJ485mt3',
11
+ username: 'test',
12
+ extra_attributes: nil,
13
+ user_agent: user_agent
14
+ })
15
+ }
16
+ let(:cookies) { { tgt: tgt } }
17
+
18
+ before(:each) do
19
+ listener.stub(:user_not_logged_in)
20
+ listener.stub(:ticket_granting_tickets_found)
21
+ other_ticket_granting_ticket
22
+ end
23
+
24
+ context 'with an existing ticket-granting ticket' do
25
+ let(:ticket_granting_ticket) {
26
+ CASinoCore::Model::TicketGrantingTicket.create!({
27
+ ticket: 'TGC-HXdkW233TsRtiqYGq4b8U7',
28
+ username: 'test',
29
+ extra_attributes: nil,
30
+ user_agent: user_agent
31
+ })
32
+ }
33
+ let(:tgt) { ticket_granting_ticket.ticket }
34
+ it 'calls the #ticket_granting_tickets_found method on the listener' do
35
+ listener.should_receive(:ticket_granting_tickets_found) do |tickets|
36
+ tickets.length.should == 2
37
+ end
38
+ processor.process(cookies, user_agent)
39
+ end
40
+ end
41
+
42
+ context 'with an invalid ticket-granting ticket' do
43
+ let(:tgt) { 'TGT-lalala' }
44
+ it 'calls the #user_not_logged_in method on the listener' do
45
+ listener.should_receive(:user_not_logged_in).with(no_args)
46
+ processor.process(cookies, user_agent)
47
+ end
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: casino_core
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nils Caspar
@@ -176,6 +176,7 @@ files:
176
176
  - lib/casino_core/helper/logger.rb
177
177
  - lib/casino_core/helper/login_tickets.rb
178
178
  - lib/casino_core/helper/service_tickets.rb
179
+ - lib/casino_core/helper/ticket_granting_tickets.rb
179
180
  - lib/casino_core/helper/tickets.rb
180
181
  - lib/casino_core/model.rb
181
182
  - lib/casino_core/model/login_ticket.rb
@@ -189,6 +190,7 @@ files:
189
190
  - lib/casino_core/processor/login_credential_requestor.rb
190
191
  - lib/casino_core/processor/logout.rb
191
192
  - lib/casino_core/processor/session_destroyer.rb
193
+ - lib/casino_core/processor/session_overview.rb
192
194
  - lib/casino_core/railtie.rb
193
195
  - lib/casino_core/rake_tasks.rb
194
196
  - lib/casino_core/settings.rb
@@ -202,6 +204,7 @@ files:
202
204
  - spec/processor/login_credential_requestor_spec.rb
203
205
  - spec/processor/logout_spec.rb
204
206
  - spec/processor/session_destroyer_spec.rb
207
+ - spec/processor/session_overview_spec.rb
205
208
  - spec/spec_helper.rb
206
209
  homepage: http://github.com/pencil/CASinoCore
207
210
  licenses:
@@ -216,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
219
  requirements:
217
220
  - - ">="
218
221
  - !ruby/object:Gem::Version
219
- hash: 3655648901496151978
222
+ hash: 4231038589682610511
220
223
  segments:
221
224
  - 0
222
225
  version: "0"