cassiopeia 0.0.4 → 0.0.5

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/README.rdoc CHANGED
@@ -7,9 +7,10 @@
7
7
  - Yet another custom CAS client/server implementation
8
8
 
9
9
  = Changelog:
10
- - 0.0.4: Fixed problem with default config
10
+ - 0.0.5: Some important fixes for configuration exceptions handling.
11
+ - 0.0.4: Fixed problem with default config.
11
12
  - 0.0.3: Added required dependency simple_rest. Doc extended.
12
- - 0.0.2: Added some doc
13
+ - 0.0.2: Added some doc.
13
14
 
14
15
 
15
16
  == SYNOPSIS:
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.4"
13
+ s.version = "0.0.5"
14
14
  s.author = "smecsia"
15
15
  s.email = "smecsia@gmail.com"
16
16
  #s.homepage = ""
@@ -43,7 +43,7 @@ module Cassiopeia
43
43
  if cas_required_roles
44
44
  logger.debug "\nCas check required roles #{cas_required_roles}...\n" + "="*50
45
45
  cas_required_roles.each do |r|
46
- raise Cassiopeia::AccessDeniedException.new "You don't have required roles for this controller" unless current_user.has_role? r
46
+ raise Cassiopeia::Exception::AccessDenied.new "You don't have required roles for this controller" unless current_user.has_role? r
47
47
  end
48
48
  end
49
49
  end
@@ -10,17 +10,19 @@ module Cassiopeia
10
10
  @@ticketClass = c
11
11
  end
12
12
  def cas_ticket_id
13
- session[@ticket_id_key] || params[@ticket_id_key]
13
+ params[@ticket_id_key] || session[@ticket_id_key]
14
14
  end
15
15
  def cas_service_url
16
- session[@service_url_key] || params[@service_url_key]
16
+ params[@service_url_key] || session[@service_url_key]
17
17
  end
18
18
  def cas_service_id
19
- session[@service_id_key] || params[@service_id_key]
19
+ params[@service_id_key] || session[@service_id_key]
20
20
  end
21
21
 
22
22
  def cas_require_config
23
- raise "ticketClass should be set to use this functionality" unless @@ticketClass
23
+ unless @@ticketClass
24
+ raise ConfigRequired.new "ticketClass should be set to use this functionality"
25
+ end
24
26
  end
25
27
 
26
28
  def cas_store_params
@@ -93,20 +95,28 @@ module Cassiopeia
93
95
  end
94
96
  end
95
97
 
98
+ def cas_redirect_to(url)
99
+ unless url
100
+ logger.debug "\n Cannot detect url (params = #{params.to_json}, session = #{session.to_json} \n" + "="*50
101
+ raise Cassiopeia::Exception::InvalidUrl.new "Cannot detect url for redirection! Please, check configuration."
102
+ end
103
+ redirect_to url
104
+ end
105
+
96
106
  def cas_proceed_auth
97
107
  if cas_current_ticket_valid? && current_user
98
108
  logger.debug "\nCurrentTicketValid, current_user exists redirecting to service...\n" + "="*50
99
- return redirect_to Cassiopeia::Server::instance.service_url(session)
109
+ return cas_redirect_to Cassiopeia::Server::instance.service_url(session)
100
110
  elsif current_user
101
111
  logger.debug "\nCurrentTicketInvalid, but current_user exists, should create new ticket...\n" + "="*50
102
112
  cas_current_ticket.destroy
103
113
  cas_create_or_find_ticket
104
- return redirect_to Cassiopeia::Server::instance.service_url(session)
114
+ return cas_redirect_to Cassiopeia::Server::instance.service_url(session)
105
115
  elsif cas_current_ticket_exists?
106
116
  logger.debug "\nCurrentTicketInvalid, but current_user exists, destroying ticket, redirecting to login...\n" + "="*50
107
117
  cas_current_ticket.destroy
108
118
  end
109
- redirect_to login_url
119
+ cas_redirect_to login_url
110
120
  end
111
121
 
112
122
  def create
@@ -15,6 +15,12 @@ module Cassiopeia
15
15
  end
16
16
  end
17
17
 
18
- class AccessDeniedException < Exception
18
+ module Exception
19
+ class ConfigRequired < Object::Exception
20
+ end
21
+ class AccessDenied < Object::Exception
22
+ end
23
+ class InvalidUrl < Object::Exception
24
+ end
19
25
  end
20
26
  end
@@ -6,9 +6,9 @@ module Cassiopeia
6
6
  :ticket_max_lifetime => 120,
7
7
  :server_controller => "cas",
8
8
  :session_id_key => "cassiopeia_sesion_id",
9
- :ticket_id_key => "ticket_id",
10
- :service_id_key => "service_id",
11
- :service_url_key => "service_url",
9
+ :ticket_id_key => "cas_ticket_id",
10
+ :service_id_key => "cas_service_id",
11
+ :service_url_key => "cas_service_url",
12
12
  :server_url => "https://localhost/cassiopeia",
13
13
  :service_url => "https://localhost/test_rails",
14
14
  :service_id => "test",
@@ -1,10 +1,12 @@
1
1
  module Cassiopeia
2
2
  class Server < Base
3
+ SERVICE_KEY = Cassiopeia::CONFIG[:service_url_key]
4
+ TICKET_KEY = Cassiopeia::CONFIG[:ticket_id_key]
3
5
  private
4
6
  @instance = nil
5
7
  def cas_data(session)
6
8
  {
7
- Cassiopeia::CONFIG[:ticket_id_key] => session[Cassiopeia::CONFIG[:ticket_id_key]]
9
+ TICKET_KEY => session[TICKET_KEY]
8
10
  }
9
11
  end
10
12
  public
@@ -14,9 +16,11 @@ module Cassiopeia
14
16
  end
15
17
 
16
18
  def service_url(session)
17
- session[Cassiopeia::CONFIG[:service_url_key]] + "?" + hash_to_query(cas_data(session))
19
+ if session && session[SERVICE_KEY] && session[TICKET_KEY]
20
+ session[SERVICE_KEY] + "?" + hash_to_query(cas_data(session))
21
+ end
18
22
  end
19
23
 
20
24
  end
21
-
25
+
22
26
  end
data/lib/cassiopeia.rb CHANGED
@@ -4,7 +4,7 @@ module Cassiopeia
4
4
  VERSION = '0.0.1'
5
5
  autoload :User, 'cassiopeia/user'
6
6
  autoload :Base, 'cassiopeia/base'
7
- autoload :AccessDeniedException, 'cassiopeia/base'
7
+ autoload :Exception, 'cassiopeia/base'
8
8
  autoload :Server, 'cassiopeia/server'
9
9
  autoload :Client, 'cassiopeia/client'
10
10
  autoload :CONFIG, 'cassiopeia/config'
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - smecsia