Authentication vs. Authorization
Authentication - Who?
Authorization - Can?
What do I want?
(as a current_user
)
- Load collection of models
- Auth an action (
create
, blow!
, etc.)
- ... and do it fast!
- ... and be happy with the code
- ... and not
require 'rails'
CanCan is good
- Popular
- Plays nice with rails
- Fast to fetch records
CanCan is bad
- Ability for all classes loaded on each request (God object
ability.rb
)
- Need to have
current_ability
in all required places
- Hard to filter secret information on viewes
Heimdallr is good
- Modular
- Loads only required data (from
restrict
block)
- Uses Proxy object instead of original record
#<Heimdallr::Proxy::Record: #<User id: 42, name: "42th User">>
Heimdallr is bad
- 81 ★ and 8 forks
- Not so comfortable API
- Slow to instantiate much records (evaluates
restrict
block each time)
:trollface:
- No
bang!
methods
-
Unable to insert scopes into relations
-
Strange caching of permissions
(evaluator.rb#L153)
Compare CanCan and Heimdallr
Comparison results
Rehearsal ----------------------------------------------------------
CanCan: 0.200000 0.010000 0.210000 ( 0.209705)
Heimdallr: 0.470000 0.000000 0.470000 ( 0.500858)
Heimdallr (insecure): 0.210000 0.000000 0.210000 ( 0.220875)
------------------------------------------------- total: 0.890000sec
user system total real
CanCan: 0.200000 0.010000 0.210000 ( 0.207055)
Heimdallr: 0.450000 0.000000 0.450000 ( 0.456898)
Heimdallr (insecure): 0.190000 0.000000 0.190000 ( 0.235545)
Authority
- Rails-dependant
- ORM-neutral (use own scopes like
available_for(current_user)
)
- Modular
Declarative Authorization
Declarative Authorization
- 5 years old gem
- Looking like CanCan to me
- Uses roles to determine user permissions
Still no perfect gems for authorization.