jorahood-rubycas-client 2.0.99.1
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/CHANGELOG.txt +1 -0
- data/History.txt +162 -0
- data/LICENSE.txt +504 -0
- data/Manifest.txt +23 -0
- data/README.rdoc +334 -0
- data/Rakefile +63 -0
- data/init.rb +6 -0
- data/lib/casclient.rb +89 -0
- data/lib/casclient/client.rb +211 -0
- data/lib/casclient/frameworks/merb/strategy.rb +110 -0
- data/lib/casclient/frameworks/rails/cas_proxy_callback_controller.rb +76 -0
- data/lib/casclient/frameworks/rails/filter.rb +195 -0
- data/lib/casclient/responses.rb +179 -0
- data/lib/casclient/tickets.rb +38 -0
- data/lib/casclient/version.rb +9 -0
- data/lib/rubycas-client.rb +5 -0
- data/setup.rb +1585 -0
- metadata +94 -0
data/Manifest.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
CHANGELOG.txt
|
|
2
|
+
History.txt
|
|
3
|
+
LICENSE.txt
|
|
4
|
+
Manifest.txt
|
|
5
|
+
README.rdoc
|
|
6
|
+
Rakefile
|
|
7
|
+
examples/merb/README.textile
|
|
8
|
+
examples/merb/Rakefile
|
|
9
|
+
examples/merb/merb.thor
|
|
10
|
+
examples/merb/merb_auth_cas.rb
|
|
11
|
+
examples/merb/spec/spec_helper.rb
|
|
12
|
+
init.rb
|
|
13
|
+
lib/casclient.rb
|
|
14
|
+
lib/casclient/client.rb
|
|
15
|
+
lib/casclient/frameworks/merb/filter.rb
|
|
16
|
+
lib/casclient/frameworks/merb/strategy.rb
|
|
17
|
+
lib/casclient/frameworks/rails/cas_proxy_callback_controller.rb
|
|
18
|
+
lib/casclient/frameworks/rails/filter.rb
|
|
19
|
+
lib/casclient/responses.rb
|
|
20
|
+
lib/casclient/tickets.rb
|
|
21
|
+
lib/casclient/version.rb
|
|
22
|
+
lib/rubycas-client.rb
|
|
23
|
+
setup.rb
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
=== IU-specific modifications
|
|
2
|
+
|
|
3
|
+
in your rubyCAS initializer, you need to specify the login_url and validate_url as well as the base_url like so:
|
|
4
|
+
|
|
5
|
+
require 'casclient'
|
|
6
|
+
require 'casclient/frameworks/rails/filter'
|
|
7
|
+
|
|
8
|
+
CASClient::Frameworks::Rails::Filter.configure(
|
|
9
|
+
:cas_base_url => 'https://cas.iu.edu/cas/',
|
|
10
|
+
# Re: 'cassvc' param, see https://kb.iu.edu/data/alqm.html
|
|
11
|
+
:login_url => 'https://cas.iu.edu/cas/login?cassvc=ANY',
|
|
12
|
+
:validate_url => 'https://cas.iu.edu/cas/validate?cassvc=ANY'
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
= RubyCAS-Client
|
|
16
|
+
|
|
17
|
+
Author:: Matt Zukowski <matt AT roughest DOT net>; inspired by code by Ola Bini <ola.bini AT ki DOT se> and Matt Walker <mwalker AT tamu DOT edu>
|
|
18
|
+
Copyright:: (c) 2008 Urbacon Ltd.
|
|
19
|
+
License:: GNU Lesser General Public License v2.1 (LGPL 2.1)
|
|
20
|
+
Websites:: http://code.google.com/p/rubycas-client
|
|
21
|
+
http://github.com/gunark/rubycas-client
|
|
22
|
+
http://rubyforge.org/projects/rubycas-client
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
=== RubyCAS-Client is a Ruby client library for Yale's Central Authentication Service (CAS) protocol.
|
|
27
|
+
|
|
28
|
+
CAS provides a secure single sign on solution for web-based applications. The user logs in to your
|
|
29
|
+
organization's CAS server, and is automatically authenticated for all other CAS-enabled applications.
|
|
30
|
+
|
|
31
|
+
For general information about the open CAS protocol, please have a look at http://www.ja-sig.org/products/cas.
|
|
32
|
+
|
|
33
|
+
If your organization does not already have a CAS server, you may be interested in RubyCAS-Client's sister project,
|
|
34
|
+
RubyCAS-Server[http://code.google.com/p/rubycas-server/].
|
|
35
|
+
|
|
36
|
+
The RubyCAS-Client package includes adapters for Rails and Merb, although the client library itself can be
|
|
37
|
+
adapted for other frameworks (for example an implementation for Camping is available via the Picnic[http://github.com/zuk/picnic/tree/master]
|
|
38
|
+
library).
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
== Getting help and reporting problems
|
|
42
|
+
|
|
43
|
+
If you need help, try posting to the RubyCAS discussion group at http://groups.google.com/group/rubycas-server.
|
|
44
|
+
|
|
45
|
+
To report problems, please use the Google Code issue tracker at http://code.google.com/p/rubycas-client/issues/list.
|
|
46
|
+
|
|
47
|
+
API documentation (i.e. the RDocs) are available at http://rubycas-client.rubyforge.org
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
== Installation
|
|
51
|
+
|
|
52
|
+
You can download the latest version of RubyCAS-Client from the project's rubyforge page at
|
|
53
|
+
http://rubyforge.org/projects/rubycas-client.
|
|
54
|
+
|
|
55
|
+
However, if you're using Rails, it's easier to install the CAS client as a plugin:
|
|
56
|
+
|
|
57
|
+
cd <your rails app>
|
|
58
|
+
./script/plugin install http://rubycas-client.googlecode.com/svn/trunk/rubycas-client
|
|
59
|
+
|
|
60
|
+
Alternatively, the library is also installable as a RubyGem[http://rubygems.org]:
|
|
61
|
+
|
|
62
|
+
gem install rubycas-client
|
|
63
|
+
|
|
64
|
+
If your Rails application is under Subversion control, you can also install the plugin as an svn:external, ensuring that
|
|
65
|
+
you always have the latest bleeding-edge version of RubyCAS-Client:
|
|
66
|
+
|
|
67
|
+
./script/plugin install -x http://rubycas-client.googlecode.com/svn/trunk/rubycas-client
|
|
68
|
+
|
|
69
|
+
With Rails 2.1 or newer, it is also possible to install the plugin directly from the bleeding-edge git repository:
|
|
70
|
+
|
|
71
|
+
./script/plugin install git://github.com/gunark/rubycas-client.git
|
|
72
|
+
|
|
73
|
+
== Usage Examples
|
|
74
|
+
|
|
75
|
+
If you'd rather jump right in, have a look at the example Rails and Merb applications pre-configured for CAS
|
|
76
|
+
authentication:
|
|
77
|
+
|
|
78
|
+
http://github.com/gunark/rubycas-client/tree/master/examples
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
Otherwise, continue reading for a step-by-step guide for integrating RubyCAS-Client with Rails:
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
==== Using RubyCAS-Client in Rails controllers
|
|
85
|
+
|
|
86
|
+
<i>Note that from this point on we are assuming that you have a working CAS server up and running!</i>
|
|
87
|
+
|
|
88
|
+
After installing RubyCAS-Client as a plugin (see above), add the following to your app's <tt>config/environment.rb</tt>
|
|
89
|
+
(make sure that you put it at the bottom of the file, *after* the Rails Initializer):
|
|
90
|
+
|
|
91
|
+
CASClient::Frameworks::Rails::Filter.configure(
|
|
92
|
+
:cas_base_url => "https://cas.example.foo/"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
(Change the <tt>:cas_base_url</tt> value to your CAS server's base URL; also note that many CAS servers are configured
|
|
96
|
+
with a base URL that looks more like "https://cas.example.foo/cas".)
|
|
97
|
+
|
|
98
|
+
Then, in your <tt>app/controllers/application.rb</tt> (or in whichever controller you want to add the CAS filter for):
|
|
99
|
+
|
|
100
|
+
before_filter CASClient::Frameworks::Rails::Filter
|
|
101
|
+
|
|
102
|
+
That's it. You should now find that you are redirected to your CAS login page whenever you try to access any action
|
|
103
|
+
in your protected controller. You can of course qualify the <tt>before_filter</tt> as you would with any other ActionController
|
|
104
|
+
filter. For example:
|
|
105
|
+
|
|
106
|
+
before_filter CASClient::Frameworks::Rails::Filter, :except => [ :unprotected_action, :another_unprotected_action ]
|
|
107
|
+
|
|
108
|
+
<b>Once the user has been authenticated, their authenticated username is available under <tt>session[:cas_user]</tt>,</b>
|
|
109
|
+
If you want to do something with this username (for example load a user record from the database), you can append another
|
|
110
|
+
filter method that checks for this value and does whatever you need it to do.
|
|
111
|
+
|
|
112
|
+
<b>Note:</b> If Rails complains about missing constants, try adding this before the CASClient configuration:
|
|
113
|
+
|
|
114
|
+
require 'casclient'
|
|
115
|
+
require 'casclient/frameworks/rails/filter'
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
==== A more complicated example
|
|
119
|
+
|
|
120
|
+
Here is a more complicated configuration showing most of the configuration options along with their default values
|
|
121
|
+
(this does not show proxy options, which are covered in the next section):
|
|
122
|
+
|
|
123
|
+
# enable detailed CAS logging
|
|
124
|
+
cas_logger = CASClient::Logger.new(RAILS_ROOT+'/log/cas.log')
|
|
125
|
+
cas_logger.level = Logger::DEBUG
|
|
126
|
+
|
|
127
|
+
CASClient::Frameworks::Rails::Filter.configure(
|
|
128
|
+
:cas_base_url => "https://cas.example.foo/",
|
|
129
|
+
:login_url => "https://cas.example.foo/login",
|
|
130
|
+
:logout_url => "https://cas.example.foo/logout",
|
|
131
|
+
:validate_url => "https://cas.example.foo/proxyValidate",
|
|
132
|
+
:username_session_key => :cas_user,
|
|
133
|
+
:extra_attributes_session_key => :cas_extra_attributes,
|
|
134
|
+
:logger => cas_logger,
|
|
135
|
+
:authenticate_on_every_request => true
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
Note that normally it is not necessary to specify <tt>:login_url</tt>, <tt>:logout_url</tt>, and <tt>:validate_url</tt>.
|
|
139
|
+
These values are automatically set to standard CAS defaults based on the given <tt>:cas_base_url</tt>.
|
|
140
|
+
|
|
141
|
+
The <tt>:username_session_key</tt> value determines the key under which you can find the CAS username in the Rails session hash.
|
|
142
|
+
|
|
143
|
+
Any additional info that the CAS server might have supplied about the user during authentication will be found under the
|
|
144
|
+
<tt>:extra_attributes_session_key</tt> value in the Rails session hash (i.e. given the above configuration, you would find this
|
|
145
|
+
info under <tt>session[:cas_extra_attributes]</tt>).
|
|
146
|
+
|
|
147
|
+
An arbitrary Logger instance can be given as the :logger parameter. In the example above we log all CAS activity to a
|
|
148
|
+
<tt>log/cas.log</tt> file in your Rails app's directory.
|
|
149
|
+
|
|
150
|
+
==== Re-authenticating on every request (i.e. the "single sign-out problem")
|
|
151
|
+
|
|
152
|
+
By default, the Rails filter will only authenticate with the CAS server when no session[:cas_user] value exists. Once the user
|
|
153
|
+
has been authenticated, no further CAS forwarding is done until the user's session is wiped. This saves you
|
|
154
|
+
the trouble of having to do this check yourself (since in most cases it is not advisable to go through the CAS server
|
|
155
|
+
on every request -- this is slow and would potentially lead to problems, for example for AJAX requests). However,
|
|
156
|
+
the disadvantage is that the filter no longer checks to make sure that the user's CAS session is still actually open.
|
|
157
|
+
In other words it is possible for the user's authentication session to be closed on the CAS server without the
|
|
158
|
+
client application knowing about it.
|
|
159
|
+
|
|
160
|
+
To address this, RubyCAS-Client now supports the new "Single Sign-Out" functionality in CAS 3.1, allowing the server to
|
|
161
|
+
notify the client application that the CAS session is closed. The client will automatically intercept Single Sign-Out
|
|
162
|
+
requsts from the CAS server, but in order for this to work you must configure your Rails application as follows:
|
|
163
|
+
|
|
164
|
+
1. The Rails session store must be set to ActiveRecord: <tt>config.action_controller.session_store = :active_record_store</tt>
|
|
165
|
+
2. The server must be able to read and write to RAILS_ROOT/tmp/sessions. If you are in a clustered environment,
|
|
166
|
+
the contents of this directory must be shared between all server instances.
|
|
167
|
+
3. Cross-site request forgery protection must be disabled. In your <tt>application.rb</tt>: <tt>self.allow_forgery_protection = false</tt>.
|
|
168
|
+
(Or rather you may want to disable forgery protection only for actions that are behind the CAS filter.)
|
|
169
|
+
|
|
170
|
+
The best way to debug single-sign out functionality is to configure your CAS client with logging (see above) and then watch the
|
|
171
|
+
log to ensure that single-sign out requests from the server are being processed correctly.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
Alternatively, it is possible to disable authentication persistence in the client by setting the <tt>:authenticate_on_every_request</tt>
|
|
175
|
+
configuration option to true as, in the example in the previous section. However, this is not recommended as it will almost
|
|
176
|
+
certainly have a deleterious impact on performance and can interfere with certain HTTP transactions (AJAX requests, for example).
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
==== Defining a 'logout' action
|
|
180
|
+
|
|
181
|
+
Your Rails application's controller(s) will probably have some sort of logout function. Here you can do any necessary local
|
|
182
|
+
cleanup, and then call <tt>CASClient::Frameworks::Rails::Filter.logout(controller)</tt>. For example:
|
|
183
|
+
|
|
184
|
+
class ApplicationController < ActionController::Base
|
|
185
|
+
|
|
186
|
+
# ...
|
|
187
|
+
|
|
188
|
+
def logout
|
|
189
|
+
# optionally do some local cleanup here
|
|
190
|
+
# ...
|
|
191
|
+
|
|
192
|
+
CASClient::Frameworks::Rails::Filter.logout(self)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
By default, the logout method will clear the local Rails session, do some local CAS cleanup, and redirect to the CAS
|
|
197
|
+
logout page. Additionally, the <tt>request.referer</tt> value from the <tt>controller</tt> instance is passed to the
|
|
198
|
+
CAS server as a 'destination' parameter. This allows RubyCAS server to provide a follow-up login page allowing
|
|
199
|
+
the user to log back in to the service they just logged out from using a different username and password. Other
|
|
200
|
+
CAS server implemenations may use this 'destination' parameter in different ways.
|
|
201
|
+
|
|
202
|
+
==== Gatewayed (i.e. optional) authentication
|
|
203
|
+
|
|
204
|
+
"Gatewaying" essentially allows for optional CAS authentication. Users who already have a pre-existing CAS SSO session
|
|
205
|
+
will be automatically authenticated for the gatewayed service, while those who do not will be allowed to access the service
|
|
206
|
+
without authentication. This is useful for example when you want to show some additional private content on a homepage to
|
|
207
|
+
authenticated users, but also want anonymous users to be able to access the page without first logging in.
|
|
208
|
+
|
|
209
|
+
To allow users to access a page without authenticatin, simply use <tt>CASClient::Frameworks::Rails::GatewayFilter</tt>
|
|
210
|
+
in place of <tt>CASClient::Frameworks::Rails::Filter</tt> in your controller. For example, you may want to require
|
|
211
|
+
CAS authentication for all actions in a controller except the index action:
|
|
212
|
+
|
|
213
|
+
class ExampleController < ApplicationController
|
|
214
|
+
before_filter CASClient::Frameworks::Rails::GatewayFilter, :only => :index
|
|
215
|
+
before_filter CASClient::Frameworks::Rails::Filter, :except => :index
|
|
216
|
+
|
|
217
|
+
# ...
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
To provide a login URL for unauthenticated users:
|
|
221
|
+
|
|
222
|
+
<%= link_to("Login", CASClient::Frameworks::Rails::Filter.login_url(controller)) %>
|
|
223
|
+
|
|
224
|
+
==== How to act as a CAS proxy
|
|
225
|
+
|
|
226
|
+
CAS 2.0 has a built-in mechanism that allows a CAS-authenticated application to pass on its authentication to other applications.
|
|
227
|
+
An example where this is useful might be a portal site, where the user logs in to a central website and then gets forwarded to
|
|
228
|
+
various other sites that run independently of the portal system (but are always accessed via the portal). The exact mechanism
|
|
229
|
+
behind this is rather complicated so I won't go over it here. If you wish to learn more about CAS proxying, a great walkthrough
|
|
230
|
+
is available at http://www.ja-sig.org/wiki/display/CAS/Proxy+CAS+Walkthrough.
|
|
231
|
+
|
|
232
|
+
RubyCAS-Client fully supports proxying, so a CAS-protected Rails application can act as a CAS proxy.
|
|
233
|
+
|
|
234
|
+
Additionally, RubyCAS-Client comes with a controller that can act as a CAS proxy callback receiver. This is necessary because
|
|
235
|
+
when your application requests to act as a CAS proxy, the CAS server must contact your application to deposit the proxy-granting-ticket
|
|
236
|
+
(PGT). Note that in this case the CAS server CONTACTS YOU, rather than you contacting the CAS server (as in all other CAS operations).
|
|
237
|
+
|
|
238
|
+
Confused? Don't worry, you don't really have to understand this to use it. To enable your Rails app to act as a CAS proxy,
|
|
239
|
+
all you need to do is this:
|
|
240
|
+
|
|
241
|
+
In your <tt>config/environment.rb</tt>:
|
|
242
|
+
|
|
243
|
+
# enable detailed CAS logging for easier troubleshooting
|
|
244
|
+
cas_logger = CASClient::Logger.new(RAILS_ROOT+'/log/cas.log')
|
|
245
|
+
cas_logger.level = Logger::DEBUG
|
|
246
|
+
|
|
247
|
+
CASClient::Frameworks::Rails::Filter.configure(
|
|
248
|
+
:cas_base_url => "https://cas.example.foo/",
|
|
249
|
+
:proxy_retrieval_url => "https://cas-proxy-callback.example.foo/cas_proxy_callback/retrieve_pgt",
|
|
250
|
+
:proxy_callback_url => "https://cas-proxy-callback.example.foo/cas_proxy_callback/receive_pgt",
|
|
251
|
+
:logger => cas_logger
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
In <tt>config/routes.rb</tt> make sure that you have a route that will allow requests to /cas_proxy_callback/:action to be routed to the
|
|
255
|
+
CasProxyCallbackController. This should work as-is with the standard Rails routes setup, but if you have disabled the default
|
|
256
|
+
route, you should add the following:
|
|
257
|
+
|
|
258
|
+
map.cas_proxy_callback 'cas_proxy_callback/:action', :controller => 'cas_proxy_callback'
|
|
259
|
+
|
|
260
|
+
Now here's a big giant caveat: <b>your CAS callback application and your CAS proxy application must run on separate Rails servers</b>.
|
|
261
|
+
In other words, if you want a Rails app to act as a CAS ticket-granting proxy, the cas_proxy_callback controller
|
|
262
|
+
must run on a different server. This is because Rails does not properly support handling of concurrent requests. The CAS proxy mechanism
|
|
263
|
+
acts in such a way that if your proxy application and your callback controller were on the same server
|
|
264
|
+
you would end up with a deadlock (the CAS server would be waiting for its callback to be accepted by your Rails server,
|
|
265
|
+
but your Rails server wouldn't respond to the CAS server's callback until the CAS server responded back first).
|
|
266
|
+
|
|
267
|
+
The simplest workaround is this:
|
|
268
|
+
|
|
269
|
+
1. Create an empty rails app (i.e. something like <tt>rails cas_proxy_callback</tt>)
|
|
270
|
+
2. Make sure that you have the CAS plugin installed. If you installed it as a gem, you don't have to do anything since
|
|
271
|
+
it is already installed. If you want to install as a plugin, see the instructions in the "Installing" section above.
|
|
272
|
+
3. Make sure that the server is up and running, and configure your proxy_callback_url and proxy_retrieval_url to point
|
|
273
|
+
to the new server as described above (or rather, make Pound point to the new server, if that's how you're handling https).
|
|
274
|
+
|
|
275
|
+
That's it. The proxy_callback_controller doesn't require any additional configuration. It doesn't access the database
|
|
276
|
+
or anything of that sort.
|
|
277
|
+
|
|
278
|
+
Once your user logs in to CAS via your application, you can do the following to obtain a service ticket that can then be used
|
|
279
|
+
to authenticate another application:
|
|
280
|
+
|
|
281
|
+
service_uri = "http://some-other-application.example.foo"
|
|
282
|
+
proxy_granting_ticket = session[:cas_pgt]
|
|
283
|
+
proxy_ticket = CASClient::Frameworks::Rails::Filter.client.request_proxy_ticket(service_uri, proxy_granting_ticket)
|
|
284
|
+
|
|
285
|
+
<tt>proxy_ticket</tt> should now contain a valid proxy ticket. You can use it to authenticate other services by sending it together with
|
|
286
|
+
the service URI as parameters to your target application:
|
|
287
|
+
|
|
288
|
+
http://some-other-application.example.foo?service=#{CGI::escape(proxy_ticket.service)}&ticket=#{proxy_ticket.ticket}
|
|
289
|
+
|
|
290
|
+
This is of course assuming that http://some-other-application.example.foo is also protected by the CAS filter.
|
|
291
|
+
Note that you should always URI-encode your service parameter inside URIs!
|
|
292
|
+
|
|
293
|
+
Note that #request_proxy_ticket returns a CASClient::ProxyTicket object, which is why we need to call #ticket on it
|
|
294
|
+
to retrieve the actual service ticket string.
|
|
295
|
+
|
|
296
|
+
===== Additional proxying notes and caveats
|
|
297
|
+
|
|
298
|
+
<b>The proxy url must be an https address.</b> Otherwise CAS will refuse to communicate with it. This means that if you are using
|
|
299
|
+
the bundled cas_proxy_callback controller, you will have to host your application on an https-enabled server. This can be a bit
|
|
300
|
+
tricky with Rails. WEBrick's SSL support is difficult to configure, and Mongrel doesn't support SSL at all. One workaround is to
|
|
301
|
+
use a reverse proxy like Pound[http://www.apsis.ch/pound/], which will accept https connections and locally re-route them
|
|
302
|
+
to your Rails application. Also, note that <i>self-signed SSL certificates likely won't work</i>. You will probably need to use
|
|
303
|
+
a real certificate purchased from a trusted CA authority (there are ways around this, but good luck :)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
== SSL Support
|
|
307
|
+
|
|
308
|
+
Make sure you have the Ruby OpenSSL library installed. Otherwise you may get errors like:
|
|
309
|
+
|
|
310
|
+
no such file to load -- net/https
|
|
311
|
+
|
|
312
|
+
To install the library on an Debian/Ubuntu system:
|
|
313
|
+
|
|
314
|
+
sudo apt-get install libopenssl-ruby
|
|
315
|
+
|
|
316
|
+
For other platforms you'll have to figure it out yourself.
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
== License
|
|
321
|
+
|
|
322
|
+
This program is free software; you can redistribute it and/or modify
|
|
323
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
324
|
+
the Free Software Foundation; either version 2 of the License, or
|
|
325
|
+
(at your option) any later version.
|
|
326
|
+
|
|
327
|
+
This program is distributed in the hope that it will be useful,
|
|
328
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
329
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
330
|
+
GNU General Public License for more details.
|
|
331
|
+
|
|
332
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
333
|
+
along with this program (see the file called LICENSE); if not, write to the
|
|
334
|
+
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
data/Rakefile
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/clean'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
require 'rake/packagetask'
|
|
6
|
+
require 'rake/gempackagetask'
|
|
7
|
+
require 'rake/rdoctask'
|
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
|
9
|
+
require 'fileutils'
|
|
10
|
+
require 'hoe'
|
|
11
|
+
include FileUtils
|
|
12
|
+
require File.join(File.dirname(__FILE__), 'lib', 'casclient', 'version')
|
|
13
|
+
|
|
14
|
+
AUTHOR = ["Matt Zukowski", "Matt Walker"] # can also be an array of Authors
|
|
15
|
+
EMAIL = "matt at roughest dot net"
|
|
16
|
+
DESCRIPTION = "Client library for the Central Authentication Service (CAS) protocol."
|
|
17
|
+
GEM_NAME = "rubycas-client" # what ppl will type to install your gem
|
|
18
|
+
RUBYFORGE_PROJECT = "rubycas-client" # The unix name for your project
|
|
19
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
|
20
|
+
|
|
21
|
+
ENV['NODOT'] = '1'
|
|
22
|
+
|
|
23
|
+
NAME = "rubycas-client"
|
|
24
|
+
REV = nil
|
|
25
|
+
#REV = `svn info`[/Revision: (\d+)/, 1] rescue nil
|
|
26
|
+
VERS = ENV['VERSION'] || (CASClient::VERSION::STRING + (REV ? ".#{REV}" : ""))
|
|
27
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
|
28
|
+
RDOC_OPTS = ['--quiet', '--title', "rubycas-client documentation",
|
|
29
|
+
"--opname", "index.html",
|
|
30
|
+
"--line-numbers",
|
|
31
|
+
"--main", "README",
|
|
32
|
+
"--inline-source"]
|
|
33
|
+
|
|
34
|
+
class Hoe
|
|
35
|
+
def extra_deps
|
|
36
|
+
@extra_deps.reject { |x| Array(x).first == 'hoe' }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Generate all the Rake tasks
|
|
41
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
|
42
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
43
|
+
p.author = AUTHOR
|
|
44
|
+
p.description = DESCRIPTION
|
|
45
|
+
p.email = EMAIL
|
|
46
|
+
p.summary = DESCRIPTION
|
|
47
|
+
p.url = HOMEPATH
|
|
48
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
|
49
|
+
p.test_globs = ["test/**/*_test.rb"]
|
|
50
|
+
p.clean_globs = CLEAN #An array of file patterns to delete on clean.
|
|
51
|
+
|
|
52
|
+
# == Optional
|
|
53
|
+
#p.changes - A description of the release's latest changes.
|
|
54
|
+
#p.extra_deps - An array of rubygem dependencies.
|
|
55
|
+
#p.spec_extras - A hash of extra values to set in the gemspec.
|
|
56
|
+
p.extra_deps = ['activesupport']
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
desc 'Build and install rubycas-client'
|
|
60
|
+
task :install do
|
|
61
|
+
system "gem build rubycas-client.gemspec"
|
|
62
|
+
system "sudo gem install rubycas-client-#{VERS}.gem"
|
|
63
|
+
end
|
data/init.rb
ADDED
data/lib/casclient.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'cgi'
|
|
3
|
+
require 'net/https'
|
|
4
|
+
require 'rexml/document'
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
require 'active_support'
|
|
8
|
+
rescue LoadError
|
|
9
|
+
require 'rubygems'
|
|
10
|
+
require 'active_support'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
|
14
|
+
|
|
15
|
+
module CASClient
|
|
16
|
+
class CASException < Exception
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Customized logger for the client.
|
|
20
|
+
# This is useful if you're trying to do logging in Rails, since Rails'
|
|
21
|
+
# clean_logger.rb pretty much completely breaks the base Logger class.
|
|
22
|
+
class Logger < ::Logger
|
|
23
|
+
def initialize(logdev, shift_age = 0, shift_size = 1048576)
|
|
24
|
+
@default_formatter = Formatter.new
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def format_message(severity, datetime, progrname, msg)
|
|
29
|
+
(@formatter || @default_formatter).call(severity, datetime, progname, msg)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def break
|
|
33
|
+
self << $/
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class Formatter < ::Logger::Formatter
|
|
37
|
+
Format = "[%s#%d] %5s -- %s: %s\n"
|
|
38
|
+
|
|
39
|
+
def call(severity, time, progname, msg)
|
|
40
|
+
Format % [format_datetime(time), $$, severity, progname, msg2str(msg)]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Wraps a real Logger. If no real Logger is set, then this wrapper
|
|
46
|
+
# will quietly swallow any logging calls.
|
|
47
|
+
class LoggerWrapper
|
|
48
|
+
def initialize(real_logger=nil)
|
|
49
|
+
set_logger(real_logger)
|
|
50
|
+
end
|
|
51
|
+
# Assign the 'real' Logger instance that this dummy instance wraps around.
|
|
52
|
+
def set_real_logger(real_logger)
|
|
53
|
+
@real_logger = real_logger
|
|
54
|
+
end
|
|
55
|
+
# Log using the appropriate method if we have a logger
|
|
56
|
+
# if we dont' have a logger, gracefully ignore.
|
|
57
|
+
def method_missing(name, *args)
|
|
58
|
+
if @real_logger && @real_logger.respond_to?(name)
|
|
59
|
+
@real_logger.send(name, *args)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
require 'casclient/tickets'
|
|
66
|
+
require 'casclient/responses'
|
|
67
|
+
require 'casclient/client'
|
|
68
|
+
require 'casclient/version'
|
|
69
|
+
|
|
70
|
+
# Detect legacy configuration and show appropriate error message
|
|
71
|
+
module CAS
|
|
72
|
+
module Filter
|
|
73
|
+
class << self
|
|
74
|
+
def method_missing(method, *args)
|
|
75
|
+
$stderr.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
76
|
+
$stderr.puts
|
|
77
|
+
$stderr.puts "WARNING: Your RubyCAS-Client configuration is no longer valid!!"
|
|
78
|
+
$stderr.puts
|
|
79
|
+
$stderr.puts "For information on the new configuration format please see: "
|
|
80
|
+
$stderr.puts
|
|
81
|
+
$stderr.puts " http://rubycas-client.googlecode.com/svn/trunk/rubycas-client/README.txt"
|
|
82
|
+
$stderr.puts
|
|
83
|
+
$stderr.puts "After upgrading your configuration you should also clear your application's session store."
|
|
84
|
+
$stderr.puts
|
|
85
|
+
$stderr.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|