2011-12-15 3 views
0

간단한 웹 기반 디렉토리 탐색/관리 응용 프로그램을 구축하려고합니다.영구 LDAP 인증 세션

응용 프로그램 요구 사항 :

  • 는 Active Directory (또는 다른 디렉터리 서비스) 도메인 사용자 액세스 이 웹 응용 프로그램과 같은 도메인 사용자/암호 자격 증명으로 로그인합니다.
  • 그런 다음 사용자가 등등/편집 항목, 편집 항목의 속성을 만들고,

을 디렉토리 트리를 탐색 할 수 있습니다 나는 펄 인터넷을 사용하고 있습니다 : LDAP를 LDAP 작업을 위해, 같이 :

#!/usr/bin/perl -wT 

use Net::LDAP; 
use CGI qw(:standard); 
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 

my $ssl = 1; 
my $srv = '192.168.56.110'; 
my $uri = $ssl ? 'ldaps://' : 'ldap://'; 

my $c = Net::LDAP->new($uri . $srv) or 
    die "Unable to connect to server: [email protected]\n"; 

# !!! This is a temporary workaround !!! 
my $binddn = "cn=Administrator,cn=users,dc=example,dc=com"; 
my $passwd = "password"; 

my $mesg = $c->bind($binddn, password => $passwd); 
die 'Unable to bind: ' . $mesg->error . "\n" if $mesg->code; 

# DN to be deleted 
my $dn = param('DN'); 

$mesg = $c->delete($dn); 
die 'Error in delete: '. $mesg->error() ."\n" if $mesg->code(); 

$c->unbind; 

전에서와 같이 HTML 양식이 CGI 스크립트를 호출 할 수

<form action="/cgi-bin/del.cgi" method="post"> 
<br>Peter Parker 
<input type="radio" name="DN" 
    value="cn=peter parker,cn=users,dc=example,dc=com"> 
<br>Clark Kent 
<input type="radio" name="DN" 
    value="cn=clark kent,cn=users,dc=example,dc=com"> 
<br> 
<input type="submit" value="Delete User"> 
</form> 

이 코드의 문제는 LDAP 작업이 ADMI을 사용하는 것입니다 웹 응용 프로그램을 실행하는 사용자의 자격 증명이 아닌 매번 사용자에게 자격 증명을 요청할 수 없기 때문에이 해결 방법을 사용하고 있습니다. 사용자 인증을 유지하는 방법을 모르겠습니다.

내 웹 응용 프로그램 그는의 자격 증명을 묻는와 같이 디렉토리 서비스에 바인드 요청을 발행, LDAP를 통해 사용자를 인증

: 그 후

... 
# read user supplied credentials 
my $user_id = param('user_id'); 
my $password = param('password'); 

# now find the DN of user_id in directory 
my $ssl = 1; 
my $srv = '192.168.56.110'; 
my $uri = $ssl ? 'ldaps://' : 'ldap://'; 

my $c = Net::LDAP->new($uri . $srv) or 
    die "Unable to connect to server: [email protected]"; 

# admin credentials are needed here to find the user DN 
my $rootdn = "cn=Administrator,cn=users,dc=example,dc=com"; 
my $rootpw = "secret"; 

my $mesg = $c->bind($rootdn, password => $rootpw); 
die "Unable to bind: ". $mesg->error if $mesg->code; 

$mesg = $c->search(
    base => 'dc=example,dc=com', 
    scope => 'sub', 
    filter => "(&(objectClass=user)(sAMAccountName=$user_id))", 
    attrs => ['sAMAccountName'], 
); 
die "Bad search: ". $mesg->error() if $mesg->code(); 

my ($entry) = $mesg->entries; 
die "User not found: $user_id\n" unless $entry; 

my $dn = $entry->dn; 

# User DN found.. now check the credentials 
$mesg = $c->bind($dn, password => $password); 
die "Unable to bind: ". $mesg->error if $mesg->code; 

$c->unbind(); 

# credentials validated! 
print header, start_html('Welcome!'), h1('Hello, YOU!'), end_html; 

이 쿠키는 웹을 시작하는 사용자의 브라우저로 전송됩니다 세션. 필자는 필요할 때마다 사용자 자격 증명을 데이터베이스에 보관 한 다음 del.cgi (및 기타 유사한 스크립트)에 전달할 수 있지만 좋은 보안 관행은 아니라고 생각합니다.

웹 세션이 활성화되어있는 동안 영구적 인 LDAP 인증 세션을 유지하려면 어떻게해야합니까?

답변

0

세션이 없습니다. LDAP 클라이언트가 디렉토리 서버에 연결하면 연결은 인증되지 않습니다. 바인드 요청은 성공한 경우 연결의 권한 부여 상태를 설정합니다. 연결은 다음 바인드 요청, 클라이언트 연결 끊기 또는 서버 연결 해제 때까지 해당 권한 부여 상태로 유지됩니다. 로컬 설정에 따라 연결 유지 또는 유사한 연결을 무기한 열어 둘 수도 있습니다. 또는 클라이언트가 다른 바인드 요청을 주기적으로 전송할 수 있습니다. 현대적이고 전문적인 디렉토리 서버는 유휴 클라이언트의 연결을 끊거나 일정 시간이 경과하거나 설정된 LDAP 작업 수가 전송 된 후에 클라이언트의 연결을 끊을 수 있습니다. 네트워크 관리자는 자체적 인 이유로 영구 연결을 허용하지 않을 수 있습니다.

  • LDAP 클라이언트는 LDAP 요청 후 응답 제어를 확인해야합니다. 응답 제어를 확인하지 않으면 클라이언트가 서버의 중요 정보를 누락하게됩니다.
  • LDAP 클라이언트는 서버가 확장 된 결과 형태로 요청하지 않은 알림을 보낼 수 있음을 알아야합니다. 원하지 않는 통지를 처리하지 않으면 잘못 구성된 LDAP 클라이언트가 발생할 수 있습니다. 대부분의 알림은 연결 해제 알림입니다. 즉, 서버가 어떤 이유로 클라이언트의 연결을 끊는 것입니다.

자세한 내용은 "LDAP: programming Practices"을 참조하십시오.

호기심 때문에 왜 그런 코드를 작성합니까? Apache Directory Studio는 훌륭한 LDAP 클라이언트입니다.