当前位置:
首页 > 技术 > ldap模拟数据及ldap数据格式说明

ldap模拟数据及ldap数据格式说明

ldap模拟数据及ldap数据格式说明 ldap模拟数据及ldap数据格式说明 ldap模拟数据及ldap数据格式说明

ldap数据表点击我:ldif

# cat base.ldif
#objectClass的选择将影响到属性,如organization类其属性有:userPassword、searchGuide、seeAlso、businessCategory等等
#objectClass属性可见\OpenLDAP\schema\nis.schema文件及\OpenLDAP\schema\core.schema文件

#root
dn: dc=Administrator,dc=company 
objectClass: top
objectClass: dcObject
objectClass: organization
dc: Administrator
o: Administrator Company

#此处为分组People及Group, People用于分配角色 / Group用于管理组
dn: ou=People,dc=Administrator,dc=company
ou: People #organizationalUnitName别名ou, 单位(部门)名称
objectClass: top
objectClass: organizationalUnit

dn: ou=Group,dc=Administrator,dc=company
ou: Group
objectClass: top
objectClass: organizationalUnit

#此处为组信息
dn: cn=Manager,ou=Group,dc=Administrator,dc=company
objectClass: top
objectClass: posixGroup
cn: Manager #commonName, 当前组名
gidNumber: 1000 #当前组id
description: 0 #为零时默认为所有权限

dn: cn=Marketing,ou=Group,dc=Administrator,dc=company
objectClass: top
objectClass: posixGroup
cn: Marketing
gidNumber: 1001
description: 1,8 #菜单相应栏目id

dn: cn=Service,ou=Group,dc=Administrator,dc=company
objectClass: top
objectClass: posixGroup
cn: Service
gidNumber: 1002
description: 1,2

dn: cn=Support,ou=Group,dc=Administrator,dc=company
objectClass: top
objectClass: posixGroup
cn: Support
gidNumber: 1003
description: 1,2,8

dn: cn=Technology,ou=Group,dc=Administrator,dc=company
objectClass: top
objectClass: posixGroup
cn: Technology
gidNumber: 1004
description: 1,2,3,5,8

dn: cn=Operation,ou=Group,dc=Administrator,dc=company
objectClass: top
objectClass: posixGroup
cn: Operation
gidNumber: 1005
description: 1,2,3,5,6

#此处为用户信息
dn: uid=Rainyin,ou=People,dc=Administrator,dc=company
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 1 #当前用户id
uid: Rainyin #当前账号
userPassword: {MD5}4QrcOUm6Wau+VuBX8g+IPg==
gidNumber: 1000 #关联组id
gecos: Cale Hsieh #用户名
description:  #提升权限
homeDirectory: /home/Rainyin #分配的目录

dn: uid=Kyle,ou=People,dc=Administrator,dc=company
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 2
uid: Kyle
userPassword: {MD5}4QrcOUm6Wau+VuBX8g+IPg==
gidNumber: 1001
gecos: Kyle Done
description: 0 #admin权限
homeDirectory: /home/Kyle

dn: uid=PeteMinsky,ou=People,dc=Administrator,dc=company
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 3
uid: PeteMinsky
userPassword: {MD5}4QrcOUm6Wau+VuBX8g+IPg==
gidNumber: 1001
gecos: Pete Minsky
description: 5,6 #增加5,6权限
homeDirectory: /home/PeteMinsky

dn: uid=LosyDan,ou=People,dc=Administrator,dc=company
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 4
uid: LosyDan
userPassword: {MD5}4QrcOUm6Wau+VuBX8g+IPg==
gidNumber: 1002
gecos: Losy Dan
description: 
homeDirectory: /home/LosyDan

dn: uid=AnnRose,ou=People,dc=Administrator,dc=company
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 5
uid: AnnRose
userPassword: {MD5}4QrcOUm6Wau+VuBX8g+IPg==
gidNumber: 1003
gecos: Ann Rose
description: 
homeDirectory: /home/AnnRose

dn: uid=JackHamm,ou=People,dc=Administrator,dc=company
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 6
uid: JackHamm
userPassword: {MD5}4QrcOUm6Wau+VuBX8g+IPg==
gidNumber: 1003
gecos: Jack Hamm
description: 
homeDirectory: /home/JackHamm

dn: uid=DingDong,ou=People,dc=Administrator,dc=company
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 7
uid: DingDong
userPassword: {MD5}4QrcOUm6Wau+VuBX8g+IPg==
gidNumber: 1004
gecos: Ding Ding Dong
description: 
homeDirectory: /home/DingDong

dn: uid=Poss,ou=People,dc=Administrator,dc=company
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 8
uid: Poss
userPassword: {MD5}4QrcOUm6Wau+VuBX8g+IPg==
gidNumber: 1004
gecos: J.D
description: 
homeDirectory: /home/Poss

dn: uid=FangXian,ou=People,dc=Administrator,dc=company
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 9
uid: FangXian
userPassword: {MD5}4QrcOUm6Wau+VuBX8g+IPg==
gidNumber: 1005
gecos: Fang Xian
description: 
homeDirectory: /home/FangXian

附上Nodejs连接ldap的javascript代码

var ldap = require("ldapjs");

//创建LDAP client,把服务器url传入
var client = ldap.createClient({
    url: 'ldap://127.0.0.1:389'
});

//创建LDAP查询选项
//filter的作用就是相当于SQL的条件
var opts = {
    // filter: '(objectClass=*)', //查询条件过滤器,查找uid=kxh的用户节点
    scope: 'sub',
    //查询范围
    timeLimit: 500 //查询超时
};

//将client绑定LDAP Server
//第一个参数:是用户,必须是从根节点到用户节点的全路径
//第二个参数:用户密码
client.bind('dc=Administrator,dc=company', '123456',
function(err, res1) {

    //开始查询
    //第一个参数:查询基础路径,代表在查询用户信心将在这个路径下进行,这个路径是由根节开始
    //第二个参数:查询选项
    client.search('dc=Administrator,dc=company', opts,
    function(err, res2) {

        //查询结果事件响应
        res2.on('searchEntry',
        function(entry) {

            //获取查询的对象
            var user = entry.object;
            var userText = JSON.stringify(user, null, 2);
            console.log(userText);

        });

        res2.on('searchReference',
        function(referral) {
            console.log('referral: ' + referral.uris.join());
        });

        //查询错误事件
        res2.on('error',
        function(err) {
            console.error('error: ' + err.message);
            //unbind操作,必须要做
            client.unbind();
        });

        //查询结束
        res2.on('end',
        function(result) {
            console.log('search status: ' + result.status);
            //unbind操作,必须要做
            client.unbind();
        });

    });

});

ldap模拟数据及ldap数据格式说明:等您坐沙发呢!

发表评论

您必须 [ 登录 ] 才能发表留言!