tobyclemson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-04 21:37 UTC
Modifying the restful_authentication plugin / Classes creating instances of themselves.
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Stephen Bannasch
2007-Aug-04 23:52 UTC
Re: Modifying the restful_authentication plugin / Classes creating instances of themselves.
>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 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Toby Clemson
2007-Aug-05 09:25 UTC
Re: Modifying the restful_authentication plugin / Classes creating instances of themselves.
That''s great thanks. My question was really vague and you still managed to answer it perfectly! On Aug 5, 12:52 am, Stephen Bannasch <stephen.banna...-BPmR3cMxM6/dtAWm4Da02A@public.gmane.org> wrote:> >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 > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---