2011-11-29 2 views
4

업데이트 11/30/11 오류를 발견 한 코드 스 니펫에서 몇 가지 사항을 변경했습니다. 지금은 성공적으로 확실히 인증하고 있지만, ldap.search 통화 시도 후이 오류가 무엇입니까 : 윈도우 서버 2008 R2Active Directory에서 Rails 3.1 Active Record 데이터베이스로 사용자로드

원본 메시지에 레일 3.1.0와 루비 1.9.2를 사용

<OpenStruct code = 1, message="Operations Error"> 

저는 Ruby, 레일 및 프로그래밍의 새로운 브랜드입니다. AD와 별도로 사용자 목록을 유지하면서 Active Directory 서버에 인증해야하는 응용 프로그램이 있습니다.

net-ldap을 사용하여 연결을 설정하고 AD를 검색하여 사용자를로드하려고 시도하지만 각 시도가 실행될 때마다 결과가 0입니다.

필자가 본 샘플을 기반으로 작성한 것입니다.하지만 회사에 맞게 사용자 정의하면 작동하지 않습니다. 모든 아이디어/비평을 환영합니다.

감사합니다.

내 사용자 클래스 모델의 방법으로이 설정 한 :

class User < ActiveRecord::Base 
    attr_accessible :username, :name, :email, :team, :office, :points_attributes 
    validates_presence_of :username, :name, :email 
    validates_uniqueness_of :username, :email 
    has_one :points 
    accepts_nested_attributes_for :points 

    def self.import_all 
    # initialization stuff. set bind_dn, bind_pass, ldap_host, base_dn and filter 

    ldap = Net::LDAP.new(:host => "dc.mycompany.com", :port => 389) 
    if ldap.bind(:method => :simple, :username => "[email protected]", :password => "secret") 
    else 
    p ldap.get_operation_result 
    end 

    begin 
    # Build the list 
    filter = Net::LDAP::Filter.eq("displayName", "J*") 
    attrs = ["givenName", "sn", "physicalDeliveryOfficeName", "sAMAccountName"] 
    records = new_records = 0 
    ldap.search(:base => "DC=mycompany,DC=com", :attributes => attrs, :filter => filter, :return_result => false) do |entry| 
    name = entry.givenName.to_s.strip + " " + entry.sn.to_s.strip 
    username = entry.sAMAccountName.to_s.strip 
    email = entry.sAMAccountName.to_s.strip + "@mycompany.com" 
    office = entry.physicalDeliveryOfficeName.to_s.strip 
    user = User.find_or_initialize_by_username :name => name, :username => username, :email => email, :office => office 
    if user.new_record? 
     user.save 
     Points.find_or_create_by_user_id(user.id) 
     new_records = new_records + 1 
    else 
     user.touch 
    end 
    records = records + 1 
    end 
    p ldap.get_operation_result 

    logger.info("LDAP Import Complete: " + Time.now.to_s) 
    logger.info("Total Records Processed: " + records.to_s) 
    logger.info("New Records: " + new_records.to_s) 

    end 

    end 
end 
+0

어떤 버전의 ruby-net-ldap을 사용하고 있습니까? – Nick

+0

나는 gem net-ldap 0.2.2를 사용하고 있는데 이것은 분명히 ruby-net-ldap과 다릅니다. – jgifford78

답변

0

그것은 밝혀 내가지고있어 오류가 I가 존재하지 않는 찾고 있어요 일부 속성 때문이다 내가보고있는 트리 아래의 모든 사용자.

감사의 말을 전하는 사람 덕분에,하지만 나는 이러한 속성이없는 항목을 처리하는 방법을 찾아야한다고 생각합니다.

관련 문제