In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Code reference: https://github.com/chocolateBlack/db2Ldap
QQ group: 223460081
Synchronize the relational data organization into LDAP
1. Acquire organizational relationships in relational DB
2. Spanning tree data structure (different ways of obtaining and spanning tree structure due to different databases)
3. Add organizational structure nodes from top to bottom to LDAP according to the tree structure.
4. Get the relationship between user and organization in relational database.
5. LDAP adds user nodes
Environment-related configuration
ApplicationContext.xml Engineering Environment spring configuration File
Related configuration of db.properties Relational Database
Jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriverjdbc.url=jdbc:sqlserver://10.10.10.10;database=hrjdbc.username=adminjdbc.password=admin
Ldap.properties,LDAP related configuration
Spring.profiles.active=no-apachedssample.ldap.url=ldap://10.10.10.10:389sample.ldap.userDn=cn=Manager,dc=openldap,dc=jw,dc=cnsample.ldap.password=G0qGH9123sample.ldap.base=dc=openldap,dc=jw,dc=cnsample.ldap.directory.type=NORMAL
Partial code
/ * add an organizational structure natively * / @ Test public void createNode () {Attributes attr = new BasicAttributes (); BasicAttribute ocattr = new BasicAttribute ("objectclass"); ocattr.add ("organizationalUnit"); ocattr.add ("top"); attr.put (ocattr) LdapTemplate.bind ("ou= Services", null, attr); ldapTemplate.bind ("ou= Division, ou= Services", null, attr); ldapTemplate.bind ("ou= Project team, ou= Division, ou= Services", null, attr);}
/ * Natively add User * / @ Test public void createU () {Attributes attr = new BasicAttributes (); BasicAttribute ocattr = new BasicAttribute ("objectclass"); ocattr.add ("top"); ocattr.add ("organizationalPerson"); ocattr.add ("shadowAccount") Attr.put (ocattr); attr.put ("userPassword", "12"); attr.put ("sn", "12"); attr.put ("uid", "12"); / / ldapTemplate.bind ("ou=IT", null, attr) / / buildDN () function ldapTemplate.bind ("cn=123,ou=A Project team, ou=A Division, ou= Business", null, attr);} / * * add an organization by annotating the Java class through Entity, one through the orgService interface and the other directly through ldapTemplate * / @ Test public void createOrganization () {JWOrganization org = new JWOrganization () Org.setId ("ou=1, ou= Division, ou= Business"); orgService.createJWOrg (org); / / ldapTemplate.create (org) } / * Test add a new user and add that user to a Group * / @ Test public void createUser () {JWUser user = new JWUser (); user.setId ("cn=111, ou= Division, ou= Business"); user.setEmail ("123@126.com") User.setEmployeeNumber ("123"); user.setLastName (" lastName "); user.setPhone (" 123"); user.setTitle ("title"); user.setUid ("123"); user.setUserPassword (" c9c4c39a6ce34112314ba89c1e777 "); userService.createJWUser (user) AddMemberToGroup (user); / / ldapTemplate.create (user);}
Organizational structure type JWOrganization
Package org.springframework.ldap.samples.useradmin.domain;import java.util.ArrayList;import java.util.List;import javax.naming.Name;import org.springframework.data.domain.Persistable;import org.springframework.ldap.odm.annotations.Attribute;import org.springframework.ldap.odm.annotations.DnAttribute;import org.springframework.ldap.odm.annotations.Entry;import org.springframework.ldap.odm.annotations.Id;import org.springframework.ldap.odm.annotations.Transient;import org.springframework.ldap.support.LdapUtils / * @ author jgh * / @ Entry (objectClasses = {"organizationalUnit", "top"}) public final class JWOrganization implements Persistable {private static final long serialVersionUID = 1L; @ Id private Name id; @ Attribute (name = "ou") @ DnAttribute (value= "ou") private String fullName; @ Transient private String orgCode; @ Transient private String orgName @ Transient private String orgParentCode; @ Transient private String orgType; @ Transient private List children = new ArrayList (); public List getChildren () {return children;} public void setChildren (List children) {this.children = children } public JWOrganization (String orgCode, String orgName, String orgParentCode, String orgType) {this.orgCode=orgCode; this.orgName=orgName; this.orgParentCode= orgParentCode; this.orgType=orgType; this.fullName = orgName } public JWOrganization () {/ / TODO Auto-generated constructor stub} public void setId (Name id) {this.id = id;} public void setId (String id) {this.id = LdapUtils.newLdapName (id);} public String getOrgCode () {return orgCode } public void setOrgCode (String orgCode) {this.orgCode = orgCode;} public String getOrgName () {return orgName;} public void setOrgName (String orgName) {this.orgName = orgName;} public String getOrgParentCode () {return orgParentCode } public void setOrgParentCode (String orgParentCode) {this.orgParentCode = orgParentCode;} public String getOrgType () {return orgType;} public void setOrgType (String orgType) {this.orgType = orgType;} public String getFullName () {return fullName } public void setFullName (String fullName) {this.fullName = fullName;} @ Override public boolean isNew () {/ / Serializable id = getId (); / / return id = = null | | StringUtils.isBlank (String.valueOf (id)); return true } @ Override public Name getId () {return this.id;}}
User class
/ * Copyright 2005-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "ASIS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * / package org.springframework.ldap.samples.useradmin.domain;import javax.naming.Name;import org.springframework.data.domain.Persistable;import org.springframework.ldap.odm.annotations.Attribute;import org.springframework.ldap.odm.annotations.DnAttribute;import org.springframework.ldap.odm.annotations.Entry;import org.springframework.ldap.odm.annotations.Id;import org.springframework.ldap.support.LdapUtils / * @ author Mattias Hellborg Arthursson * / @ Entry (objectClasses = {"inetOrgPerson", "organizationalPerson", "person", "top", "shadowAccount"}) public final class JWUser implements Persistable {private static final long serialVersionUID = 1L; @ Id private Name id; @ Attribute (name = "cn") @ DnAttribute (value= "cn") private String fullName; @ Attribute (name = "employeeNumber") private String employeeNumber Attribute (name = "sn") private String lastName; @ Attribute (name = "title") private String title; @ Attribute (name = "mail") private String email; @ Attribute (name = "telephoneNumber") private String phone; @ Attribute (name = "uid") private String uid; @ Attribute (name = "userPassword") private String userPassword; @ Override public Name getId () {return id } public void setId (Name id) {this.id = id;} public void setId (String id) {this.id = LdapUtils.newLdapName (id);} public String getEmail () {return email;} public void setEmail (String email) {this.email = email;} public String getEmployeeNumber () {return employeeNumber } public void setEmployeeNumber (String employeeNumber) {this.employeeNumber = employeeNumber;} public String getFullName () {return fullName;} public void setFullName (String fullName) {this.fullName = fullName;} public String getLastName () {return lastName;} public void setLastName (String lastName) {this.lastName = lastName;} public String getPhone () {return phone } public void setPhone (String phone) {this.phone = phone;} public String getTitle () {return title;} public void setTitle (String title) {this.title = title;} public String getUid () {return uid;} public void setUid (String uid) {this.uid = uid } public String getUserPassword () {return userPassword;} public void setUserPassword (String userPassword) {this.userPassword = userPassword;} @ Override public boolean equals (Object o) {if (this = = o) return true; if (o = = null | | getClass ()! = o.getClass ()) return false; JWUser user = (JWUser) o If (id! = null?! id.equals (user.id): user.id! = null) return false; return true;} @ Override public int hashCode () {return id! = null? Id.hashCode (): 0;} @ Override public boolean isNew () {return true;}}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.