https://github.com/noear/okldap
noear::专门为基于ldap账号做内网整合的简便客户端
https://github.com/noear/okldap
Last synced: 4 months ago
JSON representation
noear::专门为基于ldap账号做内网整合的简便客户端
- Host: GitHub
- URL: https://github.com/noear/okldap
- Owner: noear
- License: apache-2.0
- Created: 2021-08-25T07:36:03.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-11-23T02:10:47.000Z (over 1 year ago)
- Last Synced: 2025-09-03T16:47:10.366Z (9 months ago)
- Language: Java
- Homepage:
- Size: 67.4 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://mvnrepository.com/search?q=g:org.noear%20AND%20okldap)
[](https://license.coscl.org.cn/Apache2/)
[](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html)
[](https://jq.qq.com/?_wv=1027&k=kjB5JNiC)
## OkLdap
* 如果想在你的业务系统快速使用 LDAP 进行登录?
* 如果你的内网系统想使用接口快速创建员工的 LDAP 账号?
你可以试试 OkLdap。
OkLdap 是专门为基于 LDAP 账号做内网整合的简便客户端。
### 主要功能:
1. 快速的登录接口及示例
2. 修改密码的接口
3. 基于员工的管理接口(添人、减人、修改)
### 演示:
**引入依赖:**
```xml
org.noear
okldap
1.1.4
```
**配置:**
```yaml
#必要选项
ldap:
url: "ldap://127.0.0.1:389"
baseDn: "DC=company,DC=com"
bindDn: "cn=admin,dc=company,dc=com"
paasword: "123456"
userFilter: "cn=%s"
groupFilter: "cn=%s"
#Demo选项
demo:
limit:
groupCn: "manager"
```
**代码:(更多应用代码,可参考源码里的单元测试)**
```java
//应用入口
public class App {
public static void main(String[] args) {
Solon.start(App.class, args);
}
}
//Bean配置器
@Configuration
public class Config {
@Bean
public LdapClient ldapClient(@Inject("${ldap}") LdapClient ldapClient) {
return ldapClient;
}
}
//控制器示例
@Mapping("demo")
@Controller
public class DemoController {
@Inject
LdapClient ldapClient;
@Inject("${demo.limit.groupCn}")
String limitGroupCn;
/**
* 登录::
* */
@Post
@Mapping("login")
public Result login(String userName, String userPassword) {
try (LdapSession session = ldapClient.open()) {
LdapPerson person = session.findPersonOne(userName);
if (person == null) {
return Result.failure("用户不存在");
}
if (person.verifyPassword(userPassword) == false) {
return Result.failure("用户密码不对");
}
if (Utils.isNotEmpty(limitGroupCn)) {
if (person.inGroup(session.findGroupOne(limitGroupCn)) == false) {
return Result.failure("权限不够");
}
}
//可同步到本地用户库...
return Result.succeed();
}
}
/**
* 创建用户::
* */
@Post
@Mapping("create")
public Result create(String userName, String userPassword, String stageName, String realName) {
try (LdapSession session = ldapClient.open()) {
LdapPerson person = new LdapPerson();
person.setCn(userName);
person.setUserPassword(userPassword);
person.setDisplayName(stageName);
person.setGivenName(realName);
session.createPerson("employee", person);
}
return Result.succeed();
}
/**
* 修改用户::
* */
@Post
@Mapping("update")
public Result update(String userName, String stageName, String realName) {
try (LdapSession session = ldapClient.open()) {
LdapPerson person = session.findPersonOne(userName);
person.setDisplayName(stageName);
person.setGivenName(realName);
session.updatePerson(person);
}
return Result.succeed();
}
}
```