- 浏览: 158622 次
- 性别:
- 来自: 火星
文章分类
最新评论
-
zhangzhenting:
968862
EasyMock Capture的使用 -
andey007518:
不错,明天好试验试验
基于Axis2的WS构建服务端示例 -
Z_408:
谢谢,找好多例子终于成功一个了
Spring LDAP -
jyjava:
传说中单点登录,哈哈
中国移动4A系统账号密码管理方式 -
zhangzhenting:
sat on the fix ?? all day ???
TestNG plugin for Eclipse
初次对活动目录(AD)操作,记录下基本的操作方式。
import java.security.Security; import java.util.Hashtable; import javax.naming.AuthenticationException; import javax.naming.Context; import javax.naming.NamingException; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttribute; import javax.naming.directory.BasicAttributes; import javax.naming.directory.DirContext; import javax.naming.directory.ModificationItem; import javax.naming.ldap.Control; import javax.naming.ldap.InitialLdapContext; import javax.naming.ldap.LdapContext; public class ADTest { private LdapContext ctx = null; private String baseName = ",CN=users,DC=zzt,DC=com"; public ADTest() { try { Hashtable<String, String> ldapEnv = new Hashtable<String, String>(); ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); ldapEnv.put(Context.PROVIDER_URL, "ldap://192.168.0.1"); ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); ldapEnv.put(Context.SECURITY_PRINCIPAL, "CN=Administrator,CN=users,DC=zzt,DC=com"); ldapEnv.put(Context.SECURITY_CREDENTIALS, "123456"); // 密码 // ldapEnv.put(Context.SECURITY_PROTOCOL, "ssl"); ctx = new InitialLdapContext(ldapEnv, null); } catch (Exception e) { System.out.println(" bind error: " + e); e.printStackTrace(); } } /** * 创建一个新的用户 * @param username * @param surname * @param givenName */ public void createNew(String username, String surname, String givenName) { try { String distinguishedName = "cn=" + username + baseName; Attributes newAttributes = new BasicAttributes(true); Attribute oc = new BasicAttribute("objectclass"); oc.add("top"); oc.add("person"); oc.add("organizationalperson"); oc.add("user"); newAttributes.put(oc); newAttributes.put(new BasicAttribute("sAMAccountName", username)); newAttributes.put(new BasicAttribute("cn", username)); newAttributes.put(new BasicAttribute("sn", surname)); ctx.createSubcontext(distinguishedName, newAttributes); } catch (Exception e) { System.out.println("create error: " + e); e.printStackTrace(); System.exit(-1); } } /** * 更新用户 * @param username */ public void update(String username) { try { System.out.println("updating...\n"); ModificationItem[] mods = new ModificationItem[1]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description", "hello world")); ctx.modifyAttributes("cn=" + username + baseName, mods); } catch (Exception e) { System.out.println(" update error: " + e); System.exit(-1); } } /** * 修改密码 * @param username * @param password */ public void updatePassword(String username, String password) { try { System.out.println("updating password...\n"); String quotedPassword = "\"" + password + "\""; // char unicodePwd[] = quotedPassword.toCharArray(); // byte pwdArray[] = new byte[unicodePwd.length * 2]; // for (int i = 0; i < unicodePwd.length; i++) // { // pwdArray[i * 2 + 1] = (byte) (unicodePwd[i] >>> 8); // pwdArray[i * 2 + 0] = (byte) (unicodePwd[i] & 0xff); // } // System.out.print("encoded password: "); // for (int i = 0; i < pwdArray.length; i++) // { // System.out.print(pwdArray[i] + " "); // } byte[] newUnicodePassword = quotedPassword.getBytes("UTF-16LE"); System.out.println(); ModificationItem[] mods = new ModificationItem[1]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("unicodePwd", newUnicodePassword)); ctx.modifyAttributes("cn=" + username + baseName, mods); } catch (Exception e) { System.out.println("update password error: " + e); e.printStackTrace(); System.exit(-1); } } /** * 登陆认证 * * @param userDn * String * @param password * String * @return boolean */ public boolean authenticate(String userDn, String password) { try { Control[] connCtls = new Control[] {}; ctx.getRequestControls(); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password); ctx.reconnect(connCtls); return true; } catch (AuthenticationException e) { return false; } catch (NamingException e) { return false; } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { e.printStackTrace(); } ctx = null; } } } /** * 删除用户. * * @param userDN * String 用户DN * @return */ public boolean del(String userDN) { try { ctx.destroySubcontext(userDN); return true; } catch (NamingException e) { System.err.println("Problem changing password: " + e); } catch (Exception e) { System.err.println("Problem: " + e); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { e.printStackTrace(); } ctx = null; } } return false; } public static void main(String[] args) { Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); ADTest adt = new ADTest(); // System.out.println(adt.authenticate("CN=zztxxx,CN=users,DC=zzt,DC=com", "asdf23")); // System.out.println(adt.del("CN=zztxxx,CN=users,DC=zzt,DC=com")); } }
发表评论
-
测试static final 变量
2016-08-17 15:56 429private void setMockedLogg ... -
Java中调用Python代码
2016-05-17 17:22 652import org.python.core.PyFunct ... -
JAVA 练习题
2016-05-17 16:22 533需求:下面有两组数(由用户自定义)A: a1,a3,a3, ... -
JUnit培训(二)
2014-10-12 21:47 0问题: 1. 在Junit里面一些常用的方法? ... -
JUnit 培训计划
2014-10-12 21:42 588一、10/13 1. IDE 使用 2. ... -
乱码问题
2013-02-24 13:41 777我在myeclipse databae Explorer ... -
Log4j 配置
2013-02-24 11:37 884## LOGGERS ## #define a logg ... -
ReflectionTestUtils
2012-11-13 16:42 1088org.springframework.test.uti ... -
Spring与Testng整合
2013-02-25 16:00 1399Spring专门为Junit testNG提供了一套测试集成 ... -
Hibernate基础
2012-09-28 15:34 846hibernate工作原理: 1。 读取并解析配置 ... -
汉字与二进制的互相转换
2012-04-01 11:15 1940public class Test { public ... -
TestNG plugin for Eclipse
2012-03-02 14:42 991Start Eclipse Select Help / I ... -
XML -> xsd -> Java
2011-08-08 13:51 1069XML Schema Generatorhttp://ww ... -
Hibernate EHCache
2010-09-14 14:43 1532By default, Hibernate uses EHCa ... -
Java加密技术
2010-07-22 10:53 1137很喜欢梁栋关于Java Security的文章,在这里做个汇总 ... -
中国移动4A系统账号密码管理方式
2010-07-09 15:47 15546好像现在很 ... -
统一授权管理
2010-07-07 11:24 1654用户授权管理在统一用户目录和统一资源目录的基础上,实现针对不同 ... -
操作日志队列
2010-06-25 17:27 751使用队列来记录日志 附件为测试代码 未完。。。 -
UAC产品集成策略
2010-06-22 10:10 1797接触UAC(Unified Authenticatio ... -
答复: 项目规划那些事
2010-06-12 16:27 820随便说说了,仅仅发表个人看法: 层 和 模块 不能混在一起谈 ...
相关推荐
主要介绍了JAVA使用Ldap操作AD域的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
ldap与AD之间的连接的示例源代码。挺不错的。
ldap 示例 博文链接:https://laowood.iteye.com/blog/168790
比较宏观全面的介绍AD, AD LDS,LDAP, OpenLdap,LDAP client API,并提供了c++,java,python的示例代码,不是很深入,但对入门,对全面的理解这几个技术之间的关系,有很大的帮助。
SQLDAP曾经想用类似 SQL 的查询来查询 AD 或 LDAP 吗?我要自己回答这个问题:是的!为什么 ?因为我永远无法记住所有 ldapsearch 参数和过滤器等。但是在构建这个工具之后,我现在是 ldapsearch 的高手 :)支持的...
该模块旨在使用现有的 python-ldap 模块绑定到 AD 并创建可用于操作 Active Directory 对象的对象。 新类为常见操作提供实用方法,例如启用或禁用帐户,或编辑组成员资格。 这是来自 Google Code 上的 py-ad-ldap ...
针对LDAP / AD服务器的身份验证策略。 该模块是的Passport策略包装器。 该模块使您可以在Node.js应用程序中使用LDAP或AD进行身份验证。 通过插入Passport,可以将LDAP身份验证集成到支持Connect风格中间件的任何...
LINQ提供程序基于System.DirectoryServices.Protocols构建,用于与LDAP服务器进行交互。 概述 关于如何通过System.DirectoryServices和System.DirectoryServices.AccountManagement访问Active Directory的示例很多。...
Import_Usuarios_AD_Zimbra 如何将用户从AD导入到ZIMBRA 这是从AD到zimbra的用户配置的一个很小的... ldapsearch -x -b“ dc =示例,dc =本地” -H“ ldap://EXAMPLE.local” -D“ CN = USER_AUTENTICATION,OU =示
任何其他基于LDAP的目录 Azure活动目录 G Suite(Google) Okta 该应用程序使用带有Angular的Electron编写,并安装在Windows,macOS和Linux发行版上。 命令行界面 命令行界面工具也可用于Bitwarden目录连接器。 ...
ldap4net OpenLdap客户端库的跨平台端口( ) 和Windows Ldap( )到DotNet Core 帮助支持该项目: 对于Linux \ OSX,您必须确保已从安装了... 用法示例(Kerberos身份验证) using ( var cn = new LdapConnection
日志示例示例: 2015/06/26 10:46:06 Student FirstName LastName, CurrentGrade not found in LDAP Search 启用帐户时,属性useraccountcontrol设置为512 ,禁用帐户时,属性切换为514 。 这些属性来自Active ...
播放模块 AD SSO 这是 kerberos SSO 的 play 2.3 模块,支持回退。 它还包含一个简单的 ldap 类,用于获取用户详细信息并使用用户名和密码进行身份验证。 这是一个简单的示例,说明如何保护 public class ...
专注于非互联网用例的 MS ADFS / LDAP (MS AD) 集成 用例: 使用全局 AAA 的引导目录作为起点 理解后的模型 AAA 或 ACL 验证: 通过 LDAP 验证用户 只有一个用户作为本地用户:如果需要,最后的诊断用户 标头中的...
ad-ldap-demo apache-cxf-ws 货币转换 设备检测 加密邮件 通用CSV阅读器 java-deep-learning kafka-demo 邮件演示 微服务 多数据库 石英演示...