cassy 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,3 +2,42 @@
2
2
 
3
3
  This project is designed to be a Rails 3.0 engine that uses a large portion of the code from the [rubycas-server][https://github.com/gunark/rubycas-server] project. Certain portions of this code belong to the rubycas-server project owners.
4
4
 
5
+ ## Installation
6
+
7
+ This engine currently only works with Rails 3.0. To have it work with the application you must do three things:
8
+
9
+ **Install as a gem**
10
+
11
+ Put this line in your project's `Gemfile`:
12
+
13
+ gem 'cassy'
14
+
15
+ Create a new initializer (probably called `config/initializers/cassy.rb`) and point cassy at the correct configuration file of your application:
16
+
17
+ Cassy::Engine.config.config_file = Rails.root + "config/cassy.yml"
18
+
19
+ Create this configuration file at `config/cassy.yml`. Fill it with these values:
20
+
21
+ # Times are in seconds.
22
+ maximum_unused_login_ticket_lifetime: 300
23
+ maximum_unused_service_ticket_lifetime: 300
24
+
25
+ authenticator:
26
+ class: Cassy::Authenticators::Devise
27
+
28
+ The first two keys are the time-to-expiry for the login and service tickets respectively. The class for the authentication can be any constant which responds to a `validates` method. By default, only Devise authentication is supported at the moment.
29
+
30
+ Boom, done. Now this application will act as a CAS server.
31
+
32
+ ## Configuration
33
+
34
+ The configuration options for this gem go into a file, probably `config/cassy.yml` at the root of the project if you've set it up as advised, and allow the engine to be customised.
35
+
36
+ These configuration options are detailed here for your convenience. For specific term definitions, please consult the CAS spec.
37
+
38
+ `authenticator`: Must specify at least one key, `class`, which is a string version of a constant that will be used for authentication in the system. This constant *must* respond to `validate`.
39
+ `maximum_unused_login_ticket_lifetime`: The time before a login ticket would expire.
40
+ `maximum_unused_service_ticket_lifetime`: The time before a service ticket would expire.
41
+ `username_field`: Defines the field on the users table which is used for the lookup for the username. Defaults to "username".
42
+ `username_label`: Allows for the "Username" label on the sign in page to be given a different value. Helpful if you want to call it "Email" or "User Name" instead.
43
+
@@ -3,7 +3,8 @@ module Cassy
3
3
  class Devise < Base
4
4
  def self.validate(credentials)
5
5
  # Find the user with the given email
6
- user = User.find_by_email(credentials[:username])
6
+ method = "find_by_#{Cassy.config[:username_field] || 'email'}"
7
+ user = User.send(method, credentials[:username])
7
8
  # Did we find a user, and is their password valid?
8
9
  user && user.valid_password?(credentials[:password])
9
10
  end
@@ -8,6 +8,19 @@ require 'cassy/utils'
8
8
  # the Cassy::Controllers module.
9
9
  module Cassy
10
10
  module CAS
11
+
12
+ class Error
13
+ attr_reader :code, :message
14
+
15
+ def initialize(code, message)
16
+ @code = code
17
+ @message = message
18
+ end
19
+
20
+ def to_s
21
+ message
22
+ end
23
+ end
11
24
 
12
25
  def settings
13
26
  Cassy.config
@@ -147,7 +160,7 @@ module Cassy
147
160
  error = "No ticket granting ticket given."
148
161
  logger.debug error
149
162
  elsif tgt = TicketGrantingTicket.find_by_ticket(ticket)
150
- if settings.config[:maximum_session_lifetime] && Time.now - tgt.created_on > settings.config[:maximum_session_lifetime]
163
+ if settings[:maximum_session_lifetime] && Time.now - tgt.created_on > settings[:maximum_session_lifetime]
151
164
  tgt.destroy
152
165
  error = "Your session has expired. Please log in again."
153
166
  logger.info "Ticket granting ticket '#{ticket}' for user '#{tgt.username}' expired."
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cassy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - ryan@rubyx.com
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-16 00:00:00 +10:00
13
+ date: 2011-06-28 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -137,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- hash: 3009467735426729429
140
+ hash: -1080296284138574585
141
141
  segments:
142
142
  - 0
143
143
  version: "0"
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- hash: 3009467735426729429
149
+ hash: -1080296284138574585
150
150
  segments:
151
151
  - 0
152
152
  version: "0"