Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Fix listeners and authenticators
Browse files Browse the repository at this point in the history
  • Loading branch information
pencil committed Sep 17, 2013
1 parent cb5fc23 commit e8e65e5
Show file tree
Hide file tree
Showing 30 changed files with 59 additions and 67 deletions.
2 changes: 0 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ require 'rake'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

require 'casino_core'

task :default => :spec

desc 'Run all specs'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module CASinoCore
module CASino
class Authenticator
autoload :Static, 'casino_core/authenticator/static.rb'

class AuthenticatorError < StandardError; end

def validate(username, password)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'casino_core/authenticator'
require_relative 'authenticator'

# The static authenticator is just a simple example.
# Never ever us this authenticator in a productive environment!
class CASinoCore::Authenticator::Static < CASinoCore::Authenticator
class CASino::StaticAuthenticator < CASino::Authenticator

# @param [Hash] options
def initialize(options)
Expand Down
1 change: 0 additions & 1 deletion app/controllers/casino/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'casino'
require 'casino_core'
require 'http_accept_language'

class CASino::ApplicationController < ::ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/listeners/casino/legacy_validator_listener.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::LegacyValidatorListener < CASino::Listener
def validation_failed(text)
@controller.render text: text, content_type: 'text/plain'
Expand Down
16 changes: 16 additions & 0 deletions app/listeners/casino/listener.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module CASino
class Listener

# include helpers to have the route path methods (like sessions_path)
include CASino::Engine.routes.url_helpers

def initialize(controller)
@controller = controller
end

protected
def assign(name, value)
@controller.instance_variable_set("@#{name}", value)
end
end
end
2 changes: 2 additions & 0 deletions app/listeners/casino/login_credential_acceptor_listener.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::LoginCredentialAcceptorListener < CASino::Listener
def user_logged_in(url, ticket_granting_ticket, cookie_expiry_time = nil)
@controller.cookies[:tgt] = { value: ticket_granting_ticket, expires: cookie_expiry_time }
Expand Down
2 changes: 2 additions & 0 deletions app/listeners/casino/login_credential_requestor_listener.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::LoginCredentialRequestorListener < CASino::Listener
def user_not_logged_in(login_ticket)
assign(:login_ticket, login_ticket)
Expand Down
2 changes: 2 additions & 0 deletions app/listeners/casino/logout_listener.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::LogoutListener < CASino::Listener
def user_logged_out(url, redirect_immediately = false)
if redirect_immediately
Expand Down
2 changes: 2 additions & 0 deletions app/listeners/casino/other_sessions_destroyer_listener.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::OtherSessionsDestroyerListener < CASino::Listener
def other_sessions_destroyed(url)
@controller.redirect_to(url || sessions_path)
Expand Down
2 changes: 2 additions & 0 deletions app/listeners/casino/proxy_ticket_provider_listener.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::ProxyTicketProviderListener < CASino::Listener
def request_failed(xml)
@controller.render xml: xml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::SecondFactorAuthenticationAcceptorListener < CASino::Listener

def user_not_logged_in
Expand Down
2 changes: 2 additions & 0 deletions app/listeners/casino/session_destroyer_listener.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::SessionDestroyerListener < CASino::Listener
def ticket_deleted
@controller.redirect_to(sessions_path)
Expand Down
2 changes: 2 additions & 0 deletions app/listeners/casino/session_overview_listener.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::SessionOverviewListener < CASino::Listener
def user_not_logged_in
@controller.redirect_to login_path
Expand Down
2 changes: 2 additions & 0 deletions app/listeners/casino/ticket_validator_listener.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::TicketValidatorListener < CASino::Listener
def validation_failed(xml)
@controller.render xml: xml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::TwoFactorAuthenticatorActivatorListener < CASino::Listener
def user_not_logged_in
@controller.redirect_to login_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::TwoFactorAuthenticatorDestroyerListener < CASino::Listener
def user_not_logged_in
@controller.redirect_to login_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::TwoFactorAuthenticatorOverviewListener < CASino::Listener
def user_not_logged_in
# nothing to do here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'listener'

class CASino::TwoFactorAuthenticatorRegistratorListener < CASino::Listener
def user_not_logged_in
@controller.redirect_to login_path
Expand Down
2 changes: 1 addition & 1 deletion app/processors/casino/concerns/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def validate_login_credentials(username, password)
authenticators.each do |authenticator_name, authenticator|
begin
data = authenticator.validate(username, password)
rescue CASinoCore::Authenticator::AuthenticatorError => e
rescue CASino::Authenticator::AuthenticatorError => e
Rails.logger.error "Authenticator '#{authenticator_name}' (#{authenticator.class}) raised an error: #{e}"
end
if data
Expand Down
4 changes: 2 additions & 2 deletions config/cas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ defaults: &defaults
lifetime_unconsumed: 299
authenticators:
static_1:
class: "CASinoCore::Authenticator::Static"
class: "CASino::StaticAuthenticator"
options:
users:
testuser:
password: "foobar123"
name: "Test User"
static_2:
class: "CASinoCore::Authenticator::Static"
class: "CASino::StaticAuthenticator"
options:
users:
example:
Expand Down
3 changes: 0 additions & 3 deletions lib/casino.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
require 'active_support/configurable'
require 'casino_core'
require 'casino/engine'

module CASino
include ActiveSupport::Configurable

autoload :Listener, 'casino/listener.rb'

defaults = {
authenticators: HashWithIndifferentAccess.new,
logger: Rails.logger,
Expand Down
31 changes: 0 additions & 31 deletions lib/casino/listener.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/casino/tasks/service_rule.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'terminal-table'
require 'casino_core/helper/service_tickets'

namespace :casino do
namespace :service_rule do
include CASinoCore::Helper::ServiceTickets

desc 'Add a service rule (prefix the url parameter with "regex:" to add a regular expression)'
task :add, [:name, :url] => :environment do |task, args|
Expand Down
11 changes: 0 additions & 11 deletions lib/casino_core.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/generators/casino/install/templates/cas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ development:
<<: *defaults
authenticators:
static:
class: "CASinoCore::Authenticator::Static"
class: "CASino::StaticAuthenticator"
options:
users:
testuser:
Expand All @@ -25,7 +25,7 @@ test:
<<: *defaults
authenticators:
static:
class: "CASinoCore::Authenticator::Static"
class: "CASinoCore::StaticAuthenticator"
options:
users:
testuser:
Expand Down
4 changes: 2 additions & 2 deletions spec/authenticator/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'

describe CASinoCore::Authenticator do
describe CASino::Authenticator do
subject {
CASinoCore::Authenticator.new
CASino::Authenticator.new
}

context '#validate' do
Expand Down
4 changes: 2 additions & 2 deletions spec/authenticator/static_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'

describe CASinoCore::Authenticator::Static do
describe CASino::StaticAuthenticator do
subject {
CASinoCore::Authenticator::Static.new({
described_class.new({
users: {
user: {
password: 'testing123',
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/cas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defaults: &defaults
footer_text: "Powered by <a href=\"http://rbcas.com/\">CASino</a>"
authenticators:
static:
class: "CASinoCore::Authenticator::Static"
class: "CASino::StaticAuthenticator"
options:
users:
testuser:
Expand Down
4 changes: 2 additions & 2 deletions spec/processor/login_credential_acceptor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@

context 'when all authenticators raise an error' do
before(:each) do
CASinoCore::Authenticator::Static.any_instance.stub(:validate) do
raise CASinoCore::Authenticator::AuthenticatorError, 'error123'
CASino::StaticAuthenticator.any_instance.stub(:validate) do
raise CASino::Authenticator::AuthenticatorError, 'error123'
end
end

Expand Down

0 comments on commit e8e65e5

Please sign in to comment.