views:

407

answers:

1

Hello.

I was wondering how other people implemented this scenario. I have an internal rails app ( inventory management, label printing, shipping,etc). I'm rewriting security on the system, cause the old way got to cumbersome to maintain ( users table, passwords, roles) - I used restful_authentication and roles. It was implemented about 3 years ago. I already implemented AuthLogic with ruby-ldap-net to authenticate users ( actually that was surprisingly easy, compared to how I struggled with other frameworks/languages before). Next step is roles. I already have groups defined in Active Directory - so I don't want to run a separate roles system in my rails app, I just want to reuse Active Directory groups - since that part of the system is already maintained for other purposes ( shared drives, backups, pc access, etc)

So I was wondering if others had experience implementing permissions/roles in a rails app based on groups in Active Directory or LDAP. Also the roles requirements are pretty complex.

Here is an example:

For instance I have users that belong to the supervisors group in AD and to inventory dept, so I was that user to be able to run "advanced" tasks in invetory - adjust qty, run reports, however other "supervisors" from other departmanets, shouldn't be able to do this, also Top Management - should be able to use those reports (regardless weather they belong to the invetory or not), but not Middle Management, unless they are in inventory group. Admins of the system (Domain Admins) should have unrestricted access to the system , except for HR & Finances part unless they are in HR ( like you don't want all system admins (except for one authorized one) to see personal info of other employees).

I looked at acl9, cancan, aegis. I was wondering if there are any advantaged/cons to using one versus the other for this particular use of system access based on AD. Suggest other systems if you had good experience.

Thank you!!!

+2  A: 

ActiveLDAP (Documentation, Google Code) has some of the features you're looking for, specifically:

  • You can map LDAP objects (Object Class instances) to objects in a Rails application. The API doesn't mirror ActiveRecord exactly, but it's pretty easy to understand and learn.
  • It's obviously not possible to join, etc. across LDAP and Relational Databases, but you could write some mildly clever code to make composite data easily accessible from either the ActiveLDAP object or the ActiveRecord object.
  • ActiveLDAP also provides methods to write to LDAP which allows you to manage your users and roles in LDAP from rails, eliminating the requirement to manage a user table in the database, however, a user database table would likely still be necessary to store application specific data about a user.
  • Additionally, you could integrate AuthLogic with ActiveLDAP. Here's one attempt I found of just that: LDAP Pass-through Authentication with Authlogic and ActiveLdap
  • You could then use Declarative Authorization (Railscast, Github, Website) to handle your roles and authorization.
Patrick Klingemann
Patrick, thank you for a reply, but let me clarify what I was looking for. As I mentioned I already got the authentication part - worked out with authlogic, and ruby-ldap-net. It's the authorization part that interests me, I've used a bunch of gems such as acl9 and declarative authorization, I just wanted to see if anyone has done anything like that - mapping AD / LDAP groups to Roles using any authorization gem - and what problems they ran into.
Nick Gorbikoff
Nick, what I was getting at with my response is that ActiveLDAP will allow you to map roles and users from LDAP to objects in Ruby and you can use Declarative Authorization to handle the actual authorization portion of your application based on role(s) for each user. Without knowing the structure of your LDAP instance or the specifics of your authorization scheme, it's difficult to go into more detail about the architecture.
Patrick Klingemann