cassiopeia 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,15 +4,28 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- - Yet another custom CAS client/server implementation
7
+ - Yet another custom CAS client/server implementation. This plugin allows you to perform single-server authorization between two different rails applications.
8
8
 
9
9
  = Changelog:
10
+ - 0.0.6: Tiny refactoring.
10
11
  - 0.0.5: Some important fixes for configuration exceptions handling.
11
12
  - 0.0.4: Fixed problem with default config.
12
13
  - 0.0.3: Added required dependency simple_rest. Doc extended.
13
14
  - 0.0.2: Added some doc.
14
15
 
15
16
 
17
+ == INSTALL:
18
+
19
+ === Add these lines to environment.rb:
20
+
21
+ config.gem 'cassiopeia'
22
+ config.gem 'simple_rest'
23
+
24
+ === Run this from console:
25
+
26
+ rake gems:install
27
+
28
+
16
29
  == SYNOPSIS:
17
30
  === Client configuration
18
31
  <b>Create a file named config/cassiopeia.yml:</b>
@@ -34,8 +47,8 @@ This will force your application to request authorization from cassiopeia server
34
47
  You can also check required roles to access some controllers. To do this, you should add the following line to your controller:
35
48
  cas_require_roles :doctor, :admin
36
49
 
37
- This will raise the Cassiopeia::AccessDeniedException if user try to access this controller. You can rescue from this exception by adding the following to application_controller.rb:
38
- rescue_from 'Cassiopeia::AccessDeniedException', :with => :access_denied
50
+ This will raise the Cassiopeia::Exception::AccessDenied if user try to access this controller. You can rescue from this exception by adding the following to application_controller.rb:
51
+ rescue_from 'Cassiopeia::Exception::AccessDenied', :with => :access_denied
39
52
  def access_denied
40
53
  flash[:notice] = 'Access denied. You dont have permissions to access this page'
41
54
  redirect_to root_path
@@ -81,19 +94,11 @@ You should also provide the ability to extract user roles to array by calling ro
81
94
  end
82
95
  One more thing that might be useful to make everything work properly. Add these lines to routes.rb:
83
96
  map.resource :cas
84
- map.root :controller => "cas", :action => :index
85
97
  map.connect ':controller/:action.:format'
86
98
 
99
+ ==== Note:
100
+ Server's application controller should has helper method called "current_user".
87
101
 
88
- == INSTALL:
89
-
90
- === Add this line to environment.rb:
91
-
92
- config.gem 'cassiopeia'
93
-
94
- === Run this from console:
95
-
96
- rake gems:install
97
102
 
98
103
  == LICENSE:
99
104
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ PKG_FILES = FileList[ '[a-zA-Z]*', 'lib/**/*' ]
10
10
 
11
11
  spec = Gem::Specification.new do |s|
12
12
  s.name = "cassiopeia"
13
- s.version = "0.0.5"
13
+ s.version = "0.0.6"
14
14
  s.author = "smecsia"
15
15
  s.email = "smecsia@gmail.com"
16
16
  #s.homepage = ""
@@ -1,6 +1,7 @@
1
1
  module Cassiopeia
2
2
  module ActionControllerClientMixin
3
3
  module ActionControllerMethods
4
+ private
4
5
  ::CAS_USER_KEY = Cassiopeia::CONFIG[:current_user_key]
5
6
  ::CAS_TICKET_ID_KEY = Cassiopeia::CONFIG[:ticket_id_key]
6
7
  ::CAS_TICKET_KEY = Cassiopeia::CONFIG[:ticket_key]
@@ -3,12 +3,6 @@ module Cassiopeia
3
3
 
4
4
  module ActionControllerServerMixin
5
5
  module ActionControllerMethods
6
- def ActionControllerMethods.rolesMethod=(m)
7
- @@rolesMethod = m
8
- end
9
- def ActionControllerMethods.ticketClass=(c)
10
- @@ticketClass = c
11
- end
12
6
  def cas_ticket_id
13
7
  params[@ticket_id_key] || session[@ticket_id_key]
14
8
  end
@@ -20,7 +14,7 @@ module Cassiopeia
20
14
  end
21
15
 
22
16
  def cas_require_config
23
- unless @@ticketClass
17
+ unless Cassiopeia::CONFIG[:ticketClass]
24
18
  raise ConfigRequired.new "ticketClass should be set to use this functionality"
25
19
  end
26
20
  end
@@ -36,7 +30,7 @@ module Cassiopeia
36
30
 
37
31
  def cas_create_or_find_ticket
38
32
  if current_user && !(cas_current_ticket_exists?)
39
- @ticket = @@ticketClass.new(:user_id => current_user.id)
33
+ @ticket = Cassiopeia::CONFIG[:ticketClass].new(:user_id => current_user.id)
40
34
  @ticket.user = current_user
41
35
  @ticket.service = cas_service_id
42
36
  if @ticket.save
@@ -46,20 +40,18 @@ module Cassiopeia
46
40
  @ticket = nil
47
41
  end
48
42
  else
49
- @ticket = @@ticketClass.find_by_identity(cas_ticket_id.to_s)
43
+ @ticket = Cassiopeia::CONFIG[:ticketClass].find_by_identity(cas_ticket_id.to_s)
50
44
  end
51
45
  @ticket
52
46
  end
53
47
 
54
48
  def cas_current_ticket
55
49
  @ticket = cas_create_or_find_ticket unless @ticket
56
- logger.debug "\nCurrentTicket = #{@ticket.identity if @ticket}\n" + "="*50
57
50
  @ticket
58
51
  end
59
52
 
60
53
  def cas_current_ticket_exists?
61
- logger.debug "\nTicketExists = #{@@ticketClass.exists?(cas_ticket_id)}\n" + "="*50
62
- @@ticketClass.exists?(cas_ticket_id)
54
+ Cassiopeia::CONFIG[:ticketClass].exists?(cas_ticket_id) if cas_ticket_id > ""
63
55
  end
64
56
 
65
57
  def cas_current_ticket_valid?
@@ -72,7 +64,7 @@ module Cassiopeia
72
64
  if cas_current_ticket.user
73
65
  user_hash = cas_current_ticket.user.attributes
74
66
  roles = []
75
- roles = (cas_current_ticket.user.send @@rolesMethod) if cas_current_ticket.user.respond_to? @@rolesMethod
67
+ roles = (cas_current_ticket.user.send Cassiopeia::CONFIG[:rolesMethod]) if cas_current_ticket.user.respond_to? Cassiopeia::CONFIG[:rolesMethod]
76
68
  roles_hash = roles
77
69
  user_hash[:roles] = roles_hash
78
70
  else
@@ -85,9 +77,7 @@ module Cassiopeia
85
77
  end
86
78
 
87
79
  def cas_process_request
88
- if current_user
89
- cas_respond_current_ticket
90
- elsif cas_current_ticket_exists?
80
+ if current_user || cas_current_ticket_exists?
91
81
  cas_respond_current_ticket
92
82
  else
93
83
  @res = {:error => "Ticket not found"}
@@ -104,14 +94,15 @@ module Cassiopeia
104
94
  end
105
95
 
106
96
  def cas_proceed_auth
97
+ service_url = Cassiopeia::Server::instance.service_url(session)
107
98
  if cas_current_ticket_valid? && current_user
108
99
  logger.debug "\nCurrentTicketValid, current_user exists redirecting to service...\n" + "="*50
109
- return cas_redirect_to Cassiopeia::Server::instance.service_url(session)
100
+ return cas_redirect_to service_url
110
101
  elsif current_user
111
102
  logger.debug "\nCurrentTicketInvalid, but current_user exists, should create new ticket...\n" + "="*50
112
- cas_current_ticket.destroy
103
+ cas_current_ticket.destroy if cas_current_ticket_exists?
113
104
  cas_create_or_find_ticket
114
- return cas_redirect_to Cassiopeia::Server::instance.service_url(session)
105
+ return cas_redirect_to service_url
115
106
  elsif cas_current_ticket_exists?
116
107
  logger.debug "\nCurrentTicketInvalid, but current_user exists, destroying ticket, redirecting to login...\n" + "="*50
117
108
  cas_current_ticket.destroy
@@ -137,12 +128,14 @@ module Cassiopeia
137
128
  end
138
129
  end
139
130
  def acts_as_cas_controller
140
- defaultTicketClass = Ticket if defined? Ticket
141
- controllerConfig = Cassiopeia::TicketsControllerConfig.new defaultTicketClass, :roles
131
+ defaultTicketClass = ((defined? Ticket)?(Ticket):(Class))
132
+ defaultConfig = {
133
+ :ticketClass => defaultTicketClass,
134
+ :rolesMethod => :roles
135
+ }
136
+ controllerConfig = Cassiopeia::TicketsControllerConfig.new defaultConfig
142
137
  yield controllerConfig
143
- ActionControllerMethods.rolesMethod = controllerConfig.rolesMethod
144
- ActionControllerMethods.ticketClass = controllerConfig.ticketClass
145
- ActiveRecordServerMixin.ticketClass = controllerConfig.ticketClass
138
+ Cassiopeia::CONFIG[:rolesMethod], Cassiopeia::CONFIG[:ticketClass] = controllerConfig.rolesMethod, controllerConfig.ticketClass
146
139
  skip_before_filter :verify_authenticity_token, :only=> [:create, :index]
147
140
  before_filter :require_user, :except => [:create, :index]
148
141
  before_filter :cas_store_params, :cas_create_or_find_ticket, :cas_require_config
@@ -2,8 +2,8 @@ require 'uuidtools'
2
2
 
3
3
  module Cassiopeia
4
4
  module ActiveRecordServerMixin
5
- def ActiveRecordServerMixin.ticketClass=(c)
6
- @@ticketClass = c
5
+ def self.cassiopeia_ticketClass=(c)
6
+ @@cassiopeia_ticketClass = c
7
7
  end
8
8
  # cas ticket
9
9
  def acts_as_cas_ticket
@@ -13,7 +13,7 @@ module Cassiopeia
13
13
  (ticket = self.for_service service) && ticket.expires_at >= DateTime.now
14
14
  end
15
15
  def for_service(service)
16
- @@ticketClass.find(:first, :conditions => {:service => service, :user_id => user.id })
16
+ @@cassiopeia_ticketClass.find(:first, :conditions => {:service => service, :user_id => user.id })
17
17
  end
18
18
  end
19
19
  instance_eval do
@@ -2,9 +2,8 @@ module Cassiopeia
2
2
  class TicketsControllerConfig
3
3
  attr_accessor :ticketClass
4
4
  attr_accessor :rolesMethod
5
- def initialize(tClass, rMethod)
6
- @ticketClass = tClass
7
- @rolesMethod = rMethod
5
+ def initialize(opts={})
6
+ @ticketClass, @rolesMethod = opts[:ticketClass], opts[:rolesMethod]
8
7
  end
9
8
  end
10
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassiopeia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - smecsia
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-04 00:00:00 +03:00
12
+ date: 2010-03-17 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency