backend based authentication

I am new to Rails, so this might be a stupid question.
However, neither browsing the available online documentation nor googling
solved my problem.

I have a "legacy" database that is supposed to be accessed both by traditional
GUI programs (currently implemented in wxPython) and as well as a web app
(RoR based)

User authentication and role based authorization is now all handled by the
backend (Postgresql) and I want to keep it that way so that nobody in the GUI
app can accidentally access records that they are not supposed to access, and
so that I don't have to duplicate work in both GUI app and web app re
authentication.

1.) How do I (in RoR) log into a database backend as a specific user with a
given password per session? I guess there must be a model base class where I
implement this and then derive all further models from this one?

2.) How do I gracefully react to authentication errors coming from the
PostgreSQL backend in RoR?

(both so easy in Python+ wxPython which I am used to, but I have no idea how
to do it in RoR - I would be most grateful for any help)

Cheers,
Horst