2012-03-01 2 views
0

난 그냥 루비 온 레일즈로 개발을 시작하고 나는 사용자에게 역할 및 역할에 대한 권한을 연결하는 관리자를 가능하게하는 동적 인증 플러그인을 찾고 있어요.레일 동적 인증 인터페이스

나는이 주제를 대상으로 railscasts.org에서 stackoverflow 및 일부 포럼과 일부 포드 캐스트에서 일부 게시물을 발견했지만 모두 acl9, declarative_authorization, Aegis, restful acl 또는 인증이 아닌 Authlogic을 참조하지만 인증 플러그인. 다른 것들은 필요한 기능을 제공하지 않습니다. 는 사용자 역할을 다스리 다에 레일에 루비를 사용하여 웹 인터페이스를 설정 할 수 있다면

그래서 누군가가 나에게 말해 줄 수?

그래서 지금 내가 folowing 마이그레이션을 사용하여 내 데이터베이스를 마이그레이션.

class AddRolesAndRightsTables < ActiveRecord::Migration 
    def self.up 
    create_table :roles_users do |t| 
     t.integer :role_id 
     t.integer :user_id 
    end 

    create_table :roles do |t| 
     t.string :name 
    end 

    create_table :rights_roles do |t| 
     t.integer :right_id 
     t.integer :role_id 
    end 

    create_table :rights do |t| 
     t.string :name 
     t.string :controller 
     t.string :action 
    end 
    end 

    def self.down 
    drop_table :roles_users 
    drop_table :roles 
    drop_table :rights_roles 
    drop_table :rights 
    end 
end 

그리고 일부보기 및 컨트롤러 동작 외에도 다음 작업을 ApplicationController에 추가했습니다.

def check_authorization 
    user = User.find(session[:user]) 
    unless user.roles.detect do |role| 
    role.rights.select do |right| 
     right.action == action_name && right.controller == self.class.controller_path 
    end 
    end 

    redirect_back_or user 
    flash[:notice] = "You are not authorized to view the page you requested." 
    return false 
end 

Right.synchronize_with_controllers (Wolfman-Blog의 블로그 포스트를 참조)를 실행, 나는 다음과 같은 오류가 발생합니다.

syntax error, unexpected $end, expecting kEND (line 17 in application_controller) 

답변

2

나는 Ryan Bate의 cancan을 제안 할 것이다. 그것이 작동하는 방법을 이해하는 데는 어느 정도 시간이 걸렸지 만, 배워야 할 가치가 있습니다. 내 전체 프로그램에서

, 나는 그것을 마무리하기 위해 내 모든 컨트롤러에 대한 간단한 load_and_authorize_resource를 사용하고 여기에 여분의 비트를 추가 할 수 있어요.

authenticationauthorzation 사이에는 혼란이 없기를 바랍니다. 신속 관리자 인터페이스를 스캐 폴딩 할 경우에, 나는 액티브 관리을 제안한다.

그렇지 않으면, 그것은

업데이트) = cancannamespace 관리자 컨트롤러를 사용하는 것이 아마 더 유연

당신은 아마 역할을 만들고 할당하는 캉캉을 기반으로 간단한 역할 기반 권한 인터페이스를 얻으려면 그들에게 권한.

User belongs_to Role 

Role has_many Users 
Role has_and_belongs_to_many Permissions 

Permissions has_and_belongs_to_many Roles 

Permission 레코드는 모델 및 당신이 그것을 할 수있는 편안하고 Action입니다을 정의합니다.

역할을 정의 할 필요가 있지만 권한이 정적 인 경우 cancan의 Ability.rb에 쓰기 만하고 Permission 모델을 삭제하면됩니다.

내가 사용 권한을 기반으로 모델을 구현 할 필요가 없었어요 때문에 나는 당신에게 정확한 코드를 제공 할 수 없습니다 죄송합니다.

캉캉 Railscast http://railscasts.com/episodes/192-authorization-with-cancan

또 다른 좋은 캉캉 튜토리얼 DB에 http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/

능력 : 캉캉 https://github.com/ryanb/cancan/wiki/Abilities-in-Database

+0

그래서 관리자가 수 있도록 인터페이스를 프로그래밍 할 수 있습니다 새로운 역할을 만들고 권한을 할당 할 수 있습니다. 코드를 변경하지 않으셨습니까? – Phidelux

+0

예. 캔칸 (Cancan) 및 다른 대부분의 승인 보석은 귀하가 허용 한도를 구현하는 방법에 간섭하지 않을 것입니다. 아픈 짧은 스 니펫 n 개의 링크로 내 대답을 업데이 트하십시오. –

+0

Avedo, 대답은 당신에게 받아 들여지지 않습니까? –