有了域名怎么建设网站,wordpress 4.5.7漏洞,高端网站建设成都,六安人论坛最新招聘近期由于工作需要整理一下自动化的东西#xff0c;因为公司去年上线了OA#xff0c;所以公司的入职系统会提交用户的信息到IT部门#xff0c;最早的做法是入职到了#xff0c;IT部门收集用户信息在AD中创建对应的用户信息#xff0c;所以为了提高管理员的工作效率#xf… 近期由于工作需要整理一下自动化的东西因为公司去年上线了OA所以公司的入职系统会提交用户的信息到IT部门最早的做法是入职到了IT部门收集用户信息在AD中创建对应的用户信息所以为了提高管理员的工作效率所以准备实施自动创建AD账户当OA流程到IT人员审批节点后IT人员审批后根据人员信息自动创建AD账户所以整理了一些JAVA创建AD人员信息的信息但是我们需要注意点的是对于JAVA语言操作MS AD的一些普通操作是不需要SSL的但是对于用户密码的重置操作必须使用SSL当然之前看网上有说可以跳过的但是没有试验成功所以还是按照标准的配置来通过SSL对用户的AD密码进行操作废话不多说了今天我们主要介绍使用JAVA通过SSL方式创建MS AD账户因为要对创建的用户设置密码所以需要使用SSL证书既然需要SSL证书目的就是为了让JAVA信任LDAP所以我们需要从AD中导出受信任的证书然后导入到JAVA运行环境中的JRE下的cacert证书文件中。我们既然说到了OA其实OA中就可以通过系统自带的功能进行证书申请及证书导入这样比较简单当然如果没有OA环境的我们可以通过JAVA运行环境中的JDK中的keytool进行证书导入工作我们下面都会介绍到 我们首先使用OA中的功能进行证书导入我们OA中的证书路劲在/OAFS/WEAVER/jdk1.8.0_101/jre/lib/security/cacerts 确认OA环境中的JDK路劲后我们接下来就是证书申请及导入了 我们访问OA的地址然后路劲增加/integration/ldapcert.jsp路劲访问即可如果没有后面的JAVA文件可以找OA供应商要或者在附件下载 我们首先下载附件中的文件下载后附件中有三个文件classbean、 我们首先进入classbean文件夹内的内容拷贝到对应的OA服务器的对应目录 ecology\classbean\weaver\ldap 2.然后将解压文件中的文件夹integration文件中的以下文件拷贝到OA的对应的服务器目录下 ecology\integration 3.因为解压后有三个文件夹第三个文件夹src为源码我们就不用管了 按照以上方法走完后我们就可以通过以下链接来配置了 http://192.168.6.101/integration/ldapcert.jsp 访问后我们再LDAP IP输入环境的AD DC服务器地址系统会默认填写LDAP端口636及证书路劲这些信息系统会自动补全我们需要手动设置证书密码一般我们都会设置成changeit设置好这些信息后我们导入证书会提示下面的导入信息 导入完成 然后我们需要在证书路劲下载证书到本地的JRE环境进行测试了 接着我们看看第二种方式的证书申请 我们需要从DC上导入域的根证书 mmc---增加---证书---计算机---个人---选择根证书----导出 不需要导出私钥 使用默认的DRE编码 保存 我们按照同样的方式将另外一张也导出来 然后我们需要在本地的JDK环境中导入该根证书到JDK环境中的证书中 我本地的JDK环境路劲D:\Development_Environment\java\jdk\jre\lib\security 然后运行命令将刚才导出的根证书导入到该路劲的cacert证书文件中 我们首先要cd到jdk路劲 1 cd D:\Development_Environment\java\jdk\jre\bin 然后将刚才导出的根证书保存到D盘下通过以下命令导入 1 keytool keytool -import -keystore D:\Development_Environment\java\jdk\jre\lib\security\cacerts -storepass changeit -keypass changeit -alias CA -file d:\ADroot.cer 输入Y受信任 然后我们就可以通过 接着就是看看ADDS环境了 换进准备好我们就可以上代码了 我们设置好证书路劲及LDAP验证信息及需要注册的用户名 账户注册成功 上代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 package com.ixmsoft.oa.util; import java.util.Properties; import javax.naming.*; import javax.naming.ldap.*; import javax.naming.directory.*; /** * author Keven Chen * version $Revision 1.0 $ * */ public class AddAdUser { private static final String SUN_JNDI_PROVIDER com.sun.jndi.ldap.LdapCtxFactory; public static void main(String[] args) throws Exception { String keystore D:\\Development_Environment\\java\\jdk\\jre\\lib\\security\\cacerts; System.setProperty(javax.net.ssl.trustStore, keystore); Properties env new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, SUN_JNDI_PROVIDER);// java.naming.factory.initial env.put(Context.PROVIDER_URL, ldap://192.168.5.20:636);// java.naming.provider.url env.put(Context.SECURITY_AUTHENTICATION, simple);// java.naming.security.authentication env.put(Context.SECURITY_PRINCIPAL, cnAdministrator,cnUsers,dcixmsoft,dccom);// java.naming.security.principal env.put(Context.SECURITY_CREDENTIALS, 123);// java.naming.security.credentials env.put(Context.SECURITY_PROTOCOL, ssl); String userName CNgaowenlong,OUIXM Adm,OUIMXSOFT Users,DCixmsoft,DCcom; String groupName CNDomain Admins,CNUsers,DCixmsoft,DCcom; LdapContext ctx new InitialLdapContext(env, null); // Create attributes to be associated with the new user Attributes attrs new BasicAttributes(true); // These are the mandatory attributes for a user object // Note that Win2K3 will automagically create a random // samAccountName if it is not present. (Win2K does not) attrs.put(objectClass, user); attrs.put(sAMAccountName, gaowenlong); attrs.put(cn, gaowenlong); // These are some optional (but useful) attributes attrs.put(sn, gaowenlong); attrs.put(displayName, gaowenlong); attrs.put(description, gaowenlong); attrs.put(userPrincipalName, gaowenlongixmsoft.com); attrs.put(mail, gaowenlongixmsoft.com); attrs.put(telephoneNumber, 1234568999); // some useful constants from lmaccess.h int UF_ACCOUNTDISABLE 0x0002; //禁用账户 int UF_PASSWD_NOTREQD 0x0020; //用户不能修改密码 int UF_PASSWD_CANT_CHANGE 0x0040; int UF_NORMAL_ACCOUNT 0x0200; //正常用户 int UF_DONT_EXPIRE_PASSWD 0x10000; //密码永不过期 int UF_PASSWORD_EXPIRED 0x800000; //密码已经过期 // Note that you need to create the user object before you can // set the password. Therefore as the user is created with no // password, user AccountControl must be set to the following // otherwise the Win2K3 password filter will return error 53 // unwilling to perform. attrs.put(userAccountControl, Integer.toString(UF_NORMAL_ACCOUNT UF_PASSWD_NOTREQD UF_PASSWORD_EXPIRED UF_ACCOUNTDISABLE)); // Create the context Context result ctx.createSubcontext(userName, attrs); System.out.println(Created disabled account for: userName); ModificationItem[] mods new ModificationItem[2]; // Replace the unicdodePwd attribute with a new value // Password must be both Unicode and a quoted string String newQuotedPassword \Password2000\; byte[] newUnicodePassword newQuotedPassword.getBytes(UTF-16LE); mods[0] new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(unicodePwd, newUnicodePassword)); mods[1] new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(userAccountControl, Integer .toString(UF_NORMAL_ACCOUNT UF_PASSWORD_EXPIRED))); // Perform the update ctx.modifyAttributes(userName, mods); System.out.println(Set password updated userccountControl); // now add the user to a group. try { ModificationItem member[] new ModificationItem[1]; member[0] new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute(member, userName)); ctx.modifyAttributes(groupName, member); System.out.println(Added user to group: groupName); } catch (NamingException e) { System.err.println(Problem adding user to group: e); } // Could have put tls.close() prior to the group modification // but it seems to screw up the connection or context ? ctx.close(); System.out.println(Successfully created User: userName); } } 我们查看 查看账户属性 然后查看属性 我们将java文件上传到附件中如果加在eclipse中有报错请根据错误提示右击导入ldap相关的包即可 本文转自 高文龙 51CTO博客原文链接http://blog.51cto.com/gaowenlong/1969585如需转载请自行联系原作者