5

I have a PostgreSQL database that I access from various locations, and would like to add an interface with Ruby on Rails 3. For authentication I need to login users with the same credentials used to create them directly in the database; is there a way to make Rails connect to the database each time with different username/password, based on the current user? Thanks for any hints!

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Takhion
  • 2,706
  • 24
  • 30
  • Why would you want to do this? – ybakos Apr 01 '12 at 22:43
  • 1
    @ybakos to have consistency across the system and because inside the database there is a complex setup of triggers/functions that rely on users roles and permissions – Takhion Apr 01 '12 at 22:49

1 Answers1

1

Yes. Use a custom authentication on devise that makes a query to the underlying postgresql database.

See:

Custom authentication strategy for devise

I would certainly add some kind of filter to reduce the list of users that can authenticate this way.

Community
  • 1
  • 1
Nicolas Modrzyk
  • 13,961
  • 2
  • 36
  • 40
  • That looks like the way to do it! I'll check it out as soon as possible :) – Takhion Apr 01 '12 at 22:47
  • 1
    But how does any of this change which (PostgreSQL) user is used to establish the connection to the database? Sure, you can authenticate the users using any mechanism you like but that doesn't alter the user/role attached to the database connection/session. – mu is too short Apr 01 '12 at 23:24