# Modifying the restful\_authentication plugin / Classes creati

**URL:** <https://www.ruby-forum.com/t/modifying-the-restful-authentication-plugin-classes-creati/111282>\
**Category:** Rails\
**Created:** [August 4, 2007, 11:38pm UTC](https://www.ruby-forum.com/t/modifying-the-restful-authentication-plugin-classes-creati/111282 "2007-08-04T23:38:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 4, 2007, 11:38pm UTC](https://www.ruby-forum.com/t/modifying-the-restful-authentication-plugin-classes-creati/111282/1 "2007-08-04T23:38:04Z")

</div>

Hi,

I’m trying to modify the restful\_authentication plugin so that it  
first authenticates against LDAP (Active Directory), if successful, it  
tries to find a matching user with the same username in the database,  
through a model ‘user’. If it finds a user, it updates a last\_login  
attribute; if it doesn’t find one, it creates one. The “remember me”  
functionality is also incorporated.

I have incorporated these changes into the sessions controller and  
that is all working fine but I don’t know how to incorporate them into  
the authenticated\_system module. Basically the authenticated\_system.

I suppose my question really is: Is it okay for a model class to  
create an instance of itself in a class method? As this is the only  
way I can think of keeping the http authentication that is offered by  
restful\_authentication.

Thanks,  
Toby

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 5, 2007, 1:55am UTC](https://www.ruby-forum.com/t/modifying-the-restful-authentication-plugin-classes-creati/111282/2 "2007-08-05T01:55:12Z")

</div>

> Hi,
> 
> I’m trying to modify the restful\_authentication plugin so that it  
> first authenticates against LDAP (Active Directory), if successful, it  
> tries to find a matching user with the same username in the database,  
> through a model ‘user’. If it finds a user, it updates a last\_login  
> attribute; if it doesn’t find one, it creates one. The “remember me”  
> functionality is also incorporated.

I do something similar and didn’t have to change  
lib/authenticated\_system.rb.

I first check an external database that has authentication information.

If authentication is successful and this user does not already exist  
locally I copy the authentication tokens and the rest of the user  
attributes I am interested in to my local user model.

If I can’t connect to the external database I authenticate to my local  
User model.

This is all done with modifications to the User model. You can see the  
code here:

[svn.concord.org/svn/teemss2/branches/teemss2diy-plus-sail/app/models/user.rb](http://svn.concord.org/svn/teemss2/branches/teemss2diy-plus-sail/app/models/user.rb)

Look at the code that starts with this method:

# Authenticates a user by their login name and unencrypted password.

Returns the user or nil.  
def self.authenticate(identifier, password)  
user = User.remote\_authenticate(identifier, password)  
user || local\_authenticate(identifier, password)  
end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 5, 2007, 11:25am UTC](https://www.ruby-forum.com/t/modifying-the-restful-authentication-plugin-classes-creati/111282/3 "2007-08-05T11:25:42Z")

</div>

That’s great thanks. My question was really vague and you still  
managed to answer it perfectly!

On Aug 5, 12:52 am, Stephen B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
