介绍
LDAP(Light Directory Access Portocol),它是基于[X.500标准](https://blog.csdn.net/starboybenben/article/details/48244661)的轻量级目录访问协议。是一个为查询、浏览和搜索而优化的数据库,它成树状结构组织数据,类似文件目录一样。不需单独定制,只需要通过LDAP做简单的配置就可以与服务器做认证交互。可以大大降低重复开发和对接的成本。
专业术语
名词 | 全称 | 解释 |
---|---|---|
objectClass | 一种特殊的属性,它包含其它用到的属性以及它自身 | |
dc | domain component | 域名,其格式是将完整的域名分成几部分,如域名example.com变成dc=example,dc=com |
uid | user id | 用户ID |
ou | organization unit | 组织单位,组织单位可以包含其他各种对象(包括其他组织单元) |
cn | common name | 用户全称 |
sn | sur name | 姓 |
dn | distinguished name | 唯一标识,如“uid=ketty,ou=gccloud,dc=example,dc=com” |
rdn | relative | 相对唯一标识,它是与目录树结构无关的部分,如“uid=tom”或“cn= Thomas Johansson” |
接入
服务端安装
使用docker的方式进行安装openLdap服务端,可参照docker安装openldap
运行镜像
docker run -p 389:389 -p 636:636 --name myopenldap --network bridge --hostname openldap-host --env LDAP_ORGANISATION="mylitboy" --env LDAP_DOMAIN="mylitboy.com" --env LDAP_ADMIN_PASSWORD="ldap123" --detach osixia/openldap
命令解释:
- -p : 指定端口映射,格式为:主机(宿主)端口:容器端口
- —name : 为容器指定一个名称
- —network : 指定容器的网络连接类型,支持 bridge/host/none/container四种类型
- —hostname : 指定容器的hostname
- —env : 设置环境变量,有以下几项
- —env LDAP_ORGANISATION=”xxx” :设置LDAP的组织者为“xxx”,本例配置为mylitboy
- —env LDAP_DOMAIN=”xxx.com” :设置LDAP域为“xxx.com”,本例配置为mylitboy.com
- —env LDAP_ADMIN_PASSWORD=”xxx” :设置LDAP的管理密码为“xxx”,本例为ldap123
- —detach : 后台运行容器,并返回容器ID
客户端安装
使用docker 安装 PHPLdapAdmin
运行镜像
docker run -d --privileged -p 10004:80 --name myphpldapadmin --env PHPLDAPADMIN_HTTPS=false --env PHPLDAPADMIN_LDAP_HOSTS=192.168.1.100 --detach osixia/phpldapadmin
命令解释:
- -privileged : 使用该参数,容器内的root拥有真正的root权限。否则,container内的root只是外部的一个普通用户权限。
- -p : 指定端口映射,格式为:主机(宿主)端口:容器端口
- —name : 为容器指定一个名称
- —env : 设置环境变量,有以下几项
- —env PHPLDAPADMIN_HTTPS=false : false为设置不开启https(默认是true),如果开启HTTPS,需要设置443端口映射:-p 8443:443,并采用https访问
- —env PHPLDAPADMIN_LDAP_HOSTS=192.168.1.100 :设置LDAP服务端地址,端口默认是389
- —env LDAP_ADMIN_PASSWORD=”xxx” :设置LDAP的管理密码为“xxx”,本例为ldap123
-
访问
通过访问http://192.168.1.100:10004 来管理,登陆界面:用户名:cn=admin,dc=xxx,dc=com
用户名 :cn=admin,dc=xxx,dc=com,本例为cn=admin,dc=mylitboy,dc=com
-
配置用户
登录管理界面
管理员登录客户端地址:http://192.168.1.100:10004 ,用户名(本例为cn=admin,dc=mylitboy,dc=com),密码(本例为ldap123),如下图所示
新建用户
选择管理域,点击右侧【Create a child entry】
点击【Generic::Postix Group】填写【Group】,点击【Create Object】
点击【commit】
选择已添加的Group,点击右侧【Create a child entry】
点击【Generic:User Account】填写相关信息,其中User ID即为登录的用户名,Password选择sha,填写完成,点击【Create Object】
点击【commit】
认证中心集成ldap用户名和密码示例 用户名:sudaqiang
-
增加用户属性
选择已有用户,点击【Add new attribute】
- 示例选择【Email】
千行接入ldap
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
yaml文件配置
spring:
ldap:
# ldap服务端地址
urls: ldap://192.168.1.100:389
# 跟目录
base: dc=mylitboy,dc=com
# 管理用户
username: cn=admin,dc=mylitboy,dc=com
# 密码
password: ldap123
构建实体
- 组织 ```java package com.gccloud.ldap.entity;
import com.alibaba.fastjson.JSONObject; import lombok.Data; import org.springframework.ldap.odm.annotations.Attribute; import org.springframework.ldap.odm.annotations.Entry; import org.springframework.ldap.odm.annotations.Id; import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
/**
- @Copyright 版权归科大国创技术中台所有
- @ClassName LdapOrg
- @Description 组织实体类
- @Author zhangtaozhir
@Date 2022/1/24 17:20 **/ @Data @Entry( base=”dc=mylitboy,dc=com”,objectClasses = “posixGroup”) public final class LdapOrgEntity { @Id //主键 private Name id; // 组织编码 @Attribute(name=”entryDN”) private String orgCode; // 组织名称 @Attribute(name = “cn”) private String orgName; // 组织编号,自动生成的属性 @Attribute(name = “gidNumber”) private String orgNum; public LdapOrgEntity(){
this.id = LdapUtils.emptyLdapName();
} public LdapOrgEntity(String id){
this.id = LdapUtils.newLdapName(id);
} public String getId() {
return id.toString();
} public Name setId(String id){
return LdapUtils.newLdapName(id);
}
@Override public String toString(){
return JSONObject.toJSONString(this);
} }
- **用户**
```java
package com.gccloud.ldap.entity;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
/**
* @Copyright 版权归科大国创技术中台所有
* @ClassName LdapUserEntity
* @Description 用户实体类
* @Author zhangtaozhir
* @Date 2022/1/24 17:40
**/
@Data
@Entry( base="cn=admin,dc=mylitboy,dc=com",objectClasses = "inetOrgPerson")
public class LdapUserEntity {
@Id
private Name id;
//用户登录名
@Attribute(name="uid")
private String username;
//用户真实姓名
@Attribute(name = "cn")
private String realName;
// 用户的姓
@Attribute(name = "sn")
private String surname;
// 邮箱
@Attribute(name="mail")
private String email;
// 用户的目录
@Attribute(name = "homedirectory")
private String homedirectory;
//组织号码
@Attribute(name = "gidnumber")
private String orgNum;
// 用户号码
@Attribute(name = "uidnumber")
private String userNum;
// 手机号
@Attribute(name = "mobile")
private String phone;
public LdapUserEntity(){
this.id = LdapUtils.emptyLdapName();
}
public LdapUserEntity(String id){
this.id = LdapUtils.newLdapName(id);
}
public String getId() {
return id.toString();
}
public Name setId(String id){
return LdapUtils.newLdapName(id);
}
@Override
public String toString(){
return JSONObject.toJSONString(this);
}
}
构建DTO对象
- 组织 ```java package com.gccloud.ldap.dto;
import com.alibaba.fastjson.JSONObject; import lombok.Data;
import java.io.Serializable;
/**
- @Copyright 版权归科大国创技术中台所有
- @ClassName LdapOrgDTO
- @Description 组织传输对象
- @Author zhangtaozhir
- @Date 2022/1/24 17:47
**/
@Data
public class LdapOrgDTO implements Serializable {
// 组织主键
private String id;
//组织编码
private String orgCode;
// 组织名称
private String orgName;
//组织编号
private String orgNum;
@Override
public String toString(){
} }return JSONObject.toJSONString(this);
- **用户**
```java
package com.gccloud.ldap.dto;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.Id;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import java.io.Serializable;
/**
* @Copyright 版权归科大国创技术中台所有
* @ClassName LdapUserDTO
* @Description 用户传输对象
* @Author zhangtaozhir
* @Date 2022/1/24 17:50
**/
@Data
public class LdapUserDTO implements Serializable {
// 用户主键
private String id;
//用户登录名
private String username;
//用户真实姓名
private String realName;
// 用户的姓
private String surname;
// 邮箱
@Attribute(name="mail")
private String email;
// 用户的目录
private String homedirectory;
//组织号码
private String orgNum;
// 用户号码
private String userNum;
// 手机号
private String phone;
@Override
public String toString(){
return JSONObject.toJSONString(this);
}
}
返回对象类R
package com.gccloud.ldap.vo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 定义Json响应数据
*
* @param <T>
*/
@Data
@Accessors(chain = true)
@NoArgsConstructor
public class R<T> implements Serializable {
private Integer code;
private String msg;
private T data;
public R(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
/**
* 成功
*
* @return
*/
public static <E> R<E> success(E data) {
return new R<E>(200, null, data);
}
public static <E> R<E> success() {
return new R<E>(200, null, null);
}
/**
* 失败
*
* @param msg
* @return
*/
public static R error(String msg) {
R result = new R();
result.setCode(500);
result.setMsg(msg);
return result;
}
/**
* 失败
*
* @param code
* @param msg
* @return
*/
public static R error(Integer code, String msg) {
R result = new R();
result.setCode(code);
result.setMsg(msg);
return result;
}
/**
* 失败
*
* @return
*/
public static R error() {
R result = new R();
result.setCode(500);
result.setMsg("未知异常,请联系管理员");
return result;
}
/**
* 添加返回的数据
*
* @param data
* @return
*/
public R<T> put(T data) {
this.data = data;
return this;
}
/**
* 是否正常
*
* @return
*/
@JsonIgnore
public boolean isSuccess() {
return this.code == 200;
}
@JsonIgnore
public boolean isError() {
return this.code != 200;
}
}
构建用户组织管理
- 构建组织接口
- 接口类 ```java package com.gccloud.ldap.service;
import com.gccloud.ldap.dto.LdapOrgDTO; import com.gccloud.ldap.entity.LdapOrgEntity;
import java.util.List;
/**
- @Copyright 版权归科大国创技术中台所有
- @ClassName ILdapOrgSerevice
- @Description 组织接口类
- @Author zhangtaozhir
- @Date 2022/1/24 18:29
**/
public interface ILdapOrgService {
List
getAll(); LdapOrgEntity getByOrgCode(String orgCode); List getByOrgNameMatch(String orgNameMatchStr); void add(LdapOrgDTO ldapOrgDTO); void update(LdapOrgDTO ldapOrgDTO); void delete(LdapOrgDTO ldapOrgDTO); }
- **接口实现类**
```java
package com.gccloud.ldap.service.impl;
import com.gccloud.ldap.dto.LdapOrgDTO;
import com.gccloud.ldap.entity.LdapOrgEntity;
import com.gccloud.ldap.service.ILdapOrgService;
import org.springframework.beans.BeanUtils;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.query.LdapQueryBuilder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* @Copyright 版权归科大国创技术中台所有
* @ClassName LdapOrgServiceImpl
* @Description 组织接口实现类
* @Author zhangtaozhir
* @Date 2022/1/24 18:31
**/
@Service
public class LdapOrgServiceImpl implements ILdapOrgService {
@Resource
private LdapTemplate template;
@Override
public List<LdapOrgEntity> getAll() {
Iterable<LdapOrgEntity> ldapOrgEntityIterable = template.findAll(LdapOrgEntity.class);
if(ldapOrgEntityIterable == null){
return null;
}
List<LdapOrgEntity> ldapOrgEntities = new ArrayList<>();
ldapOrgEntityIterable.forEach(p->ldapOrgEntities.add(p));
return ldapOrgEntities;
}
@Override
public LdapOrgEntity getByOrgCode(String orgCode) {
LdapOrgEntity ldapOrgEntity = template.findOne(LdapQueryBuilder.query().where("entryDN").is(orgCode), LdapOrgEntity.class);
return ldapOrgEntity;
}
@Override
public List<LdapOrgEntity> getByOrgNameMatch(String orgNameMatchStr) {
List<LdapOrgEntity> ldapOrgEntities =template.find(LdapQueryBuilder.query().where("cn").like(orgNameMatchStr), LdapOrgEntity.class);
return ldapOrgEntities;
}
@Override
public void add(LdapOrgDTO ldapOrgDTO) {
LdapOrgEntity entity = new LdapOrgEntity(ldapOrgDTO.getId());
BeanUtils.copyProperties(ldapOrgDTO,entity);
entity.setId(ldapOrgDTO.getId());
template.create(entity);
}
@Override
public void update(LdapOrgDTO ldapOrgDTO) {
LdapOrgEntity entity = new LdapOrgEntity(ldapOrgDTO.getId());
BeanUtils.copyProperties(ldapOrgDTO,entity);
entity.setId(ldapOrgDTO.getId());
template.update(entity);
}
@Override
public void delete(LdapOrgDTO ldapOrgDTO) {
LdapOrgEntity entity = new LdapOrgEntity(ldapOrgDTO.getId());
BeanUtils.copyProperties(ldapOrgDTO,entity);
entity.setId(ldapOrgDTO.getId());
template.delete(entity);
}
}
- 构建组织controller ```java package com.gccloud.ldap.controller;
import com.gccloud.ldap.dto.LdapOrgDTO; import com.gccloud.ldap.entity.LdapOrgEntity; import com.gccloud.ldap.service.ILdapOrgService; import com.gccloud.ldap.vo.R; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import java.util.List;
/**
- @Copyright 版权归科大国创技术中台所有
- @ClassName LdapUserController
- @Description 组织controller
- @Author zhangtaozhir
@Date 2022/1/24 18:55 **/ @RestController @RequestMapping(“/ldap/org”) public class LdapOrgController { @Resource private ILdapOrgService ldapOrgService; @GetMapping( “/getAll”) public R
- > getAll(){
List<LdapOrgEntity> ldapOrgEntities = ldapOrgService.getAll(); return R.success(ldapOrgEntities);
}
@GetMapping(“/getAllMatch/{orgName}”) public R
- > getAllMatch(@PathVariable String orgName){
List<LdapOrgEntity> ldapOrgEntities = ldapOrgService.getByOrgNameMatch(orgName); return R.success(ldapOrgEntities);
} @GetMapping(“/getOne/{orgCode}”) public R
getOne(@PathVariable String orgCode){ LdapOrgEntity ldapOrgEntity = ldapOrgService.getByOrgCode(orgCode); return R.success(ldapOrgEntity);
}
@PostMapping(value = “/add”,consumes = “application/json”, produces = “application/json”) public R
add(@RequestBody LdapOrgDTO ldapOrgDTO){ ldapOrgService.add(ldapOrgDTO); return R.success("成功");
}
@PostMapping(value = “/update”,consumes = “application/json”, produces = “application/json”) public R
update(@RequestBody LdapOrgDTO ldapOrgDTO){ ldapOrgService.update(ldapOrgDTO); return R.success("成功");
} @PostMapping(value = “/delete”,consumes = “application/json”, produces = “application/json”) public R
delete(@RequestBody LdapOrgDTO ldapOrgDTO){ ldapOrgService.delete(ldapOrgDTO); return R.success("成功");
} }
<a name="Rp6n1"></a>
### 构建用户管理
- **构建用户接口**
- **接口类**
```java
package com.gccloud.ldap.service;
import com.gccloud.ldap.dto.LdapUserDTO;
import com.gccloud.ldap.entity.LdapUserEntity;
import java.util.List;
/**
* @Copyright 版权归科大国创技术中台所有
* @ClassName ILdapUserService
* @Description 用户接口类
* @Author zhangtaozhir
* @Date 2022/1/24 18:41
**/
public interface ILdapUserService {
List<LdapUserEntity> getAll();
LdapUserEntity getByUsername(String username);
List<LdapUserEntity> getByUsernameMatch(String usernameMatchStr);
List<LdapUserEntity> getLdapUserEntityByOrgId(String orgId);
void add(LdapUserDTO ldapUserDTO);
void update(LdapUserDTO ldapUserDTO);
void delete(LdapUserDTO ldapUserDTO);
}
- 接口实现类 ```java package com.gccloud.ldap.service.impl;
import com.gccloud.ldap.dto.LdapUserDTO; import com.gccloud.ldap.entity.LdapUserEntity; import com.gccloud.ldap.service.ILdapUserService; import org.springframework.beans.BeanUtils; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.query.LdapQueryBuilder; import org.springframework.ldap.support.LdapUtils; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.naming.Name; import javax.naming.directory.SearchControls; import java.util.ArrayList; import java.util.List;
/**
- @Copyright 版权归科大国创技术中台所有
- @ClassName LdapUserServiceImpl
- @Description 用户接口实现类
- @Author zhangtaozhir
@Date 2022/1/24 18:44 **/ @Service public class LdapUserServiceImpl implements ILdapUserService { @Resource private LdapTemplate template; @Override public List
getAll() { Iterable<LdapUserEntity> ldapUserIterable = template.findAll(LdapUserEntity.class); if(ldapUserIterable == null){ return null; } List<LdapUserEntity> ldapUserEntities = new ArrayList<>(); ldapUserIterable.forEach(p->ldapUserEntities.add(p)); return ldapUserEntities;
}
@Override public LdapUserEntity getByUsername(String username) {
LdapUserEntity ldapUserEntity = template.findOne(LdapQueryBuilder.query().where("entryDN").is(username), LdapUserEntity.class); return ldapUserEntity;
}
@Override public List
getByUsernameMatch(String usernameMatchStr) { List<LdapUserEntity> ldapUserEntities =template.find(LdapQueryBuilder.query().where("uid").like(usernameMatchStr), LdapUserEntity.class); return ldapUserEntities;
}
@Override public List
getLdapUserEntityByOrgId(String orgId) { Name groupName = LdapUtils.newLdapName(orgId); List<LdapUserEntity> ldapUserEntities =template.findAll(groupName, new SearchControls(),LdapUserEntity.class); return ldapUserEntities;
}
@Override public void add(LdapUserDTO ldapUserDTO) {
LdapUserEntity entity = new LdapUserEntity(ldapUserDTO.getId()); BeanUtils.copyProperties(ldapUserDTO,entity); entity.setId(ldapUserDTO.getId()); template.create(entity);
}
@Override public void update(LdapUserDTO ldapUserDTO) {
LdapUserEntity entity = new LdapUserEntity(ldapUserDTO.getId()); BeanUtils.copyProperties(ldapUserDTO,entity); entity.setId(ldapUserDTO.getId()); template.update(entity);
}
@Override public void delete(LdapUserDTO ldapUserDTO) {
LdapUserEntity entity = new LdapUserEntity(ldapUserDTO.getId()); BeanUtils.copyProperties(ldapUserDTO,entity); entity.setId(ldapUserDTO.getId()); template.delete(entity);
} }
- **构建用户controller**
```java
package com.gccloud.ldap.controller;
import com.gccloud.ldap.dto.LdapUserDTO;
import com.gccloud.ldap.entity.LdapUserEntity;
import com.gccloud.ldap.service.ILdapUserService;
import com.gccloud.ldap.vo.R;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @Author zhangtaozhir
* @Description 用户controller
* @Date 19:07 2022/1/24
* @Param
* @return
**/
@RestController
@RequestMapping("/ldap/user")
public class LdapUserController {
@Resource
private ILdapUserService ldapUserService;
@GetMapping( "/getAll")
public R<List<LdapUserEntity>> getAll(){
List<LdapUserEntity> ldapUserEntities = ldapUserService.getAll();
return R.success(ldapUserEntities);
}
// @GetMapping(value = "/getAll/{username}",consumes = "application/json", produces = "application/json")
@GetMapping("/getAllMatch/{username}")
public R<List<LdapUserEntity>> getAllMatch(@PathVariable String username){
List<LdapUserEntity> ldapUserEntities = ldapUserService.getByUsernameMatch(username);
return R.success(ldapUserEntities);
}
@GetMapping("/getAllByOrgId/{orgId}")
public R<List<LdapUserEntity>> getAllByOrgId(@PathVariable String orgId){
List<LdapUserEntity> ldapUserEntities = ldapUserService.getLdapUserEntityByOrgId(orgId);
return R.success(ldapUserEntities);
}
@GetMapping("/getOne/{username}")
public R<LdapUserEntity> getOne(@PathVariable String username){
LdapUserEntity ldapUserEntity = ldapUserService.getByUsername(username);
return R.success(ldapUserEntity);
}
@PostMapping(value = "/add",consumes = "application/json", produces = "application/json")
public R<String> add(@RequestBody LdapUserDTO ldapUserDTO){
ldapUserService.add(ldapUserDTO);
return R.success("成功");
}
@PostMapping(value = "/update",consumes = "application/json", produces = "application/json")
public R<String> update(@RequestBody LdapUserDTO ldapUserDTO){
ldapUserService.update(ldapUserDTO);
return R.success("成功");
}
@PostMapping(value = "/delete",consumes = "application/json", produces = "application/json")
public R<String> delete(@RequestBody LdapUserDTO ldapUserDTO){
ldapUserService.delete(ldapUserDTO);
return R.success("成功");
}
}
调用示例
增加组织
- 接口地址:/ldap/org/add
- 请求方式: post
示例报文:
接口地址:/ldap/org/update
- 请求方式: post
示例报文:
接口地址:/ldap/org/getOne/{orgCode}
- 请求方式: get
示例报文:
- 请求方式: get
示例报文:
请求示例
http://localhost:8080/ldap/org/getAllMatch/qianxing*
响应示例
{ "code": 200, "msg": null, "data": [ { "id": "cn=qianxing,cn=gccloud", "orgCode": "cn=qianxing,cn=gccloud,dc=mylitboy,dc=com", "orgName": "qianxing", "orgNum": "505" }, { "id": "cn=qianxing1,cn=gccloud", "orgCode": "cn=qianxing1,cn=gccloud,dc=mylitboy,dc=com", "orgName": "qianxing1", "orgNum": "1506" } ] }
查询所有组织
- 请求方式: get
- 响应示例报文:
{ "code": 200, "msg": null, "data": [ { "id": "cn=gccloud", "orgCode": "cn=gccloud,dc=mylitboy,dc=com", "orgName": "gccloud", "orgNum": "500" }, { "id": "cn=rd", "orgCode": "cn=rd,dc=mylitboy,dc=com", "orgName": "rd", "orgNum": "501" }, { "id": "cn=jszt,cn=gccloud", "orgCode": "cn=jszt,cn=gccloud,dc=mylitboy,dc=com", "orgName": "jszt", "orgNum": "502" }, { "id": "cn=jszt,cn=rd", "orgCode": "cn=jszt,cn=rd,dc=mylitboy,dc=com", "orgName": "jszt", "orgNum": "503" }, { "id": "cn=qianxing,cn=gccloud", "orgCode": "cn=qianxing,cn=gccloud,dc=mylitboy,dc=com", "orgName": "qianxing", "orgNum": "505" }, { "id": "cn=qianxing1,cn=gccloud", "orgCode": "cn=qianxing1,cn=gccloud,dc=mylitboy,dc=com", "orgName": "qianxing1", "orgNum": "1506" } ] }
删除组织
- 接口地址:/ldap/org/delete
- 请求方式: post
示例报文:
接口地址:/ldap/user/add
- 请求方式: post
示例报文:
接口地址:/ldap/user/update
- 请求方式: post
示例报文:
接口地址:/ldap/user/getOne/{username}
- 请求方式: get
示例报文:
请求示例
http://localhost:8080/ldap/user/getOne/cn=zhang san2,cn=qianxing,cn=gccloud,dc=mylitboy,dc=com
响应示例
{ "code": 200, "msg": null, "data": { "id": "cn=zhang san2,cn=qianxing,cn=gccloud", "username": "zhangsan2", "realName": "zhang san2", "surname": "zhang", "email": "123456@163.com", "homedirectory": null, "orgNum": null, "userNum": null, "phone": "12345678901" } }
带条件查询用户
- 请求方式: get
示例报文:
请求示例
http://localhost:8080/ldap/user/getAllMatch/zhang*
响应示例
{ "code": 200, "msg": null, "data": [ { "id": "cn=zhang tao,cn=gccloud", "username": "zhangtao", "realName": "zhang tao", "surname": "tao", "email": null, "homedirectory": "/home/users/zhangtao", "orgNum": "500", "userNum": "1000", "phone": null }, { "id": "cn=zhangsan zhangsan,cn=gccloud", "username": "zhangsan", "realName": "zhangsan zhangsan", "surname": "zhangsan", "email": null, "homedirectory": "/home/users/zhangsan", "orgNum": "500", "userNum": "1002", "phone": null }, { "id": "cn=zhang san,cn=qianxing,cn=gccloud", "username": "zhangsan", "realName": "zhang san", "surname": "zhang", "email": null, "homedirectory": null, "orgNum": null, "userNum": null, "phone": null }, { "id": "cn=zhang san2,cn=qianxing,cn=gccloud", "username": "zhangsan2", "realName": "zhang san2", "surname": "zhang", "email": "123456@163.com", "homedirectory": null, "orgNum": null, "userNum": null, "phone": "12345678901" } ] }
查询所有用户
- 请求方式: get
响应示例报文:
{ "code": 200, "msg": null, "data": [ { "id": "cn=zhang tao,cn=gccloud", "username": "zhangtao", "realName": "zhang tao", "surname": "tao", "email": null, "homedirectory": "/home/users/zhangtao", "orgNum": "500", "userNum": "1000", "phone": null }, { "id": "cn=lisi lisi,cn=gccloud", "username": "lisi", "realName": "lisi lisi", "surname": "lisi", "email": null, "homedirectory": "/home/users/lisi", "orgNum": "500", "userNum": "1001", "phone": null }, { "id": "cn=zhangsan zhangsan,cn=gccloud", "username": "zhangsan", "realName": "zhangsan zhangsan", "surname": "zhangsan", "email": null, "homedirectory": "/home/users/zhangsan", "orgNum": "500", "userNum": "1002", "phone": null }, { "id": "cn=su daqiang,cn=rd", "username": "sudaqiang", "realName": "su daqiang", "surname": "daqiang", "email": "sudaqiang@suhou.com", "homedirectory": "/home/users/sudaqiang", "orgNum": "501", "userNum": "1003", "phone": "13013013013" }, { "id": "cn=zhang san,cn=qianxing,cn=gccloud", "username": "zhangsan", "realName": "zhang san", "surname": "zhang", "email": null, "homedirectory": null, "orgNum": null, "userNum": null, "phone": null }, { "id": "cn=zhang san2,cn=qianxing,cn=gccloud", "username": "zhangsan2", "realName": "zhang san2", "surname": "zhang", "email": "123456@163.com", "homedirectory": null, "orgNum": null, "userNum": null, "phone": "12345678901" } ] }
根据组织查询用户
- 请求方式: get
示例报文:
请求示例
http://localhost:8080/ldap/user/getAllByOrgId/cn=qianxing,cn=gccloud
响应示例
{ "code": 200, "msg": null, "data": [ { "id": "cn=zhang san,cn=qianxing,cn=gccloud", "username": "zhangsan", "realName": "zhang san", "surname": "zhang", "email": null, "homedirectory": null, "orgNum": null, "userNum": null, "phone": null }, { "id": "cn=zhang san2,cn=qianxing,cn=gccloud", "username": "zhangsan2", "realName": "zhang san2", "surname": "zhang", "email": "123456@163.com", "homedirectory": null, "orgNum": null, "userNum": null, "phone": "12345678901" } ] }
删除用户
接口地址:/ldap/user/delete
- 请求方式: post
示例报文: