söndag, juli 16, 2006

CAS Rails filter

Yesterday I released a Rails filter for doing authentication with CAS. This is really neat, but it's the Rails plugins that make it so neat, since you just have to install the plugin, add three configuration parameters and everything will just work out of the box with all your controllers protected by authentication.

During development it's often practical to not do real authentication, but rather just get a username back as if you'd actually been authenticated already. This can be easily accomplished in three ways with the filter, by a configuration options:

CAS::Filter.fake = "testuid"

which returns the string provided as a username

CAS::Filter.fake = :param

which takes the value of params[:username] and returns this as the authenticated user, and lastly

CAS::Filter.fake = lambda { |controller| ['testuser1','testuser2','testuser3'][rand(3)] }

which invokes the proc every time the filter is called, and uses the string returned as username.

Anyway, authentication is just one of those things that you don't want to think about. It should just be there. And now it is:

script/plugin install http://svn.ki.se/rails/plugins/cas_auth

Enjoy.

Inga kommentarer: