码迷,mamicode.com
首页 > 其他好文 > 详细

[Liferay] Liferay 实现单点登录 - OpenLDAP

时间:2014-10-29 14:53:22      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:liferay   openldap   sso   单点登录   cas   

Liferay 的单点登录绝对是个难啃的骨头,更何况网上能搜到的基本都是些滥竽充数的文章,非常不负责任。

于是在自己搭通单点登录一条线之后,决定整理下思路并写出来,希望各位能别重蹈覆辙。


本文不介绍概念,只注重实现


软件版本:

Liferay : 6.1.1 CE GA2
OpenLdap for Windows :openldap-2.4.38-x86
Apache Directory Studio : Apache Directory Studio 2.0.0-M3
CAS : cas-server-3.5.2
Windows : 7 x64


第一篇 OpenLDAP


不再讲述 LDAP 概念,只需知道 OpenLDAP 是 LDAP 协议的几个主流实现之一,重点是介绍如何在 windows 平台上安装和配置 OpenLDAP。


下载

openLDAP官方网站:http://www.openldap.org/
openLDAP官网只提供了linux平台的相关安装文件,windows平台的安装包可以到以下一些网站下载:
http://www.userbooster.de/download/openldap-for-windows.aspx
http://sourceforge.jp/projects/openldapwin32/releases/
http://sourceforge.net/projects/openldapwindows/files/

http://sourceforge.net/projects/openldapwindows/(本文所用的版本)

以上四个地址中第一个安装完成之后 LDAP server 启动总是异常,并没有具体分析原因,直接卸载安装最后一个链接中的版本,好使。

安装

bubuko.com,布布扣

一路点击 next 即可,注意默认的 backend engine 为 BDB,意思也就是 LDAP 使用 BDB 存储数据,可以根据需求自行配置如 SQL Server 等。
安装完成之后找到安装路径下的E:\OpenLDAP\etc\openldap,打开slapd.conf,替换整个内容为


include   ../etc/openldap/schema/core.schema
include   ../etc/openldap/schema/cosine.schema
include   ../etc/openldap/schema/inetorgperson.schema

pidfile ../var/run/slapd.pid

loglevel  -1

moduleload back_bdb.la

database bdb
suffix "dc=example, dc=com"

rootdn "cn=jimbob, dc=example, dc=com"
rootpw dirtysecret

directory       ../var/openldap-data

# Indices to maintain for this directory
# unique id so equality match only
index uid eq
# allows general searching on commonname, givenname and email
index cn,gn,mail eq,sub
# allows multiple variants on surname searching
index sn eq,sub
# sub above includes subintial,subany,subfinal
# optimise department searches
index ou eq
# if searches will include objectClass uncomment following
# index objectClass eq
# shows use of default index parameter
index default eq,sub
# indices missing - uses default eq,sub
index telephonenumber

# other database parameters
# read more in slapd.conf reference section
cachesize 10000
checkpoint 128 15

其中

suffix "dc=example, dc=com"
可以理解为整个 LDAP 的跟目录地址,可以自行配置
rootdn "cn=jimbob, dc=example, dc=com" rootpw dirtysecret
管理员用户的 DN 以及密码,可以自行配置
directory       ../var/openldap-data
LDAP 数据库目录

至于其他参数我暂时也不关心是什么意思。

启动 LDAP server

这个安装版本中,不需要通过命令行启动,开始菜单里找到 OpenLDAP,并启动


bubuko.com,布布扣

看到如下内容就算是启动成功了

bubuko.com,布布扣

一般教程到这里都会提示需要新建个 .ldif 文件,用来添加用户或者组织,其实刚开始大可不必纠结于这个文件以及里面的语法,因为完全可以使用 LDAP 可视化工具完成同样的工作。但毕竟写文档,这部分还是得写。

LDIF 文件

DIT 结构 – 如下图,可以理解为LDAP 的结构目录,就比如 Java Web应用的目录。


bubuko.com,布布扣

在E:\OpenLDAP 目录创建demo.ldif 文件,粘贴以下的 内容,用来创建 DIT 结构,并添加用户

dn: dc=example,dc=com
dc: example
description: text whatever you want for description
objectClass: dcObject
objectClass: organization
o: Example, Inc.

dn: ou=people, dc=example,dc=com
ou: people
description: All people in organisation
objectclass: organizationalunit

dn: cn=Robert Smith,ou=people,dc=example,dc=com
objectclass: inetOrgPerson
cn: Robert Smith
sn: smith
uid: rjsmith
userpassword: rJsmitH
mail: rsmith@example.com
description: swell guy
ou: Human Resources

在E:\OpenLDAP\bin目录下输入以下指令用来导入 LDIF 文件,为什么要到这个目录,因为这个目录底下有ldapadd.exe,不然使用 ldapadd 指令会提示提示:’ldapadd’ 不是内部或外部命令,也不是可运行的程序或批处理文件

ldapadd -x -D "cn=jimbob,dc=example,dc=com" -f ./mydemo.ldif -w dirtysecret

接下来通过以下search 指令确认是否导入成功

ldapsearch -x -b "dc=example,dc=com" "(objectclass=*)"

LDAP 客户端 Apache Directory Studio

LDAP 有多种客户端,本文使用的是Apache Directory Studio,没什么特别原因,就是觉得 Apache 相对比较亲切一点。
下载地址 :http://directory.apache.org/studio/downloads.html
下载最新版的即可。安装以及配置步骤可以参考官方文档https://directory.apache.org/studio/users-guide/ldap_browser/gettingstarted_download_install.html
左下 Connection 区域点击右键添加 Connection。
注意 OpenLdap 的 Port 为 389。

bubuko.com,布布扣


Bind DN or User :slapd.conf 文件内的rootdn
Bind password : slapd.conf 文件内的rootpw
点解 Check Authentication 确认验证成功


bubuko.com,布布扣

之后点击 Finish,配置成功。可以在左侧 LDAPBrowser 里看到整个 DIT 结构。

Liferay 配置 LDAP

在 Liferay 的 Crontrol Panel 找到 LDAP 配置界面,点击添加 LDAP Server。
Server Name – 没什么可说的
Default Values – 只有当你想切换 LDAP 工具时,根据具体的 LDAP 实现工具来重置底下所有属性
Connection : 配置用来连接 LDAP server


bubuko.com,布布扣

Users

User Mapping – 用来映射 LDAP 内 user 属性与 Liferay 内user属性


bubuko.com,布布扣

Groups – 对应于  LDAP 里的 group

bubuko.com,布布扣

Export – 这个必须配置,不然无法将 Liferay 用户到处到 LDAP server,导致配置完成之后, Liferay 用户反而不能成功登录


bubuko.com,布布扣

保存,回到LDAP主界面,确认选择 Enabled 与 Required, Liferay 官方对这两个属性解释如下:
ldap.auth.enabled=true
Set ldap.auth.enabled = true to enable LDAP Authentication

ldap.auth.required=true
Setting required = true means that you must successfully bind with the record in the LDAP server before Liferay will allow the user to log in

确认选择 Import / Export


bubuko.com,布布扣

Liferay 官方解释如下:
ldap.import.enabled=true
If set to true, then Liferay will do a mass import of users on the specified interval

ldap.import.on.startup=true
If set to true, Liferay will do a mass import of all LDAP users according to the import method (that match the user specified search filter) on startup


ldap.export.enabled=true
If set to true, Liferay will export the user to LDAP. Liferay uses a listener to track any changes made to the User object and will push these changes out to the LDAP server whenever the User object is updated. Note that on every login, fields such as "LastLoginDate" are updated and so if export is enabled, logging in with a user will export the user to LDAP.


上述步骤只是单点登录的准备工作而已,只要能在 Liferay 配置 LDAP 界面 Test 成功就算是配置正确。




[Liferay] Liferay 实现单点登录 - OpenLDAP

标签:liferay   openldap   sso   单点登录   cas   

原文地址:http://blog.csdn.net/paranoid_android/article/details/40585507

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!