使用JAVA进行ad域身份验证常用属性详解

一些变态的公司经常对开发者提出一些变态的问题。比如在oa系统中,要求登录验证必须使用ad域进行登录。还有的如登录crm系统必须使用公司的阿里云邮箱账号进行身份验证等等。
作为程序员我们只能按照客户的需求进行完善系统。毕竟客户才是我们的衣食父母,没办法拒绝。我这里就列举一些,在系统中集成ad域身份验证的一些配置信息,并一一解释他们的作用。
直接看代码:
public boolean login() {
		// 判断必填字段是否全部填写
		if (StringUtils.isEmpty(this.username)
			|| StringUtils.isEmpty(this.domain)
			|| StringUtils.isEmpty(this.ip)) {
			logger.info("必填信息为空,LDAP连接失败!");
			return false;
		}
		Properties env = new Properties();
		String account = this.username + "@" + this.domain;
		String ldapURL = "LDAP://" + this.ip + ":" + this.port;
		env.put(Context.PROVIDER_URL, ldapURL);
		env.put(Context.SECURITY_AUTHENTICATION, "simple");
		env.put(Context.SECURITY_PRINCIPAL, account);
		env.put(Context.SECURITY_CREDENTIALS, this.password);
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");  
        //批量处理
        env.put(Context.BATCHSIZE, "50");
        // 连接超时设置
        env.put("com.sun.jndi.ldap.connect.timeout", "3000");
        // LDAP连接池
        env.put("com.sun.jndi.ldap.connect.pool", "true");
        // LDAP连接池最大数
        env.put("com.sun.jndi.ldap.connect.pool.maxsize", "3");
        // LDAP连接池优先数
        env.put("com.sun.jndi.ldap.connect.pool.prefsize", "1");
        // LDAP连接池超时
        env.put("com.sun.jndi.ldap.connect.pool.timeout", "300000");
        // LDAP连接池初始化数
        env.put("com.sun.jndi.ldap.connect.pool.initsize", "1");
        // LDAP连接池的认证方式
        env.put("com.sun.jndi.ldap.connect.pool.authentication", "simple");
		try {
			dc = new InitialLdapContext(env, null);
			logger.info("域用户" + this.username + " 登录" + account + "成功!");
			return true;
		} catch (Exception e) {
			logger.info("域用户" + this.username + " 登录" + account + "失败!");
			return false;
		}
	}
欢迎大家关注我的博客!如有疑问,请加QQ群:135430763共同学习!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

业余草

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值