#!/usr/bin/perl
use Net::LDAP;
use Data::Dumper;
my $ldap = Net::LDAP->new( 'sub.ad.mydomain.org' );
# bind to a directory with dn and password
my $mesg = $ldap->bind(
'myusername@ad.mydomain.com',
password => 'mypassword'
);
$mesg = $ldap->search(
base => "DC=sub,DC=ad,DC=mydomain,DC=org",
filter => "(sAMAccountName=myusername)",
);
die Dumper $mesg->entries;
####
ldapsearch -H ldap://sub.ad.mydomain.org \
-b dc=sub,dc=ad,dc=mydomain,dc=org \
-D myusername@ad.subdomain.org \
-w mypassword \
'(sAMAccountName=myusername)'
##
##
[debug] Body Parameters are:
.-------------+-------------.
| Parameter | Value |
+-------------+-------------+
| password | mypassword |
| username | myusername |
'-------------+-------------'
[debug] Path is "login"
[debug] Unable to locate user matching user info provided
##
##
name MyApp
# Config for Store::LDAP
default_realm ldap
class Password
password_field password
password_type self_check
class LDAP
ldap_server ldap://sub.ad.mydomain.org
timeout 30
onerror warn
binddn myusername@ad.mydomain.org
bindpw mypassword
start_tls 0
verify none
user_basedn DC=sub,DC=ad,DC=mydomain,DC=org
user_filter (sAMAccountName=%s)
user_scope one
user_field sAMAccountName # also tried samaccountname
deref always
use_roles 0
##
##
sub login : Global {
my ( $self, $c ) = @_;
# Get the username and password from form
my $username = $c->request->params->{username};
my $password = $c->request->params->{password};
if ( $username and $password ) {
if ($c->authenticate({username => $username, password => $password })) {
$c->res->body("Welcome " . $c->user->username . "!");
} else {
$c->stash(error_msg => "Bad username or password.");
}
} else {
# Set an error message
$c->stash(error_msg => "Empty username or password.");
}
}