前言:
网上很多文章都在讲LDAP Server,但是很少有人提及如何使用它来做验证和授权,今天写出此贴,希望能够帮助各位开发人员。
目标:
使用JAAS框架,使用Struts框架,使用LDAP Server,使用JBOSS,做用户的验证和授权
(验证的含义是用户有效,即用户名、密码输入正确;授权的含义是用户被授予某种角色)
基础要求:
精通J2EE框架
会使用Struts开发
能够正确安装iPlanet Directory Server,并有使用经验
熟悉JBOSS开发
熟悉JAAS框架
准备:
windows 2k (要加入域)
j2sdk1.4.2 installed
jboss3.2.5 higher installed
iPlanet Directory Server 5.1 Service Pack 2 installed
首先说一下JAAS和LDAP:
在实际开发过程中,很多项目都会使用同一个用户信息源,比如客户的Notes系统、ERP系统等等。
如果我们授命为客户开发一套新的应用,就需要和上述系统一同使用一个用户信息源“LDAP Server”。
JAAS是一个JAVA应用的验证、授权框架。很多Application Server都会去实现这个框架(JBOSS就是其中之一),从而使开发人员不需要自己动手就可以在项目中使用高可靠的安全验证体系。
首先假设我们在JBOSS下开发一个应用,叫做“myapp”
LDAP Server使用Sun iPlanet Directory Server
LDAP中增加一个组织结构
Group: admin, Engineer
Role: SysUser, admin, Engineer
User: JZhao (密码:password,角色:SysUser、admin、Engineer)
如果不愿意手动建立用户,可以copy下面的内容存入temp.ldif文件中,使用iPlanet的导入功能建立用户
temp.ldif文件的内容:
# ================================== OU DEFINITIONS
# People OU - for holding records of all individuals
dn: ou=People,dc=china,dc=xxx,dc=com
ou: People
objectClass: top
objectClass: organizationalUnit
# Groups OU - for holding records of groupings of individuals
dn: ou=Groups,dc=china,dc=xxx,dc=com
ou: Groups
objectClass: top
objectClass: organizationalUnit
# Roles OU - for holding records of roles and the groups to which those roles have been assigned
dn: ou=Roles,dc=china,dc=xxx,dc=com
ou: Roles
objectClass: top
objectClass: organizationalUn