Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 authorization gem [closed]

I am looking an authorization gem for rails 4. Before I used cancan, but it looks outdated nowadays...

I found the_role here https://github.com/the-teacher/the_role It is nearly what I want, but has a few annoying issues. Maybe similar gems exist? I need roles, store roles in database and association actions with rules. It wound be great if gem cooperate with bootstrap.

P.S. For authentication I use devise.

like image 285
mystdeim Avatar asked Nov 30 '13 10:11

mystdeim


People also ask

What are the different types of authentication and authorization in rails?

In this tutorial, I will show you how simple it is to authenticate and authorizate your application using the popular rails gems: Devise, CanCanCan, and Rolify. What is authentication and authorization? Authentication is a confirmation of user identity, while authorization determines whether you can access a particular resource. What is Devise?

What are the best Ruby on rails gems to use?

Devise. Devise is most probably the most commonly used Gem when using Ruby on Rails. It provides an easy-to-use authentication solution for your Rails application which will allow you to get login, registration, forget password, account locks and much more account-related features by simply using this Gem.

What is the Ruby on Rails framework?

The Ruby on Rails framework is an extremely powerful tool for developing web applications. It comes with plenty of built-in features that help accelerate the development of your web application such as intelligent routing and an object-relation mapper, all using an MVC pattern.

Where are all permissions defined in rails?

All permissions are defined in a single location (the Ability class). Step 1. Create a new Rails application I used 4.2.6 version of Rails and SQLite as a database. Let’s skip a test and create a new Rails application. Step 2. Add Bootstrap and styles


3 Answers

You should look at the bigger picture even outside Ruby and consider authorization model. The traditional prevalent model is role-based access control (RBAC) and this is what most frameworks and - in Ruby - most gems implement.

But if you have more advanced scenarios you want to consider attribute-based access control and XACML, the eXtensible Access Control Markup Language.

With XACML, you can implement context-aware authorization that is policy-based. For instance you can write rules such as:

  • managers can edit documents they own
  • doctors can view the medical record of patients they are assigned to

And so on...

I am not aware of any Ruby gem to apply XACML to your Ruby projects but the nature of XACML is such that you can easily implement your own authorization agents (enforcement points). I've written some in PHP, Java, .NET, and Perl.

You'll need an authorization engine. There are several open-source and vendor solutions out there such as SunXACML and Axiomatics.

Here are some interesting resources:

  • NIST RBAC - the official definition of the RBAC Model
  • NIST ABAC
  • OASIS XACML
like image 109
David Brossard Avatar answered Nov 26 '22 05:11

David Brossard


CanCanCan

CanCan was a popular gem for authorization developed by Ryan Bates (best known for RailsCasts) and abandoned prior to the release of Rails 4.0. Due to its popularity, the community-based CanCanCan project maintains an updated version of CanCan. CanCan provides a DSL (domain-specific language) that isolates all authorization logic in a single Ability class.

Pundit

The Pundit gem is gaining in popularity for Rails authorization. Pundit is an authorization system that uses simple Ruby objects for access rules. Pundit uses a folder named app/policies/ containing plain Ruby objects that implement access rules.

CanCanCan or Pundit or ?

As an application grows in complexity, the CanCan Ability class can grow unwieldy. Also, every authorization request requires evaluation of the full CanCan Ability class, adding performance overhead. Pundit also offers the advantage of segregating access rules into a central location, keeping controllers skinny. Pundit policy objects are lightweight, adding authorization logic without as much overhead as CanCan.

Simple Role-Based Authorization

With Rails 4.1, you can implement role-based authorization using Active Record Enum. You can use CanCanCan or Pundit to keep controllers skinny if your access rules are complex but for simple requirements, you may not need CanCanCan or Pundit.

I've written an article on Rails Authorization that goes into more detail, comparing CanCanCan and Pundit and simple role-based authorization.

like image 28
Daniel Kehoe Avatar answered Nov 26 '22 05:11

Daniel Kehoe


Cancancan is the new version of can can:

https://github.com/CanCanCommunity/cancancan

like image 29
Mosselman Avatar answered Nov 26 '22 06:11

Mosselman