Spring3 LDAP

Spring3 LDAP

这里介绍使用LDAP来校验用户

1.准备阶段

下载相关的jar
spring-ldap-1.3.0.RELEASE-all.jar
可以去http://www.springsource.org/ldap/这里下载。

2.配置相关

        <bean id="contextSource"
		class="org.springframework.ldap.test.TestContextSourceFactoryBean">
		<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
		<property name="defaultPartitionName" value="jayway" />
		<property name="principal" value="${userDn}" />
		<property name="password" value="${password}" />
		<property name="ldifFile" value="classpath:/setup_data.ldif" />
		<property name="port" value="3900" />
	</bean>

	<bean id="ldapTemplate"
		class="org.springframework.ldap.core.LdapTemplate">
		<constructor-arg ref="contextSource" />
	</bean>

3.访问LDAP服务器

import javax.inject.Inject;

import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
import org.springframework.stereotype.Service;

@Service
public class SpringLdapDaoImpl implements SpringLdapDao {

	@Inject
	LdapTemplate ldapTemplate;

	@Override
	public boolean authUser(String userId, String password) {
		AndFilter filter = new AndFilter();
		filter.and(new EqualsFilter("CN", userId));
		return ldapTemplate.authenticate("OU=Org" , filter.toString(), password);
	}
}

然后在server端调用即可验证用户。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值