drc_client 0.1.0
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/Manifest +4 -0
- data/README.rdoc +76 -0
- data/Rakefile +14 -0
- data/drc_client.gemspec +33 -0
- data/lib/drc_client.rb +125 -0
- metadata +74 -0
data/Manifest
ADDED
data/README.rdoc
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
= DeRose Connect Client
|
|
2
|
+
|
|
3
|
+
Rails gem for interaction with DeRose Connect
|
|
4
|
+
|
|
5
|
+
= Dependencies
|
|
6
|
+
|
|
7
|
+
(sudo) gem install echoe
|
|
8
|
+
|
|
9
|
+
(sudo) gem install rubycas-client
|
|
10
|
+
|
|
11
|
+
= Installation
|
|
12
|
+
|
|
13
|
+
git clone git@github.com:dwaynemac/drc_client.git
|
|
14
|
+
|
|
15
|
+
cd drc_client
|
|
16
|
+
|
|
17
|
+
rake manifest
|
|
18
|
+
|
|
19
|
+
(sudo) rake install
|
|
20
|
+
|
|
21
|
+
= Usage
|
|
22
|
+
|
|
23
|
+
== Environement.rb
|
|
24
|
+
|
|
25
|
+
config.gem "drc_client"
|
|
26
|
+
|
|
27
|
+
DRCClient.configure(:base_url => "https://url-to-drc-server")
|
|
28
|
+
|
|
29
|
+
== ApplicationController
|
|
30
|
+
|
|
31
|
+
include DRCClient::HelperMethods
|
|
32
|
+
|
|
33
|
+
== Filtering access
|
|
34
|
+
|
|
35
|
+
Just write in your controllers (ApplicationController if filtering full application)
|
|
36
|
+
|
|
37
|
+
before_filter DRCClient.filter(*options)
|
|
38
|
+
|
|
39
|
+
# TODO a filter that considers both drc_logged_in? and drc_user_allowed?
|
|
40
|
+
|
|
41
|
+
=== Options
|
|
42
|
+
|
|
43
|
+
<tt>:gateway</tt> - if set true, DRC-connection won't be mandatory.
|
|
44
|
+
|
|
45
|
+
<tt>:enable_single_sign_out</tt> - if set true, when logged out from DRC you'll be logout from the application as well. REQUIRES: config.action_controller.session_store = :active_record_store in environment and disabling forgery_protection
|
|
46
|
+
|
|
47
|
+
<tt>:user_model</tt> - name of your user model, defaults to User
|
|
48
|
+
|
|
49
|
+
<tt>:drc_user_column</tt> - name of the column of your user model that identifies its DRC user, defaults to drc_user
|
|
50
|
+
|
|
51
|
+
<tt>:local_user_id_column</tt> - if your user model doesn't have an :id attribute set it's id_attribute_name here.
|
|
52
|
+
|
|
53
|
+
<tt>:require_local_user</tt> - set this true if you users need a local_user on top of a DRC user. (if true set :user_model) DRCClient.filter WON'T CHECK THIS, USER drc_user_allowed?
|
|
54
|
+
|
|
55
|
+
<tt>:require_access_level</tt> - not implemented yet - define access level needed to access your app. (:none, :student, :teacher, :director)
|
|
56
|
+
|
|
57
|
+
== OTher DRCClient Methods
|
|
58
|
+
|
|
59
|
+
<tt>logout</tt> - destroys session and logs user out of DRCServer
|
|
60
|
+
|
|
61
|
+
== Helpers Available with DRCClient::HelperMethods
|
|
62
|
+
|
|
63
|
+
current_drc_user
|
|
64
|
+
|
|
65
|
+
logged_in_drc?
|
|
66
|
+
|
|
67
|
+
drc_login_url
|
|
68
|
+
|
|
69
|
+
logout_drc
|
|
70
|
+
|
|
71
|
+
get_local_user_id
|
|
72
|
+
|
|
73
|
+
drc_user_has_local_user?
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
...
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'echoe'
|
|
4
|
+
|
|
5
|
+
Echoe.new('drc_client', '0.1.0') do |p|
|
|
6
|
+
p.description = "Rails client for DeRoseConnect"
|
|
7
|
+
p.url = "http://github.com/dwaynemac/drc_client"
|
|
8
|
+
p.author = "Dwayne Macgowan"
|
|
9
|
+
p.email = "dwaynemac@gmail.com"
|
|
10
|
+
# p.ignore_pattern = ["tmp/*", "script/*"]
|
|
11
|
+
p.development_dependencies = ['rubycas-client']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/drc_client.gemspec
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{drc_client}
|
|
5
|
+
s.version = "0.1.0"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["Dwayne Macgowan"]
|
|
9
|
+
s.date = %q{2010-09-07}
|
|
10
|
+
s.description = %q{Rails client for DeRoseConnect}
|
|
11
|
+
s.email = %q{dwaynemac@gmail.com}
|
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/drc_client.rb"]
|
|
13
|
+
s.files = ["README.rdoc", "Rakefile", "lib/drc_client.rb", "Manifest", "drc_client.gemspec"]
|
|
14
|
+
s.homepage = %q{http://github.com/dwaynemac/drc_client}
|
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Drc_client", "--main", "README.rdoc"]
|
|
16
|
+
s.require_paths = ["lib"]
|
|
17
|
+
s.rubyforge_project = %q{drc_client}
|
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
|
19
|
+
s.summary = %q{Rails client for DeRoseConnect}
|
|
20
|
+
|
|
21
|
+
if s.respond_to? :specification_version then
|
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
23
|
+
s.specification_version = 3
|
|
24
|
+
|
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
26
|
+
s.add_development_dependency(%q<rubycas-client>, [">= 0"])
|
|
27
|
+
else
|
|
28
|
+
s.add_dependency(%q<rubycas-client>, [">= 0"])
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
s.add_dependency(%q<rubycas-client>, [">= 0"])
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/drc_client.rb
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# DeRose Connect Client (DRCClient) requires rubycas-client
|
|
2
|
+
require 'casclient'
|
|
3
|
+
require 'casclient/frameworks/rails/filter'
|
|
4
|
+
require 'i18n'
|
|
5
|
+
|
|
6
|
+
module DRCClient
|
|
7
|
+
|
|
8
|
+
# These are initialized when you call configure
|
|
9
|
+
@@drc_config = {
|
|
10
|
+
:base_url => nil,
|
|
11
|
+
:enable_single_sign_out => nil,
|
|
12
|
+
:user_model => nil,
|
|
13
|
+
:drc_user_column => nil,
|
|
14
|
+
:local_user_id_column => nil,
|
|
15
|
+
:require_local_user => nil,
|
|
16
|
+
:require_access_level => nil # none, student, teacher, director, federation_president
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def self.filter(opts={})
|
|
20
|
+
gateway = opts.delete(:gateway)
|
|
21
|
+
if gateway
|
|
22
|
+
CASClient::Frameworks::Rails::GatewayFilter
|
|
23
|
+
else
|
|
24
|
+
CASClient::Frameworks::Rails::Filter
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.configure(configuration)
|
|
29
|
+
@@drc_config[:base_url] = configuration.delete(:base_url)
|
|
30
|
+
@@drc_config[:enable_single_sign_out] = configuration.delete(:enable_single_sign_out) || false
|
|
31
|
+
@@drc_config[:user_model] = configuration.delete(:user_model)
|
|
32
|
+
@@drc_config[:drc_user_column] = configuration.delete(:drc_user_column) || :drc_user
|
|
33
|
+
@@drc_config[:require_local_user] = configuration.delete(:require_local_user)
|
|
34
|
+
@@drc_config[:require_access_level] = configuration.delete(:require_access_level)
|
|
35
|
+
@@drc_config[:local_user_id_column] = configuration.delete(:local_user_id_column) || :id
|
|
36
|
+
|
|
37
|
+
configuration.merge!({:cas_base_url => @@drc_config[:base_url],
|
|
38
|
+
:enable_single_sign_out => @@drc_config[:enable_single_sign_out]})
|
|
39
|
+
CASClient::Frameworks::Rails::Filter.configure(configuration)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.logout(controller,service=nil)
|
|
43
|
+
CASClient::Frameworks::Rails::Filter.logout(controller,service)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.config
|
|
47
|
+
return @@drc_config
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.mock_login(username)
|
|
51
|
+
CASClient::Frameworks::Rails::Filter.fake(username)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
module HelperMethods
|
|
55
|
+
|
|
56
|
+
def self.included(base)
|
|
57
|
+
base.send :helper_method, :logged_in_drc?, :cas_is_pama_allowed?, :current_drc_user,
|
|
58
|
+
:drc_user_has_local_user?, :login_with_drc, :drc_logout_url, :drc_login_url,
|
|
59
|
+
:drc_top_bar, :clear_local_drc_session
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def current_drc_user
|
|
63
|
+
return session[:cas_user]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def clear_local_drc_session
|
|
67
|
+
session[:cas_user] = nil
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# check if session has DRC credentials
|
|
71
|
+
def logged_in_drc?
|
|
72
|
+
return !current_drc_user.blank?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# checks if DRC credentials have access to local application
|
|
76
|
+
def allowed_drc_user?
|
|
77
|
+
return false if !logged_in_drc?
|
|
78
|
+
allowed = true # by default having a drc_user is enough
|
|
79
|
+
allowed &&= drc_user_has_local_user? if DRCClient.config[:require_local_user]
|
|
80
|
+
allowed &&= true if DRCClient.config[:require_access_level] # TODO
|
|
81
|
+
return allowed
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# finds local user that matches logged in DRC user
|
|
85
|
+
# return user's id or nil if none found
|
|
86
|
+
def get_local_user_id
|
|
87
|
+
return nil if DRCClient.config[:user_model].nil?
|
|
88
|
+
return nil unless logged_in_drc?
|
|
89
|
+
user = DRCClient.config[:user_model].find(:first,
|
|
90
|
+
:select => DRCClient.config[:local_user_id_column],
|
|
91
|
+
:conditions => { DRCClient.config[:drc_user_column] => current_drc_user})
|
|
92
|
+
if user
|
|
93
|
+
return user[DRCClient.config[:local_user_id_column].to_sym]
|
|
94
|
+
else
|
|
95
|
+
return nil
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# checks if drc_user matches any local application user.
|
|
100
|
+
def drc_user_has_local_user?
|
|
101
|
+
return !get_local_user_id.nil?
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# returns login url to DRC server.
|
|
105
|
+
def drc_login_url
|
|
106
|
+
return CASClient::Frameworks::Rails::Filter.login_url(self)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def drc_logout_url
|
|
110
|
+
return DRCClient.config[:base_url]+"/logout" # TODO strip posible / at end of base_url
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# helper for rendering top_bar
|
|
114
|
+
def drc_top_bar(local_logout_url=nil)
|
|
115
|
+
logout_href = (local_logout_url.nil?)? drc_logout_url : local_logout_url
|
|
116
|
+
ret = "<div style='width: 100%; height: 12px; top: 0; border-bottom: 1px solid grey; margin-bottom: 5px; padding-bottom: 5px; vertical-align: middle; font-size: 12px;'>"
|
|
117
|
+
ret << "<div style='text-align: left; float: left;'>DRC-Bar. (TODO: list available apps here)</div>"
|
|
118
|
+
ret << "<div style='text-align: right; float: right;'><strong>#{current_drc_user}</strong> | "
|
|
119
|
+
ret << "<a href='#{logout_href}'>#{I18n.t('logout', :default => "logout").capitalize}</a></div>"
|
|
120
|
+
ret << "</div>"
|
|
121
|
+
return ret
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
125
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: drc_client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dwayne Macgowan
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2010-09-07 00:00:00 -03:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: rubycas-client
|
|
17
|
+
type: :development
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: "0"
|
|
24
|
+
version:
|
|
25
|
+
description: Rails client for DeRoseConnect
|
|
26
|
+
email: dwaynemac@gmail.com
|
|
27
|
+
executables: []
|
|
28
|
+
|
|
29
|
+
extensions: []
|
|
30
|
+
|
|
31
|
+
extra_rdoc_files:
|
|
32
|
+
- README.rdoc
|
|
33
|
+
- lib/drc_client.rb
|
|
34
|
+
files:
|
|
35
|
+
- README.rdoc
|
|
36
|
+
- Rakefile
|
|
37
|
+
- lib/drc_client.rb
|
|
38
|
+
- Manifest
|
|
39
|
+
- drc_client.gemspec
|
|
40
|
+
has_rdoc: true
|
|
41
|
+
homepage: http://github.com/dwaynemac/drc_client
|
|
42
|
+
licenses: []
|
|
43
|
+
|
|
44
|
+
post_install_message:
|
|
45
|
+
rdoc_options:
|
|
46
|
+
- --line-numbers
|
|
47
|
+
- --inline-source
|
|
48
|
+
- --title
|
|
49
|
+
- Drc_client
|
|
50
|
+
- --main
|
|
51
|
+
- README.rdoc
|
|
52
|
+
require_paths:
|
|
53
|
+
- lib
|
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: "0"
|
|
59
|
+
version:
|
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: "1.2"
|
|
65
|
+
version:
|
|
66
|
+
requirements: []
|
|
67
|
+
|
|
68
|
+
rubyforge_project: drc_client
|
|
69
|
+
rubygems_version: 1.3.5
|
|
70
|
+
signing_key:
|
|
71
|
+
specification_version: 3
|
|
72
|
+
summary: Rails client for DeRoseConnect
|
|
73
|
+
test_files: []
|
|
74
|
+
|