|
HowToConfigure
IntroductionThe following is a detailed walkthrough explaining the entire process of setting up and running RubyCAS-Server. A quick guide for configuring the Rails and PHP CAS clients is also provided. This guide assumes that you are doing all of this on a Linux system. Of course RubyCAS-Server should work fine on other platforms (Windows, Mac OS X, BSD, etc.), but you will have to translate a few things for yourself (file system paths, for example). Configuring RubyCAS-ServerFirst, download and install RubyCAS-Server, as described on the RubyCAS-Server project home page. Once installed, you should find that you can launch the server by typing rubycas-server on the command line. The first time you run rubycas-server, a default configuration file will be generated for you, probably under /etc/rubycas-server/config.yml. The server will then exit. You will have edit the sample configuration file as described below, and then launch rubycas-server again. RubyCAS-Server's config.yml file is formatted using YAML, a simple, text-based format easily readable by both humans and machines. YAML formatting is mostly self-explanatory, but one thing to be careful about is indentation. Make sure that you use spaces instead of tabs, as YAML is sensitive to this. You can leave most of the settings in config.yml at their defaults, but a few things need to be changed:
Running RubyCAS-ServerNow that you have RubyCAS-Server configured, you should be able to start it up. Since by default RubyCAS-Server writes to some system directories (for example logging to /var/log/casserver.log), you will have to launch it as root. Try sudo rubycas-server in your shell prompt. You should get output roughly like this: *** Starting RubyCAS-Server 0.4.2 using codebase at /usr/lib/ruby/gems/1.8/gems/rubycas-server-0.4.2/lib
[2007-08-03 13:14:54] INFO WEBrick 1.3.1
[2007-08-03 13:14:54] INFO ruby 1.8.5 (2006-08-25) [i586-linux]
[2007-08-03 13:14:54] INFO
Certificate:
Data:
Version: 3 (0x2)
... lots of other SSL certificate info ...
** CASServer is running at https://<your hostname>:443/cas and logging to '/var/log/casserver.log'As the output states, further logging is done to /var/log/casserver.log. You can monitor what's going on using tail: tail -f /var/log/casserver.log. To make sure that everything is working, point your web browser to https://localhost/cas. You should see the default CAS login page. Configuring CAS ClientsWe've got our basic CAS server up and running, so it's time to configure our websites to use CAS for authentication. We will assume that your CAS server is accessible at https://login.example.com/cas. RailsFor Rails, we will use RubyCAS-Client. This works as a standard Rails controller filter. Detailed installation and configuration instructions are available at http://rubycas-client.rubyforge.org/files/README_txt.html, but very roughly speaking, you should do this:
./script/plugin install http://rubycas-client.googlecode.com/svn/trunk/rubycas-client CASClient::Frameworks::Rails::Filter.configure(:cas_base_url => "https://login.example.com/") class ApplicationController < ActionController::Base before_filter CASClient::Frameworks::Rails::Filter # ... end You should now find that the Rails application is CAS protected. Visiting any of its pages should automatically redirect to our CAS server where the user must enter a valid username and password. Once authenticated, the user's username is available within the Rails app in the controller session as session[:casfilteruser]. To logout, your Rails app should delete the :casfilteruser session key and redirect to the CAS server's logout URI: session.delete(:casfilteruser) redirect_to(CASClient::Frameworks::Rails::Filter.client.logout_url(request.referer)) and return PHPTo protect our PHP application, we will use the phpCAS library. Download and installation instructions are available at http://www.ja-sig.org/wiki/display/CASC/phpCAS+installation+guide+and+requirements. Once the library has been installed, you should create a file that will be included at the top of every CAS-protected page. Lets call it cas_filter.inc.php, and paste into it the following code: <?php
if (!$_SESSION['casfilteruser']) :
session_start();
phpCAS::setDebug('cas.log');
phpCAS::client(CAS_VERSION_2_0,'login.example.com',443,'cas');
if ($_REQUEST['service']) :
phpCAS::setFixedServiceURL(urlencode($_REQUEST'service']));
endif;
phpCAS::forceAuthentication();
// at this step, the user has been authenticated by the CAS server
// and the user's login name can be read with phpCAS::getUser().
// logout if desired
if (isset($_REQUEST['logout'])) {
phpCAS::logout();
}
$_SESSION['casfilteruser'] = phpCAS::getUser();
endif;
?>Now, we'll need to require this at the top of our CAS-protected pages: <?php require('cas_filter.inc.php') ?>However, for this to work, we have to make sure that we have a session started BEFORE the CAS authentication takes place. You should make sure then that the session is started in some code above the cas_fitler require using session_start() or that you have PHP configured to auto-start sessions with every request. Once authenticated, as with the Rails filter, the user's username should be available at $SESSION['casfilteruser']. To log out, simply go to any protected page with &logout added to the URI. |
I tried to configure rubycas-server with SQLRestAuth authenticator. When I tried to log in, I got NameError? undefined local variable or method `encryption_salt' for #<CASServer::Authenticators::SQLRestAuth::CASUser>
It seems that rubycas-server uses encrypt method which is defined in sql_encrypted.rb, not in sql_rest_auth.rb.
Any ideas?
Having same problem!
If you got the following error when logging into the system:
where 1234567 appears under your config.yml file:
authenticator: class: CASServer::Authenticators::ActiveDirectoryLDAP ldap: host: myrubycas.local port: 389 base: dc=myrubycas,dc=local filter: (objectClass=person) auth_user: DomainAdmin auth_password: 1234567Note: The password is revealed to all users!!! Dangerous. To fix, set the password in quotes (')
This appears to be a bug. Also, I've got users whose password start with space. Apparently, the space is being filtered! Bad implementation!