ldap-demo/README.md

243 lines
5.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# LDAP管理系统
一个基于Spring Boot的LDAP目录管理系统提供用户和组的完整管理功能。
## 功能特性
### 用户管理
- ✅ 创建、查看、编辑、删除用户
- ✅ 用户密码管理
- ✅ 用户信息搜索
- ✅ 批量用户操作
- ✅ 用户统计信息
### 组管理
- ✅ 创建、查看、编辑、删除组
- ✅ 组成员管理(添加/移除用户)
- ✅ 批量成员操作
- ✅ 组搜索功能
- ✅ 组统计信息
### Web界面
- ✅ 现代化的响应式Web UI
- ✅ 用户友好的操作界面
- ✅ 实时数据更新
- ✅ 错误处理和用户反馈
### REST API
- ✅ 完整的RESTful API接口
- ✅ 统一的响应格式
- ✅ 全局异常处理
- ✅ API文档和示例
## 技术栈
- **后端框架**: Spring Boot 3.2.0
- **LDAP集成**: Spring LDAP, Spring Security LDAP
- **Web框架**: Spring MVC
- **模板引擎**: Thymeleaf
- **前端**: Bootstrap 5 + Font Awesome
- **构建工具**: Maven
- **Java版本**: 17
## 快速开始
### 1. 环境要求
- Java 17+
- Maven 3.6+
- LDAP服务器如OpenLDAP、Active Directory等
### 2. 配置LDAP连接
编辑 `src/main/resources/application.yml` 文件:
```yaml
spring:
ldap:
urls: ldap://localhost:389 # 您的LDAP服务器地址
base: dc=example,dc=com # LDAP基础DN
username: cn=admin,dc=example,dc=com # 管理员DN
password: admin # 管理员密码
ldap:
config:
user-search-base: ou=people # 用户搜索基础
group-search-base: ou=groups # 组搜索基础
# 其他LDAP配置...
```
### 3. 构建和运行
```bash
# 克隆项目
git clone <repository-url>
cd ldap-demo
# 构建项目
mvn clean compile
# 运行项目
mvn spring-boot:run
```
### 4. 访问应用
- **Web界面**: http://localhost:8080/ldap-demo/web/
- **API接口**: http://localhost:8080/ldap-demo/api/
## API接口文档
### 用户管理 API
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | `/api/users` | 获取所有用户 |
| GET | `/api/users/{username}` | 获取指定用户 |
| POST | `/api/users` | 创建新用户 |
| PUT | `/api/users/{username}` | 更新用户信息 |
| DELETE | `/api/users/{username}` | 删除用户 |
| GET | `/api/users/search?keyword={keyword}` | 搜索用户 |
| PUT | `/api/users/{username}/password` | 更新用户密码 |
| POST | `/api/users/{username}/validate` | 验证用户密码 |
| POST | `/api/users/batch` | 批量创建用户 |
| GET | `/api/users/statistics` | 获取用户统计 |
### 组管理 API
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | `/api/groups` | 获取所有组 |
| GET | `/api/groups/{groupName}` | 获取指定组 |
| POST | `/api/groups` | 创建新组 |
| PUT | `/api/groups/{groupName}` | 更新组信息 |
| DELETE | `/api/groups/{groupName}` | 删除组 |
| GET | `/api/groups/search?keyword={keyword}` | 搜索组 |
| POST | `/api/groups/{groupName}/members/{username}` | 添加用户到组 |
| DELETE | `/api/groups/{groupName}/members/{username}` | 从组中移除用户 |
| GET | `/api/groups/{groupName}/members` | 获取组成员 |
| GET | `/api/groups/user/{username}` | 获取用户所属组 |
| POST | `/api/groups/{groupName}/members/batch` | 批量添加用户到组 |
| DELETE | `/api/groups/{groupName}/members/batch` | 批量从组中移除用户 |
| GET | `/api/groups/statistics` | 获取组统计 |
### API请求示例
#### 创建用户
```bash
curl -X POST http://localhost:8080/ldap-demo/api/users \
-H "Content-Type: application/json" \
-d '{
"username": "john.doe",
"password": "password123",
"commonName": "John Doe",
"surname": "Doe",
"givenName": "John",
"email": "john.doe@example.com",
"department": "IT",
"title": "Software Engineer"
}'
```
#### 创建组
```bash
curl -X POST http://localhost:8080/ldap-demo/api/groups \
-H "Content-Type: application/json" \
-d '{
"name": "developers",
"description": "Software Development Team",
"category": "department"
}'
```
#### 添加用户到组
```bash
curl -X POST http://localhost:8080/ldap-demo/api/groups/developers/members/john.doe
```
## 项目结构
```
src/
├── main/
│ ├── java/com/example/ldap/
│ │ ├── config/ # 配置类
│ │ ├── controller/ # 控制器
│ │ ├── dto/ # 数据传输对象
│ │ ├── entity/ # 实体类
│ │ ├── exception/ # 异常处理
│ │ └── service/ # 服务层
│ └── resources/
│ ├── templates/ # Thymeleaf模板
│ └── application.yml # 配置文件
└── test/ # 测试代码
```
## 自定义配置
### LDAP对象类配置
如果您的LDAP服务器使用不同的对象类可以在配置文件中修改
```yaml
ldap:
config:
user-object-class: inetOrgPerson # 用户对象类
group-object-class: groupOfNames # 组对象类
```
### 属性映射配置
可以根据您的LDAP架构调整属性映射
```yaml
ldap:
config:
group-member-attribute: member # 组成员属性
group-role-attribute: cn # 组角色属性
```
## 安全考虑
1. **密码加密**: 用户密码使用BCrypt加密存储
2. **LDAP连接**: 支持LDAP连接池配置
3. **API安全**: 可以集成Spring Security进行API认证
4. **输入验证**: 所有输入都经过验证和清理
## 故障排除
### 常见问题
1. **连接LDAP失败**
- 检查LDAP服务器地址和端口
- 验证管理员凭据
- 确认网络连接
2. **用户创建失败**
- 检查用户DN格式
- 验证必填字段
- 确认LDAP权限
3. **组管理错误**
- 验证组对象类配置
- 检查成员属性设置
### 日志配置
`application.yml` 中启用详细日志:
```yaml
logging:
level:
com.example.ldap: DEBUG
org.springframework.ldap: DEBUG
```
## 贡献
欢迎提交问题和功能请求!
## 许可证
本项目采用 MIT 许可证。