├── .gitignore ├── LICENSE ├── README.MD ├── cfg.json.example ├── cmd ├── auth.go ├── check.go ├── http.go ├── root.go ├── search.go ├── utils.go └── version.go ├── g ├── cfg.go └── const.go ├── go.mod ├── go.sum ├── http ├── controllers │ ├── authMulti.go │ ├── authSingle.go │ ├── default.go │ ├── health.go │ ├── searchFilter.go │ ├── searchMulti.go │ └── searchUser.go ├── http.go └── router.go ├── main.go └── models ├── funcs.go ├── ldap.go └── ldap_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | *.json 3 | *.exe 4 | *.csv -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [2018] [shanghai-edu & ECNU] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # ldap-test-tool 2 | 3 | 一个轻量级的 ldap 测试工具 4 | 5 | 支持: 6 | 7 | - ldap 认证 8 | - ldap 查询(默认基于用户) 9 | - 自定义 filter 的 ldap 查询 10 | - 多用户的批量 ldap 认证 11 | - 多用户的批量 ldap 查询 12 | - 支持批量查询结果输出到 csv 13 | - REST API 14 | 15 | ## 编译 16 | 17 | ```shell 18 | go get ./... 19 | go build 20 | ``` 21 | 22 | ## release 23 | 24 | 可以直接下载编译好的 release 版本 25 | 26 | 提供 win64 和 linux64 两个平台的可执行文件 27 | 28 | 29 | 30 | ## 配置文件 31 | 32 | 默认配置文件为目录下的 `cfg.json`,也可以使用 `-c` 或 `--config` 来加载自定义的配置文件。 33 | 34 | openldap 配置示例 35 | 36 | ```json 37 | { 38 | "ldap": { 39 | "addr": "ldap.example.org:389", 40 | "baseDn": "dc=example,dc=org", 41 | "bindDn": "cn=manager,dc=example,dc=org", 42 | "bindPass": "password", 43 | "authFilter": "(&(uid=%s))", 44 | "attributes": ["uid", "cn", "mail"], 45 | "tls": false, 46 | "startTLS": false 47 | }, 48 | "http": { 49 | "listen": "0.0.0.0:8888" 50 | } 51 | } 52 | ``` 53 | 54 | AD 配置示例 55 | 56 | ```json 57 | { 58 | "ldap": { 59 | "addr": "ad.example.org:389", 60 | "baseDn": "dc=example,dc=org", 61 | "bindDn": "manager@example.org", 62 | "bindPass": "password", 63 | "authFilter": "(&(sAMAccountName=%s))", 64 | "attributes": ["sAMAccountName", "displayName", "mail"], 65 | "tls": false, 66 | "startTLS": false 67 | }, 68 | "http": { 69 | "listen": "0.0.0.0:8888" 70 | } 71 | } 72 | ``` 73 | 74 | ## 命令体系 75 | 76 | 命令行部分使用 [cobra](github.com/spf13/cobra) 框架,可以使用 `help` 命令查看命令的使用方式 77 | 78 | ```shell 79 | # ./ldap-test-tool help 80 | ldap-test-tool is a simple tool for ldap test 81 | build by shanghai-edu. 82 | Complete documentation is available at github.com/shanghai-edu/ldap-test-tool 83 | 84 | Usage: 85 | ldap-test-tool [flags] 86 | ldap-test-tool [command] 87 | 88 | Available Commands: 89 | auth Auth Test 90 | check Check Cdap Connectivity 91 | help Help about any command 92 | http Enable a http server for ldap-test-tool 93 | search Search Test 94 | version Print the version number of ldap-test-tool 95 | 96 | Flags: 97 | -c, --config string load config file. default cfg.json (default "cfg.json") 98 | -h, --help help for ldap-test-tool 99 | 100 | Use "ldap-test-tool [command] --help" for more information about a command. 101 | ``` 102 | 103 | ## 健康检查 104 | 105 | ```shell 106 | # ./ldap-test-tool check 107 | Successed 108 | ``` 109 | 110 | ## 认证测试 111 | 112 | ```shell 113 | ./ldap-test-tool auth -h 114 | Auth Test 115 | 116 | Usage: 117 | ldap-test-tool auth [flags] 118 | ldap-test-tool auth [command] 119 | 120 | Available Commands: 121 | multi Multi Auth Test 122 | single Single Auth Test 123 | 124 | Flags: 125 | -h, --help help for auth 126 | 127 | Global Flags: 128 | -c, --config string load config file. default cfg.json (default "cfg.json") 129 | 130 | Use "ldap-test-tool auth [command] --help" for more information about a command. 131 | ``` 132 | 133 | ### 单用户测试 134 | 135 | 命令行说明 136 | 137 | ```shell 138 | Single Auth Test 139 | 140 | Usage: 141 | ldap-test-tool auth single [username] [password] [flags] 142 | 143 | Flags: 144 | -h, --help help for single 145 | 146 | Global Flags: 147 | -c, --config string load config file. default cfg.json (default "cfg.json") 148 | ``` 149 | 150 | 示例 151 | 152 | ```shell 153 | ./ldap-test-tool auth single qfeng 123456 154 | LDAP Auth Start 155 | ================================== 156 | 157 | qfeng auth test successed 158 | 159 | ================================== 160 | LDAP Auth Finished, Time Usage 47.821884ms 161 | ``` 162 | 163 | ### 批量测试 164 | 165 | 命令行说明 166 | 167 | ```shell 168 | # ./ldap-test-tool auth multi -h 169 | Multi Auth Test 170 | 171 | Usage: 172 | ldap-test-tool auth multi [filename] [flags] 173 | 174 | Flags: 175 | -h, --help help for multi 176 | 177 | Global Flags: 178 | -c, --config string load config file. default cfg.json (default "cfg.json") 179 | ``` 180 | 181 | 示例 182 | 183 | ```shell 184 | # cat authusers.txt 185 | qfeng,123456 186 | qfengtest,111111 187 | ``` 188 | 189 | 用户名和密码以逗号分隔(csv 风格) 190 | authusers.txt 中有两个用户,密码正确的 qfeng 和密码错误的 qfengtest 191 | 192 | ```shell 193 | # ./ldap-test-tool auth multi authusers.txt 194 | LDAP Multi Auth Start 195 | ================================== 196 | 197 | Successed count 1 198 | Failed count 1 199 | Failed users: 200 | -- User: qfengtest , Msg: Cannot find such user 201 | 202 | ================================== 203 | LDAP Multi Auth Finished, Time Usage 49.582994ms 204 | ``` 205 | 206 | ## 查询 207 | 208 | ```shell 209 | # ./ldap-test-tool search -h 210 | Search Test 211 | 212 | Usage: 213 | ldap-test-tool search [flags] 214 | ldap-test-tool search [command] 215 | 216 | Available Commands: 217 | filter Search By Filter 218 | multi Search Multi Users 219 | user Search Single User 220 | 221 | Flags: 222 | -h, --help help for search 223 | 224 | Global Flags: 225 | -c, --config string load config file. default cfg.json (default "cfg.json") 226 | 227 | Use "ldap-test-tool search [command] --help" for more information about a command. 228 | [root@wiki-qfeng ldap-test-tool]# 229 | ``` 230 | 231 | ### 单用户查询 232 | 233 | 命令行说明 234 | 235 | ```shell 236 | # ./ldap-test-tool search user -h 237 | Search Single User 238 | 239 | Usage: 240 | ldap-test-tool search user [username] [flags] 241 | 242 | Flags: 243 | -h, --help help for user 244 | 245 | Global Flags: 246 | -c, --config string load config file. default cfg.json (default "cfg.json") 247 | [root@wiki-qfeng ldap-test-tool]# 248 | ``` 249 | 250 | 示例 251 | 252 | ```shell 253 | # ./ldap-test-tool search user qfeng 254 | LDAP Search Start 255 | ================================== 256 | 257 | 258 | DN: uid=qfeng,ou=people,dc=example,dc=org 259 | Attributes: 260 | -- uid : qfeng 261 | -- cn : 冯骐测试 262 | -- mail : qfeng@example.org 263 | 264 | 265 | ================================== 266 | LDAP Search Finished, Time Usage 44.711268ms 267 | ``` 268 | 269 | PS: 如果属性有多值,将以 `;` 分割 270 | 271 | ### LDAP Filter 查询 272 | 273 | ```shell 274 | # ./ldap-test-tool search filter -h 275 | Search By Filter 276 | 277 | Usage: 278 | ldap-test-tool search filter [searchFilter] [flags] 279 | 280 | Flags: 281 | -h, --help help for filter 282 | 283 | Global Flags: 284 | -c, --config string load config file. default cfg.json (default "cfg.json") 285 | ``` 286 | 287 | 示例 288 | 289 | ```shell 290 | # ./ldap-test-tool search filter "(cn=*测试)" 291 | LDAP Search By Filter Start 292 | ================================== 293 | 294 | 295 | DN: uid=test1,ou=people,dc=example,dc=org 296 | Attributes: 297 | -- uid : test1 298 | -- cn : 一号测试 299 | -- mail : test1@example.org 300 | 301 | 302 | DN: uid=test2,ou=people,dc=example,dc=org 303 | Attributes: 304 | -- uid : test2 305 | -- cn : 二号测试 306 | -- mail : test2@example.org 307 | 308 | 309 | DN: uid=test3,ou=people,dc=example,dc=org 310 | Attributes: 311 | -- uid : test3 312 | -- cn : 三号测试 313 | -- mail : test3@example.org 314 | 315 | results count 3 316 | 317 | ================================== 318 | LDAP Search By Filter Finished, Time Usage 46.071833ms 319 | ``` 320 | 321 | ### 批量查询测试 322 | 323 | 命令行说明 324 | 325 | ```shell 326 | # ./ldap-test-tool search multi -h 327 | Search Multi Users 328 | 329 | Usage: 330 | ldap-test-tool search multi [filename] [flags] 331 | 332 | Flags: 333 | -f, --file output search to users.csv, failed search to failed.csv 334 | -h, --help help for multi 335 | 336 | Global Flags: 337 | -c, --config string load config file. default cfg.json (default "cfg.json") 338 | ``` 339 | 340 | 示例 341 | 342 | ```shell 343 | # cat searchusers.txt 344 | qfeng 345 | qfengtest 346 | nofounduser 347 | ``` 348 | 349 | searchuser.txt 中有三个用户,其中 nofounduser 是不存在的用户 350 | 351 | ```shell 352 | # ldap-test-tool.exe search multi .\searchusers.txt 353 | LDAP Multi Search Start 354 | ================================== 355 | 356 | Successed users: 357 | 358 | DN: uid=qfeng,ou=people,dc=example,dc=org 359 | Attributes: 360 | -- uid : qfeng 361 | -- cn : 冯骐 362 | -- mail : qfeng@example.org 363 | 364 | 365 | DN: uid=qfengtest,ou=people,dc=example,dc=org 366 | Attributes: 367 | -- uid : qfengtest 368 | -- cn : 冯骐测试 369 | -- mail : qfeng@example.org 370 | 371 | nofounduser : Cannot find such user 372 | 373 | Successed count 2 374 | Failed count 1 375 | 376 | ================================== 377 | LDAP Multi Search Finished, Time Usage 134.744ms 378 | ``` 379 | 380 | 当使用 `-f` 选项时,查询的结果将输出到 `csv` 中。`csv` 将以配置文件中 `attributes` 的属性作为 title。因此当使用 `-f` 选项时,`attributes` 不得为空。 381 | 382 | ```shell 383 | # ./ldap-test-tool search multi searchusers.txt -f 384 | LDAP Multi Search Start 385 | ================================== 386 | 387 | OutPut to csv successed 388 | 389 | ================================== 390 | LDAP Multi Search Finished, Time Usage 88.756956ms 391 | 392 | # ls | grep csv 393 | failed.csv 394 | users.csv 395 | ``` 396 | 397 | ## HTTP API 398 | 399 | HTTP API 部分使用 [beego](https://github.com/astaxie/beego) 框架 400 | 使用如下命令开启 HTTP API 401 | 402 | ```shell 403 | # ldap-test-tool.exe http 404 | 2018/03/12 14:30:25 [I] http server Running on http://0.0.0.0:8888 405 | ``` 406 | 407 | ### 健康状态 408 | 409 | 检测 ldap 健康状态 410 | 411 | ```shell 412 | # curl http://127.0.0.1:8888/api/v1/ldap/health 413 | { 414 | "msg": "ok", 415 | "success": true 416 | } 417 | ``` 418 | 419 | ### 查询用户 420 | 421 | 查询单个用户信息 422 | 423 | ```shell 424 | # curl http://127.0.0.1:8888/api/v1/ldap/search/user/qfeng 425 | { 426 | "user": { 427 | "dn": "uid=qfeng,ou=people,dc=example,dc=org", 428 | "attributes": { 429 | "cn": [ 430 | "冯骐" 431 | ], 432 | "mail": [ 433 | "qfeng" 434 | ], 435 | "uid": [ 436 | "qfeng" 437 | ] 438 | } 439 | }, 440 | "success": true 441 | } 442 | ``` 443 | 444 | ### Filter 查询 445 | 446 | 根据 LDAP Filter 查询 447 | 448 | ```shell 449 | # curl http://127.0.0.1:8888/api/v1/ldap/search/filter/\(cn=*测试\) 450 | { 451 | "results": [ 452 | { 453 | "dn": "uid=test1,ou=people,dc=example,dc=org", 454 | "attributes": { 455 | "cn": [ 456 | "一号测试" 457 | ], 458 | "mail": [ 459 | "test1@example.org" 460 | ], 461 | "uid": [ 462 | "test1" 463 | ] 464 | } 465 | }, 466 | { 467 | "dn": "uid=test2,ou=people,dc=example,dc=org", 468 | "attributes": { 469 | "cn": [ 470 | "二号测试" 471 | ], 472 | "mail": [ 473 | "test2@example.org" 474 | ], 475 | "uid": [ 476 | "test2" 477 | ] 478 | } 479 | }, 480 | { 481 | "dn": "uid=test3,ou=people,dc=example,dc=org", 482 | "attributes": { 483 | "cn": [ 484 | "三号测试" 485 | ], 486 | "mail": [ 487 | "test3@example.org" 488 | ], 489 | "uid": [ 490 | "test3" 491 | ] 492 | } 493 | }, 494 | ], 495 | "success": true 496 | } 497 | ``` 498 | 499 | ### 多用户查询 500 | 501 | 同时查询多个用户,以 `application/json` 方式发送请求数据,请求数据示例 502 | 503 | ```json 504 | ["qfeng", "qfengtest", "nofounduser"] 505 | ``` 506 | 507 | curl 示例 508 | 509 | ```shell 510 | # curl -X POST -H 'Content-Type:application/json' -d '["qfeng","qfengtest","nofounduser"]' http://127.0.0.1:8888/api/v1/ldap/search/multi 511 | { 512 | "success": true, 513 | "result": { 514 | "successed": 2, 515 | "failed": 1, 516 | "users": [ 517 | { 518 | "dn": "uid=qfeng,ou=people,dc=example,dc=org", 519 | "attributes": { 520 | "cn": [ 521 | "冯骐" 522 | ], 523 | "mail": [ 524 | "qfeng@example.org" 525 | ], 526 | "uid": [ 527 | "qfeng" 528 | ] 529 | } 530 | }, 531 | { 532 | "dn": "uid=qfengtest,ou=people,dc=example,dc=org", 533 | "attributes": { 534 | "cn": [ 535 | "冯骐测试" 536 | ], 537 | "mail": [ 538 | "qfeng@example.org" 539 | ], 540 | "uid": [ 541 | "qfengtest" 542 | ] 543 | } 544 | } 545 | ], 546 | "failed_messages": [ 547 | { 548 | "username": "nofounduser", 549 | "message": "Cannot find such user" 550 | } 551 | ] 552 | } 553 | } 554 | ``` 555 | 556 | ## 认证 557 | 558 | ### 单用户认证 559 | 560 | 单个用户认证测试,以 `application/json` 方式发送请求数据,请求数据示例 561 | 562 | ```json 563 | { 564 | "username": "qfeng", 565 | "password": "123456" 566 | } 567 | ``` 568 | 569 | curl 示例 570 | 571 | ```shell 572 | # curl -X POST -H 'Content-Type:application/json' -d '{"username":"qfeng","password":"123456"}' http://127.0.0.1:8888/api/v1/ldap/auth/single 573 | { 574 | "msg": "user 20150073 Auth Successed", 575 | "success": true 576 | } 577 | ``` 578 | 579 | ### 多用户认证 580 | 581 | 同时发起多个用户认证测试,以 `application/json` 方式发送请求数据,请求数据示例 582 | 583 | ```json 584 | [ 585 | { 586 | "username": "qfeng", 587 | "password": "123456" 588 | }, 589 | { 590 | "username": "qfengtest", 591 | "password": "1111111" 592 | } 593 | ] 594 | ``` 595 | 596 | curl 示例 597 | 598 | ```shell 599 | # curl -X POST -H 'Content-Type:application/json' -d '[{"username":"qfeng","password":"123456"},{"username":"qfengtest","password":"1111111"}]' http://127.0.0.1:8888/api/v1/ldap/auth/multi 600 | { 601 | "success": true, 602 | "result": { 603 | "successed": 1, 604 | "failed": 1, 605 | "failed_messages": [ 606 | { 607 | "username": "qfengtest", 608 | "message": "LDAP Result Code 49 \"Invalid Credentials\": " 609 | } 610 | ] 611 | } 612 | } 613 | ``` 614 | 615 | ## LICENSE 616 | 617 | Apache License 2.0 618 | -------------------------------------------------------------------------------- /cfg.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "ldap": { 3 | "addr": "ldap.example.org:389", 4 | "baseDn": "dc=example,dc=org", 5 | "bindDn": "cn=manager,dc=example,dc=org", 6 | "bindPass": "password", 7 | "authFilter": "(&(uid=%s))", 8 | "attributes": ["uid", "cn", "mail"], 9 | "tls": false, 10 | "startTLS": false 11 | }, 12 | "http": { 13 | "listen": "0.0.0.0:8888" 14 | } 15 | } -------------------------------------------------------------------------------- /cmd/auth.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | 8 | "github.com/shanghai-edu/ldap-test-tool/g" 9 | "github.com/shanghai-edu/ldap-test-tool/models" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | rootCmd.AddCommand(authCmd) 15 | authCmd.AddCommand(authUserCmd) 16 | authCmd.AddCommand(authMultiCmd) 17 | } 18 | 19 | var authCmd = &cobra.Command{ 20 | Use: "auth", 21 | Short: "Auth Test", 22 | Args: cobra.OnlyValidArgs, 23 | ValidArgs: []string{authUserCmd.Use, authMultiCmd.Use}, 24 | Run: func(cmd *cobra.Command, args []string) { 25 | fmt.Println(` 26 | multi Multi Auth Test 27 | single Single Auth Test 28 | `) 29 | }, 30 | } 31 | 32 | var authUserCmd = &cobra.Command{ 33 | Use: "single [username] [password]", 34 | Short: "Single Auth Test", 35 | Args: cobra.ExactArgs(2), 36 | Run: func(cmd *cobra.Command, args []string) { 37 | action := "Auth" 38 | 39 | username := args[0] 40 | password := args[1] 41 | 42 | startTime := time.Now() 43 | PrintStart(action) 44 | 45 | _, err := models.Single_Auth(g.Config().Ldap, username, password) 46 | 47 | if err != nil { 48 | fmt.Fprintf(os.Stderr, "%s auth test failed: %s \n", username, err.Error()) 49 | PrintEnd(action, startTime) 50 | return 51 | } 52 | fmt.Printf("%s auth test successed \n", username) 53 | PrintEnd(action, startTime) 54 | }, 55 | } 56 | 57 | var authMultiCmd = &cobra.Command{ 58 | Use: "multi [filename]", 59 | Short: "Multi Auth Test", 60 | Args: cobra.ExactArgs(1), 61 | Run: func(cmd *cobra.Command, args []string) { 62 | action := "Multi Auth" 63 | 64 | userlist := args[0] 65 | authUsers, err := g.GetUsers(userlist) 66 | if err != nil { 67 | fmt.Fprintf(os.Stderr, "Read file %s failed: %s \n", userlist, err.Error()) 68 | return 69 | } 70 | startTime := time.Now() 71 | PrintStart(action) 72 | 73 | res, err := models.Multi_Auth(g.Config().Ldap, authUsers) 74 | if err != nil { 75 | fmt.Fprintf(os.Stderr, "Multi Auth failed: %s \n", err.Error()) 76 | PrintEnd(action, startTime) 77 | return 78 | } 79 | fmt.Printf("Successed count %d \n", res.Successed) 80 | fmt.Printf("Failed count %d \n", res.Failed) 81 | fmt.Println("Failed users:") 82 | for _, failed_Message := range res.Failed_Messages { 83 | fmt.Printf(" -- User: %s , Msg: %s \n", failed_Message.Username, failed_Message.Message) 84 | } 85 | PrintEnd(action, startTime) 86 | }, 87 | } 88 | -------------------------------------------------------------------------------- /cmd/check.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/shanghai-edu/ldap-test-tool/g" 8 | "github.com/shanghai-edu/ldap-test-tool/models" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | rootCmd.AddCommand(checkCmd) 14 | } 15 | 16 | var checkCmd = &cobra.Command{ 17 | Use: "check", 18 | Short: "Check Cdap Connectivity", 19 | Long: `Check Cdap Connectivity`, 20 | Run: func(cmd *cobra.Command, args []string) { 21 | _, err := models.Health_Check(g.Config().Ldap) 22 | if err != nil { 23 | fmt.Fprintf(os.Stderr, "Failed: %v\n", err) 24 | return 25 | } 26 | fmt.Println("Successed") 27 | }, 28 | } 29 | -------------------------------------------------------------------------------- /cmd/http.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/shanghai-edu/ldap-test-tool/http" 5 | "github.com/spf13/cobra" 6 | ) 7 | 8 | func init() { 9 | rootCmd.AddCommand(httpCmd) 10 | } 11 | 12 | var httpCmd = &cobra.Command{ 13 | Use: "http", 14 | Short: "Enable a http server for ldap-test-tool", 15 | Long: `ldap-test-tool provide a restful api for ldap test`, 16 | Run: func(cmd *cobra.Command, args []string) { 17 | http.Start() 18 | }, 19 | } 20 | -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/shanghai-edu/ldap-test-tool/g" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | var cfg string 12 | 13 | func init() { 14 | cobra.OnInitialize(initConfig) 15 | rootCmd.PersistentFlags().StringVarP(&cfg, "config", "c", "cfg.json", "load config file. default cfg.json") 16 | } 17 | 18 | func initConfig() { 19 | g.ParseConfig(cfg) 20 | } 21 | 22 | var rootCmd = &cobra.Command{ 23 | Use: "ldap-test-tool", 24 | Short: "ldap-test-tool is a simple tool for ldap test", 25 | Long: `ldap-test-tool is a simple tool for ldap test 26 | build by shanghai-edu. 27 | Complete documentation is available at github.com/shanghai-edu/ldap-test-tool`, 28 | Run: func(cmd *cobra.Command, args []string) { 29 | fmt.Println(` 30 | auth Auth Test 31 | check Check Cdap Connectivity 32 | help Help about any command 33 | http Enable a http server for ldap-test-tool 34 | search Search Test 35 | version Print the version number of ldap-test-tool 36 | `) 37 | }, 38 | } 39 | 40 | func Execute() { 41 | 42 | if err := rootCmd.Execute(); err != nil { 43 | fmt.Println(err) 44 | os.Exit(1) 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /cmd/search.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | 8 | "github.com/shanghai-edu/ldap-test-tool/g" 9 | "github.com/shanghai-edu/ldap-test-tool/models" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | var csvFile bool 14 | 15 | func init() { 16 | searchMultiCmd.Flags().BoolVarP(&csvFile, "file", "f", false, "output search to users.csv, failed search to failed.csv") 17 | rootCmd.AddCommand(searchCmd) 18 | searchCmd.AddCommand(searchUserCmd) 19 | searchCmd.AddCommand(searchMultiCmd) 20 | searchCmd.AddCommand(searchFilterCmd) 21 | } 22 | 23 | var searchCmd = &cobra.Command{ 24 | Use: "search", 25 | Short: "Search Test", 26 | Args: cobra.OnlyValidArgs, 27 | ValidArgs: []string{searchUserCmd.Use, searchFilterCmd.Use, searchMultiCmd.Use}, 28 | Run: func(cmd *cobra.Command, args []string) { 29 | fmt.Println(` 30 | filter Search By Filter 31 | multi Search Multi Users 32 | user Search Single User 33 | `) 34 | }, 35 | } 36 | 37 | var searchUserCmd = &cobra.Command{ 38 | Use: "user [username]", 39 | Short: "Search Single User", 40 | Args: cobra.ExactArgs(1), 41 | Run: func(cmd *cobra.Command, args []string) { 42 | action := "Search" 43 | 44 | username := args[0] 45 | startTime := time.Now() 46 | PrintStart(action) 47 | 48 | result, err := models.Single_Search_User(g.Config().Ldap, username) 49 | 50 | if err != nil { 51 | fmt.Fprintf(os.Stderr, "%s Search failed: %s \n", username, err.Error()) 52 | PrintEnd(action, startTime) 53 | return 54 | } 55 | PrintSearchResult(result) 56 | 57 | PrintEnd(action, startTime) 58 | }, 59 | } 60 | 61 | var searchMultiCmd = &cobra.Command{ 62 | Use: "multi [filename]", 63 | Short: "Search Multi Users", 64 | Args: cobra.ExactArgs(1), 65 | Run: func(cmd *cobra.Command, args []string) { 66 | action := "Multi Search" 67 | 68 | userlist := args[0] 69 | searchUsers, err := g.GetLines(userlist) 70 | if err != nil { 71 | fmt.Fprintf(os.Stderr, "Read file %s failed: %s \n", userlist, err.Error()) 72 | return 73 | } 74 | startTime := time.Now() 75 | PrintStart(action) 76 | 77 | res, err := models.Multi_Search_User(g.Config().Ldap, searchUsers) 78 | 79 | if err != nil { 80 | fmt.Fprintf(os.Stderr, "Multi Search failed: %s \n", err.Error()) 81 | PrintEnd(action, startTime) 82 | return 83 | } 84 | if csvFile { 85 | err = WriteUsersToCsv(res.Users, g.USERS_CSV) 86 | if err != nil { 87 | fmt.Fprintf(os.Stderr, "Open file %s failed: \n", g.USERS_CSV) 88 | return 89 | } 90 | if len(res.Failed_Messages) > 0 { 91 | err = WriteFailsToCsv(res.Failed_Messages, g.FAILED_CSV) 92 | if err != nil { 93 | fmt.Fprintf(os.Stderr, "Open file %s failed: \n", g.FAILED_CSV) 94 | return 95 | } 96 | } 97 | fmt.Println("OutPut to csv successed") 98 | PrintEnd(action, startTime) 99 | return 100 | } 101 | fmt.Println("Successed users:") 102 | for _, user := range res.Users { 103 | PrintSearchResult(user) 104 | } 105 | 106 | for _, failed_Message := range res.Failed_Messages { 107 | fmt.Printf("%s : %s \n", failed_Message.Username, failed_Message.Message) 108 | } 109 | fmt.Println("") 110 | fmt.Printf("Successed count %d \n", res.Successed) 111 | fmt.Printf("Failed count %d \n", res.Failed) 112 | 113 | PrintEnd(action, startTime) 114 | 115 | }, 116 | } 117 | 118 | var searchFilterCmd = &cobra.Command{ 119 | Use: "filter [searchFilter]", 120 | Short: "Search By Filter", 121 | Args: cobra.ExactArgs(1), 122 | Run: func(cmd *cobra.Command, args []string) { 123 | action := "Search By Filter" 124 | 125 | filter := args[0] 126 | startTime := time.Now() 127 | PrintStart(action) 128 | 129 | results, err := models.Single_Search(g.Config().Ldap, filter) 130 | 131 | if err != nil { 132 | fmt.Printf("%s Search failed: %s \n", filter, err.Error()) 133 | PrintEnd(action, startTime) 134 | return 135 | } 136 | for _, res := range results { 137 | PrintSearchResult(res) 138 | } 139 | fmt.Println("results count ", len(results)) 140 | PrintEnd(action, startTime) 141 | }, 142 | } 143 | -------------------------------------------------------------------------------- /cmd/utils.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "encoding/csv" 5 | "fmt" 6 | "os" 7 | "strings" 8 | "time" 9 | 10 | "github.com/shanghai-edu/ldap-test-tool/g" 11 | "github.com/shanghai-edu/ldap-test-tool/models" 12 | ) 13 | 14 | func PrintStart(action string) { 15 | fmt.Printf("LDAP %s Start \n", action) 16 | fmt.Println("==================================") 17 | fmt.Println("") 18 | } 19 | 20 | func PrintEnd(action string, startTime time.Time) { 21 | endTime := time.Now() 22 | fmt.Println("") 23 | fmt.Println("==================================") 24 | fmt.Printf("LDAP %s Finished, Time Usage %s \n", action, endTime.Sub(startTime)) 25 | } 26 | 27 | func PrintSearchResult(result models.LDAP_RESULT) { 28 | fmt.Println("") 29 | fmt.Printf("DN: %s \n", result.DN) 30 | fmt.Println("Attributes:") 31 | longestKeyLenth := getLongestKeyLen(result.Attributes) 32 | for key, value := range result.Attributes { 33 | if len(key) < longestKeyLenth { 34 | key = addSpace(key, (longestKeyLenth - len(key))) 35 | } 36 | valueString := strings.Join(value, ";") 37 | fmt.Printf(" -- %s : %s \n", key, valueString) 38 | } 39 | fmt.Println("") 40 | 41 | } 42 | 43 | func inArray(str string, array []string) bool { 44 | for _, s := range array { 45 | if s == str { 46 | return true 47 | } 48 | } 49 | return false 50 | } 51 | 52 | func getLongestKeyLen(m map[string][]string) int { 53 | l := 0 54 | for key, _ := range m { 55 | if len(key) > l { 56 | l = len(key) 57 | } 58 | } 59 | return l 60 | } 61 | 62 | func addSpace(s string, l int) string { 63 | for i := 0; i < l; i++ { 64 | s = s + " " 65 | } 66 | return s 67 | } 68 | 69 | func WriteUsersToCsv(users []models.LDAP_RESULT, filename string) (err error) { 70 | csvFile, err := os.Create(filename) 71 | if err != nil { 72 | return 73 | } 74 | defer csvFile.Close() 75 | csvFile.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM 76 | writer := csv.NewWriter(csvFile) 77 | title := make([]string, len(g.Config().Ldap.Attributes)+1) 78 | title[0] = "DN" 79 | for index, value := range g.Config().Ldap.Attributes { 80 | title[index+1] = value 81 | } 82 | writer.Write(title) 83 | for _, user := range users { 84 | s := make([]string, len(g.Config().Ldap.Attributes)+1) 85 | s[0] = user.DN 86 | for key, value := range user.Attributes { 87 | valueString := strings.Join(value, ";") 88 | for i, v := range title { 89 | if key == v { 90 | s[i] = valueString 91 | } 92 | } 93 | } 94 | writer.Write(s) 95 | } 96 | writer.Flush() 97 | return 98 | } 99 | 100 | func WriteFailsToCsv(msgs []models.Failed_Message, filename string) (err error) { 101 | csvFile, err := os.Create(filename) 102 | if err != nil { 103 | return 104 | } 105 | defer csvFile.Close() 106 | csvFile.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM 107 | writer := csv.NewWriter(csvFile) 108 | title := make([]string, 2) 109 | title[0] = "username" 110 | title[1] = "message" 111 | writer.Write(title) 112 | for _, msg := range msgs { 113 | s := make([]string, 2) 114 | s[0] = msg.Username 115 | s[1] = msg.Message 116 | writer.Write(s) 117 | } 118 | writer.Flush() 119 | return 120 | } 121 | -------------------------------------------------------------------------------- /cmd/version.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/shanghai-edu/ldap-test-tool/g" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rootCmd.AddCommand(versionCmd) 12 | } 13 | 14 | var versionCmd = &cobra.Command{ 15 | Use: "version", 16 | Short: "Print the version number of ldap-test-tool", 17 | Long: `All software has versions. This is ldap-test-tool's`, 18 | Run: func(cmd *cobra.Command, args []string) { 19 | fmt.Println("ldap-test-tool version : ", g.VERSION) 20 | }, 21 | } 22 | -------------------------------------------------------------------------------- /g/cfg.go: -------------------------------------------------------------------------------- 1 | package g 2 | 3 | import ( 4 | "encoding/json" 5 | "io/ioutil" 6 | "log" 7 | "strings" 8 | "sync" 9 | 10 | "github.com/shanghai-edu/ldap-test-tool/models" 11 | "github.com/toolkits/file" 12 | ) 13 | 14 | type GlobalConfig struct { 15 | Ldap *models.LDAP_CONFIG `jspn:"ldap"` 16 | Http *HttpConfig `json:"http"` 17 | } 18 | 19 | type HttpConfig struct { 20 | Listen string `json:"listen"` 21 | } 22 | 23 | var ( 24 | ConfigFile string 25 | config *GlobalConfig 26 | lock = new(sync.RWMutex) 27 | ) 28 | 29 | func Config() *GlobalConfig { 30 | lock.RLock() 31 | defer lock.RUnlock() 32 | return config 33 | } 34 | 35 | func GetLines(filePath string) ([]string, error) { 36 | result := []string{} 37 | b, err := ioutil.ReadFile(filePath) 38 | if err != nil { 39 | return result, err 40 | } 41 | s := string(b) 42 | for _, lineStr := range strings.Split(s, "\n") { 43 | lineStr = strings.TrimSpace(lineStr) 44 | if lineStr == "" { 45 | continue 46 | } 47 | result = append(result, lineStr) 48 | } 49 | return result, nil 50 | } 51 | 52 | func GetUsers(filePath string) ([]models.User, error) { 53 | var user models.User 54 | users := []models.User{} 55 | 56 | lines, err := GetLines(filePath) 57 | if err != nil { 58 | return users, err 59 | } 60 | 61 | for _, line := range lines { 62 | if strings.Contains(line, ",") { 63 | strList := strings.Split(line, ",") 64 | user.Username = strList[0] 65 | user.Password = strList[1] 66 | users = append(users, user) 67 | } 68 | } 69 | return users, nil 70 | } 71 | func ParseConfig(cfg string) { 72 | if cfg == "" { 73 | log.Fatalln("use -c to specify configuration file") 74 | } 75 | 76 | if !file.IsExist(cfg) { 77 | log.Fatalln("config file:", cfg, "is not existent. maybe you need `mv cfg.example.json cfg.json`") 78 | } 79 | 80 | ConfigFile = cfg 81 | 82 | configContent, err := file.ToTrimString(cfg) 83 | if err != nil { 84 | log.Fatalln("read config file:", cfg, "fail:", err) 85 | } 86 | 87 | var c GlobalConfig 88 | err = json.Unmarshal([]byte(configContent), &c) 89 | if err != nil { 90 | log.Fatalln("parse config file:", cfg, "fail:", err) 91 | } 92 | 93 | lock.Lock() 94 | defer lock.Unlock() 95 | 96 | config = &c 97 | 98 | } 99 | -------------------------------------------------------------------------------- /g/const.go: -------------------------------------------------------------------------------- 1 | package g 2 | 3 | const ( 4 | VERSION = "0.2.1" 5 | USERS_CSV = "users.csv" 6 | FAILED_CSV = "failed.csv" 7 | ) 8 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/shanghai-edu/ldap-test-tool 2 | 3 | go 1.20 4 | 5 | require github.com/astaxie/beego v1.12.3 6 | 7 | require ( 8 | github.com/inconshreveable/mousetrap v1.0.1 // indirect 9 | github.com/spf13/pflag v1.0.5 // indirect 10 | gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect 11 | ) 12 | 13 | require ( 14 | github.com/beorn7/perks v1.0.1 // indirect 15 | github.com/cespare/xxhash/v2 v2.1.1 // indirect 16 | github.com/golang/protobuf v1.4.2 // indirect 17 | github.com/hashicorp/golang-lru v0.5.4 // indirect 18 | github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect 19 | github.com/prometheus/client_golang v1.7.0 // indirect 20 | github.com/prometheus/client_model v0.2.0 // indirect 21 | github.com/prometheus/common v0.10.0 // indirect 22 | github.com/prometheus/procfs v0.1.3 // indirect 23 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect 24 | github.com/spf13/cobra v1.6.1 25 | github.com/toolkits/file v0.0.0-20160325033739-a5b3c5147e07 26 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect 27 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect 28 | golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 // indirect 29 | golang.org/x/text v0.3.0 // indirect 30 | google.golang.org/protobuf v1.23.0 // indirect 31 | gopkg.in/ldap.v2 v2.5.1 32 | gopkg.in/yaml.v2 v2.2.8 // indirect 33 | ) 34 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= 3 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 4 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 5 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 6 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 7 | github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= 8 | github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk= 9 | github.com/astaxie/beego v1.12.3 h1:SAQkdD2ePye+v8Gn1r4X6IKZM1wd28EyUOVQ3PDSOOQ= 10 | github.com/astaxie/beego v1.12.3/go.mod h1:p3qIm0Ryx7zeBHLljmd7omloyca1s4yu1a8kM1FkpIA= 11 | github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ= 12 | github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU= 13 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 14 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 15 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 16 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 17 | github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60= 18 | github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE= 19 | github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= 20 | github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 21 | github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= 22 | github.com/couchbase/go-couchbase v0.0.0-20200519150804-63f3cdb75e0d/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U= 23 | github.com/couchbase/gomemcached v0.0.0-20200526233749-ec430f949808/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c= 24 | github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs= 25 | github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 26 | github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY= 27 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 28 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 29 | github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= 30 | github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI= 31 | github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= 32 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 33 | github.com/glendc/gopher-json v0.0.0-20170414221815-dc4743023d0c/go.mod h1:Gja1A+xZ9BoviGJNA2E9vFkPjjsl+CoJxSXiQM1UXtw= 34 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 35 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 36 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 37 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 38 | github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= 39 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 40 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 41 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 42 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 43 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 44 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 45 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 46 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 47 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 48 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 49 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 50 | github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= 51 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 52 | github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 53 | github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 54 | github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= 55 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 56 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 57 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 58 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 59 | github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= 60 | github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= 61 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 62 | github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= 63 | github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 64 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 65 | github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 66 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 67 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 68 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 69 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 70 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 71 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 72 | github.com/ledisdb/ledisdb v0.0.0-20200510135210-d35789ec47e6/go.mod h1:n931TsDuKuq+uX4v1fulaMbA/7ZLLhjc85h7chZGBCQ= 73 | github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= 74 | github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= 75 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 76 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 77 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 78 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 79 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 80 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 81 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 82 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 83 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 84 | github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= 85 | github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= 86 | github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 87 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 88 | github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= 89 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 90 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 91 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 92 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 93 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 94 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 95 | github.com/prometheus/client_golang v1.7.0 h1:wCi7urQOGBsYcQROHqpUUX4ct84xp40t9R9JX0FuA/U= 96 | github.com/prometheus/client_golang v1.7.0/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= 97 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 98 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 99 | github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= 100 | github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 101 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 102 | github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc= 103 | github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= 104 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 105 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 106 | github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= 107 | github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= 108 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 109 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo= 110 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg= 111 | github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw= 112 | github.com/siddontang/goredis v0.0.0-20150324035039-760763f78400/go.mod h1:DDcKzU3qCuvj/tPnimWSsZZzvk9qvkvrIL5naVBPh5s= 113 | github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA= 114 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 115 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 116 | github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= 117 | github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= 118 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 119 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 120 | github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE= 121 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 122 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 123 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 124 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 125 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 126 | github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= 127 | github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= 128 | github.com/toolkits/file v0.0.0-20160325033739-a5b3c5147e07 h1:d/VUIMNTk65Xz69htmRPNfjypq2uNRqVsymcXQu6kKk= 129 | github.com/toolkits/file v0.0.0-20160325033739-a5b3c5147e07/go.mod h1:FbXpUxsx5in7z/OrWFDdhYetOy3/VGIJsVHN9G7RUPA= 130 | github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= 131 | github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc= 132 | github.com/yuin/gopher-lua v0.0.0-20171031051903-609c9cd26973/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU= 133 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 134 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 135 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= 136 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 137 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 138 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 139 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 140 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 141 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= 142 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 143 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 144 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 145 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 146 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 147 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 148 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 149 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 150 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 151 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 152 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 153 | golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 154 | golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 155 | golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= 156 | golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 157 | golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 158 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 159 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 160 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 161 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 162 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 163 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 164 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 165 | google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= 166 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 167 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 168 | gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d h1:TxyelI5cVkbREznMhfzycHdkp5cLA7DpE+GKjSslYhM= 169 | gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw= 170 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 171 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 172 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 173 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 174 | gopkg.in/ldap.v2 v2.5.1 h1:wiu0okdNfjlBzg6UWvd1Hn8Y+Ux17/u/4nlk4CQr6tU= 175 | gopkg.in/ldap.v2 v2.5.1/go.mod h1:oI0cpe/D7HRtBQl8aTg+ZmzFUAvu4lsv3eLXMLGFxWk= 176 | gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= 177 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 178 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 179 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 180 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 181 | gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 182 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 183 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 184 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 185 | -------------------------------------------------------------------------------- /http/controllers/authMulti.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/astaxie/beego" 7 | "github.com/shanghai-edu/ldap-test-tool/g" 8 | "github.com/shanghai-edu/ldap-test-tool/models" 9 | ) 10 | 11 | type AuthMultiController struct { 12 | beego.Controller 13 | } 14 | 15 | type MsgResult struct { 16 | Msg string `json:"msg"` 17 | Success bool `json:"success"` 18 | } 19 | 20 | type AuthResult struct { 21 | Success bool `json:"success"` 22 | Result models.Multi_Auth_Result `json:"result"` 23 | } 24 | 25 | func (this *AuthMultiController) Post() { 26 | var userlist []models.User 27 | var msgResult MsgResult 28 | var authResult AuthResult 29 | err := json.Unmarshal(this.Ctx.Input.RequestBody, &userlist) 30 | if err != nil { 31 | msgResult.Msg = err.Error() 32 | this.Data["json"] = msgResult 33 | this.ServeJSON() 34 | return 35 | } 36 | 37 | result, err := models.Multi_Auth(g.Config().Ldap, userlist) 38 | 39 | if err != nil { 40 | msgResult.Msg = err.Error() 41 | this.Data["json"] = msgResult 42 | this.ServeJSON() 43 | return 44 | } 45 | authResult.Success = true 46 | authResult.Result = result 47 | this.Data["json"] = authResult 48 | this.ServeJSON() 49 | } 50 | -------------------------------------------------------------------------------- /http/controllers/authSingle.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "fmt" 5 | 6 | "encoding/json" 7 | 8 | "github.com/astaxie/beego" 9 | "github.com/shanghai-edu/ldap-test-tool/g" 10 | "github.com/shanghai-edu/ldap-test-tool/models" 11 | ) 12 | 13 | type AuthSingleController struct { 14 | beego.Controller 15 | } 16 | 17 | func (this *AuthSingleController) Post() { 18 | var user models.User 19 | var msgResult MsgResult 20 | err := json.Unmarshal(this.Ctx.Input.RequestBody, &user) 21 | if err != nil { 22 | msgResult.Msg = err.Error() 23 | this.Data["json"] = msgResult 24 | this.ServeJSON() 25 | return 26 | } 27 | if user.Username == "" || user.Password == "" { 28 | msgResult.Msg = "Missing username or password" 29 | this.Data["json"] = msgResult 30 | this.ServeJSON() 31 | return 32 | } 33 | 34 | success, err := models.Single_Auth(g.Config().Ldap, user.Username, user.Password) 35 | 36 | if err != nil { 37 | msgResult.Msg = err.Error() 38 | 39 | } else { 40 | msgResult.Msg = fmt.Sprintf("user %s Auth Successed", user.Username) 41 | } 42 | msgResult.Success = success 43 | this.Data["json"] = msgResult 44 | this.ServeJSON() 45 | } 46 | -------------------------------------------------------------------------------- /http/controllers/default.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "github.com/astaxie/beego" 5 | ) 6 | 7 | type MainController struct { 8 | beego.Controller 9 | } 10 | 11 | func (this *MainController) Get() { 12 | this.Ctx.Output.Body([]byte("ldap test api")) 13 | } 14 | -------------------------------------------------------------------------------- /http/controllers/health.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "github.com/astaxie/beego" 5 | "github.com/shanghai-edu/ldap-test-tool/g" 6 | "github.com/shanghai-edu/ldap-test-tool/models" 7 | ) 8 | 9 | type HealthController struct { 10 | beego.Controller 11 | } 12 | 13 | func (this *HealthController) Get() { 14 | var msgResult MsgResult 15 | 16 | success, err := models.Health_Check(g.Config().Ldap) 17 | 18 | if err != nil { 19 | msgResult.Msg = err.Error() 20 | 21 | } else { 22 | msgResult.Msg = "ok" 23 | } 24 | msgResult.Success = success 25 | this.Data["json"] = msgResult 26 | this.ServeJSON() 27 | } 28 | -------------------------------------------------------------------------------- /http/controllers/searchFilter.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "github.com/astaxie/beego" 5 | "github.com/shanghai-edu/ldap-test-tool/g" 6 | "github.com/shanghai-edu/ldap-test-tool/models" 7 | ) 8 | 9 | type SearchFilterController struct { 10 | beego.Controller 11 | } 12 | 13 | type SearchResult struct { 14 | Results []models.LDAP_RESULT `json:"results"` 15 | Success bool `json:"success"` 16 | } 17 | 18 | func (this *SearchFilterController) Get() { 19 | searchFilter := this.Ctx.Input.Param(":filter") 20 | results, err := models.Single_Search(g.Config().Ldap, searchFilter) 21 | if err != nil { 22 | var failedResult MsgResult 23 | failedResult.Msg = err.Error() 24 | this.Data["json"] = failedResult 25 | } else { 26 | var successResult SearchResult 27 | successResult.Success = true 28 | successResult.Results = results 29 | this.Data["json"] = successResult 30 | } 31 | this.ServeJSON() 32 | } 33 | -------------------------------------------------------------------------------- /http/controllers/searchMulti.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/astaxie/beego" 7 | "github.com/shanghai-edu/ldap-test-tool/g" 8 | "github.com/shanghai-edu/ldap-test-tool/models" 9 | ) 10 | 11 | type SearchMultiController struct { 12 | beego.Controller 13 | } 14 | 15 | type SearchMultiResult struct { 16 | Success bool `json:"success"` 17 | Result models.Multi_Search_User_Result `json:"result"` 18 | } 19 | 20 | func (this *SearchMultiController) Post() { 21 | var msgResult MsgResult 22 | var searchMultiResult SearchMultiResult 23 | var userlist []string 24 | err := json.Unmarshal(this.Ctx.Input.RequestBody, &userlist) 25 | if err != nil { 26 | msgResult.Msg = err.Error() 27 | this.Data["json"] = msgResult 28 | this.ServeJSON() 29 | return 30 | } 31 | 32 | result, err := models.Multi_Search_User(g.Config().Ldap, userlist) 33 | if err != nil { 34 | msgResult.Msg = err.Error() 35 | this.Data["json"] = msgResult 36 | this.ServeJSON() 37 | return 38 | } 39 | searchMultiResult.Success = true 40 | searchMultiResult.Result = result 41 | this.Data["json"] = searchMultiResult 42 | this.ServeJSON() 43 | } 44 | -------------------------------------------------------------------------------- /http/controllers/searchUser.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "github.com/astaxie/beego" 5 | "github.com/shanghai-edu/ldap-test-tool/g" 6 | "github.com/shanghai-edu/ldap-test-tool/models" 7 | ) 8 | 9 | type SearchUserController struct { 10 | beego.Controller 11 | } 12 | 13 | type SearchUserResult struct { 14 | User models.LDAP_RESULT `json:"user"` 15 | Success bool `json:"success"` 16 | } 17 | 18 | func (this *SearchUserController) Get() { 19 | 20 | username := this.Ctx.Input.Param(":username") 21 | user, err := models.Single_Search_User(g.Config().Ldap, username) 22 | if err != nil { 23 | var failedResult MsgResult 24 | failedResult.Msg = err.Error() 25 | this.Data["json"] = failedResult 26 | } else { 27 | var successResult SearchUserResult 28 | successResult.Success = true 29 | successResult.User = user 30 | this.Data["json"] = successResult 31 | } 32 | this.ServeJSON() 33 | } 34 | -------------------------------------------------------------------------------- /http/http.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "github.com/astaxie/beego" 5 | "github.com/shanghai-edu/ldap-test-tool/g" 6 | ) 7 | 8 | func Start() { 9 | beego.BConfig.CopyRequestBody = true 10 | ConfigRouters() 11 | beego.Run(g.Config().Http.Listen) 12 | } 13 | -------------------------------------------------------------------------------- /http/router.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "github.com/astaxie/beego" 5 | "github.com/shanghai-edu/ldap-test-tool/http/controllers" 6 | ) 7 | 8 | func ConfigRouters() { 9 | beego.Router("/api/v1/ldap/", &controllers.MainController{}) 10 | beego.Router("/api/v1/ldap/health", &controllers.HealthController{}) 11 | beego.Router("/api/v1/ldap/search/filter/:filter", &controllers.SearchFilterController{}) 12 | beego.Router("/api/v1/ldap/search/user/:username", &controllers.SearchUserController{}) 13 | beego.Router("/api/v1/ldap/search/multi", &controllers.SearchMultiController{}) 14 | beego.Router("/api/v1/ldap/auth/single", &controllers.AuthSingleController{}) 15 | beego.Router("/api/v1/ldap/auth/multi", &controllers.AuthMultiController{}) 16 | } 17 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/shanghai-edu/ldap-test-tool/cmd" 5 | ) 6 | 7 | func main() { 8 | cmd.Execute() 9 | } 10 | -------------------------------------------------------------------------------- /models/funcs.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type User struct { 4 | Username string `json:"username"` 5 | Password string `json:"password"` 6 | } 7 | 8 | type Multi_Auth_Result struct { 9 | Successed int `json:"successed"` 10 | Failed int `json:"failed"` 11 | Failed_Messages []Failed_Message `json:"failed_messages"` 12 | } 13 | 14 | type Multi_Search_User_Result struct { 15 | Successed int `json:"successed"` 16 | Failed int `json:"failed"` 17 | Users []LDAP_RESULT `json:"users"` 18 | Failed_Messages []Failed_Message `json:"failed_messages"` 19 | } 20 | type Failed_Message struct { 21 | Username string `json:"username"` 22 | Message string `json:"message"` 23 | } 24 | 25 | func Multi_Auth(lc *LDAP_CONFIG, userlist []User) (result Multi_Auth_Result, err error) { 26 | err = lc.Connect() 27 | defer lc.Close() 28 | 29 | if err != nil { 30 | return 31 | } 32 | var Failed_Msg Failed_Message 33 | for _, user := range userlist { 34 | success, err := lc.Auth(user.Username, user.Password) 35 | if success { 36 | result.Successed++ 37 | } else { 38 | result.Failed++ 39 | Failed_Msg.Username = user.Username 40 | Failed_Msg.Message = err.Error() 41 | result.Failed_Messages = append(result.Failed_Messages, Failed_Msg) 42 | } 43 | } 44 | return 45 | } 46 | 47 | func Multi_Search_User(lc *LDAP_CONFIG, userlist []string) (result Multi_Search_User_Result, err error) { 48 | err = lc.Connect() 49 | defer lc.Close() 50 | 51 | if err != nil { 52 | return 53 | } 54 | var Failed_Msg Failed_Message 55 | for _, username := range userlist { 56 | user, err := lc.Search_User(username) 57 | if err == nil { 58 | result.Successed++ 59 | result.Users = append(result.Users, user) 60 | } else { 61 | result.Failed++ 62 | Failed_Msg.Username = username 63 | Failed_Msg.Message = err.Error() 64 | result.Failed_Messages = append(result.Failed_Messages, Failed_Msg) 65 | } 66 | } 67 | return 68 | } 69 | 70 | func Single_Search(lc *LDAP_CONFIG, SearchFilter string) (results []LDAP_RESULT, err error) { 71 | err = lc.Connect() 72 | defer lc.Close() 73 | 74 | if err != nil { 75 | return 76 | } 77 | results, err = lc.Search(SearchFilter) 78 | 79 | return 80 | } 81 | 82 | func Single_Auth(lc *LDAP_CONFIG, username, password string) (success bool, err error) { 83 | err = lc.Connect() 84 | defer lc.Close() 85 | 86 | if err != nil { 87 | return 88 | } 89 | success, err = lc.Auth(username, password) 90 | 91 | return 92 | } 93 | 94 | func Single_Search_User(lc *LDAP_CONFIG, username string) (user LDAP_RESULT, err error) { 95 | err = lc.Connect() 96 | defer lc.Close() 97 | 98 | if err != nil { 99 | return 100 | } 101 | user, err = lc.Search_User(username) 102 | 103 | return 104 | } 105 | 106 | func Health_Check(lc *LDAP_CONFIG) (success bool, err error) { 107 | err = lc.Connect() 108 | defer lc.Close() 109 | 110 | if err != nil { 111 | return 112 | } 113 | return true, nil 114 | } 115 | -------------------------------------------------------------------------------- /models/ldap.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "crypto/tls" 5 | "errors" 6 | "fmt" 7 | 8 | ldap "gopkg.in/ldap.v2" 9 | ) 10 | 11 | type LDAP_CONFIG struct { 12 | Addr string `json:"addr"` 13 | BaseDn string `json:"baseDn"` 14 | BindDn string `json:"bindDn` 15 | BindPass string `json:"bindPass"` 16 | AuthFilter string `json:"authFilter"` 17 | Attributes []string `json:"attributes"` 18 | TLS bool `json:"tls"` 19 | StartTLS bool `json:"startTLS"` 20 | Conn *ldap.Conn 21 | } 22 | 23 | type LDAP_RESULT struct { 24 | DN string `json:"dn"` 25 | Attributes map[string][]string `json:"attributes"` 26 | } 27 | 28 | func (lc *LDAP_CONFIG) Close() { 29 | if lc.Conn != nil { 30 | lc.Conn.Close() 31 | lc.Conn = nil 32 | } 33 | } 34 | 35 | func (lc *LDAP_CONFIG) Connect() (err error) { 36 | if lc.TLS { 37 | lc.Conn, err = ldap.DialTLS("tcp", lc.Addr, &tls.Config{InsecureSkipVerify: true}) 38 | } else { 39 | lc.Conn, err = ldap.Dial("tcp", lc.Addr) 40 | } 41 | if err != nil { 42 | return err 43 | } 44 | if !lc.TLS && lc.StartTLS { 45 | err = lc.Conn.StartTLS(&tls.Config{InsecureSkipVerify: true}) 46 | if err != nil { 47 | lc.Conn.Close() 48 | return err 49 | } 50 | } 51 | 52 | err = lc.Conn.Bind(lc.BindDn, lc.BindPass) 53 | if err != nil { 54 | lc.Conn.Close() 55 | return err 56 | } 57 | return err 58 | } 59 | 60 | func (lc *LDAP_CONFIG) Auth(username, password string) (success bool, err error) { 61 | searchRequest := ldap.NewSearchRequest( 62 | lc.BaseDn, // The base dn to search 63 | ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, 64 | fmt.Sprintf(lc.AuthFilter, username), // The filter to apply 65 | lc.Attributes, // A list attributes to retrieve 66 | nil, 67 | ) 68 | sr, err := lc.Conn.Search(searchRequest) 69 | if err != nil { 70 | return 71 | } 72 | if len(sr.Entries) == 0 { 73 | err = errors.New("Cannot find such user") 74 | return 75 | } 76 | if len(sr.Entries) > 1 { 77 | err = errors.New("Multi users in search") 78 | return 79 | } 80 | err = lc.Conn.Bind(sr.Entries[0].DN, password) 81 | if err != nil { 82 | return 83 | } 84 | //Rebind as the search user for any further queries 85 | err = lc.Conn.Bind(lc.BindDn, lc.BindPass) 86 | if err != nil { 87 | return 88 | } 89 | success = true 90 | return 91 | } 92 | 93 | func (lc *LDAP_CONFIG) Search_User(username string) (user LDAP_RESULT, err error) { 94 | searchRequest := ldap.NewSearchRequest( 95 | lc.BaseDn, // The base dn to search 96 | ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, 97 | fmt.Sprintf(lc.AuthFilter, username), // The filter to apply 98 | lc.Attributes, // A list attributes to retrieve 99 | nil, 100 | ) 101 | sr, err := lc.Conn.Search(searchRequest) 102 | if err != nil { 103 | return 104 | } 105 | if len(sr.Entries) == 0 { 106 | err = errors.New("Cannot find such user") 107 | return 108 | } 109 | if len(sr.Entries) > 1 { 110 | err = errors.New("Multi users in search") 111 | return 112 | } 113 | 114 | attributes := make(map[string][]string) 115 | for _, attr := range sr.Entries[0].Attributes { 116 | attributes[attr.Name] = attr.Values 117 | } 118 | 119 | user.DN = sr.Entries[0].DN 120 | user.Attributes = attributes 121 | return 122 | } 123 | 124 | func (lc *LDAP_CONFIG) Search(SearchFilter string) (results []LDAP_RESULT, err error) { 125 | searchRequest := ldap.NewSearchRequest( 126 | lc.BaseDn, // The base dn to search 127 | ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, 128 | SearchFilter, // The filter to apply 129 | lc.Attributes, // A list attributes to retrieve 130 | nil, 131 | ) 132 | sr, err := lc.Conn.Search(searchRequest) 133 | if err != nil { 134 | return 135 | } 136 | if len(sr.Entries) == 0 { 137 | err = errors.New("Cannot find such dn") 138 | return 139 | } 140 | results = []LDAP_RESULT{} 141 | var result LDAP_RESULT 142 | for _, entry := range sr.Entries { 143 | attributes := make(map[string][]string) 144 | for _, attr := range entry.Attributes { 145 | attributes[attr.Name] = attr.Values 146 | } 147 | result.DN = entry.DN 148 | result.Attributes = attributes 149 | results = append(results, result) 150 | } 151 | return 152 | } 153 | -------------------------------------------------------------------------------- /models/ldap_test.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var openldap = &LDAP_CONFIG{ 8 | Addr: "ldap.example.org:389", 9 | BaseDn: "dc=example,dc=org", 10 | BindDn: "cn=manager,dc=example,dc=org", 11 | BindPass: "password", 12 | AuthFilter: "(&(uid=%s))", 13 | Attributes: []string{}, 14 | TLS: false, 15 | StartTLS: false, 16 | } 17 | 18 | var ad = &LDAP_CONFIG{ 19 | Addr: "ldap.example.org:636", 20 | BaseDn: "dc=example.dc=org", 21 | BindDn: "manager@example.org", 22 | BindPass: "password", 23 | AuthFilter: "(&(sAMAccountName=%s))", 24 | Attributes: []string{"sAMAccountName", "displayName", "mail"}, 25 | TLS: true, 26 | StartTLS: false, 27 | } 28 | 29 | func Test_ldap_auth_ad(t *testing.T) { 30 | err := ad.Connect() 31 | defer ad.Close() 32 | if err != nil { 33 | t.Error(err) 34 | return 35 | } 36 | 37 | success, err := ad.Auth("user1", "pass") 38 | t.Log(success, err) 39 | success, err = ad.Auth("user2", "pass") 40 | t.Log(success, err) 41 | 42 | } 43 | 44 | func Test_ldap_auth_openldap(t *testing.T) { 45 | err := openldap.Connect() 46 | defer openldap.Close() 47 | if err != nil { 48 | t.Error(err) 49 | return 50 | } 51 | success, err := openldap.Auth("user1", "pass") 52 | t.Log(success, err) 53 | success, err = openldap.Auth("user2", "pass") 54 | t.Log(success, err) 55 | openldap.Close() 56 | } 57 | 58 | func Test_ldap_search_ad(t *testing.T) { 59 | err := ad.Connect() 60 | defer ad.Close() 61 | if err != nil { 62 | t.Error(err) 63 | return 64 | } 65 | user, err := ad.Search_User("user1") 66 | t.Log(user, err) 67 | user, err = ad.Search_User("user2") 68 | t.Log(user, err) 69 | res, err := ad.Search("(mail=user1@example.org)") 70 | t.Log(res, err) 71 | 72 | ad.Close() 73 | } 74 | 75 | func Test_ldap_search_openldap(t *testing.T) { 76 | err := openldap.Connect() 77 | defer openldap.Close() 78 | if err != nil { 79 | t.Error(err) 80 | return 81 | } 82 | user, err := openldap.Search_User("user1") 83 | t.Log(user, err) 84 | user, err = openldap.Search_User("user2") 85 | t.Log(user, err) 86 | res, err := openldap.Search("(sn=冯冯)") 87 | t.Log(res, err) 88 | 89 | openldap.Close() 90 | } 91 | 92 | var user1 = User{ 93 | Username: "user1", 94 | Password: "pass", 95 | } 96 | 97 | var user2 = User{ 98 | Username: "user2", 99 | Password: "pass", 100 | } 101 | 102 | var user3 = User{ 103 | Username: "cannotsuchuser", 104 | Password: "123456", 105 | } 106 | 107 | func Test_multi_auth(t *testing.T) { 108 | userlist := []User{user1, user2, user3} 109 | res, err := Multi_Auth(openldap, userlist) 110 | if err != nil { 111 | t.Error(err) 112 | return 113 | } 114 | t.Log(res) 115 | 116 | } 117 | 118 | func Test_multi_search_user(t *testing.T) { 119 | userlist := []string{"user1", "user2", "user3", "cannotsuchuser"} 120 | res, err := Multi_Search_User(ad, userlist) 121 | if err != nil { 122 | t.Error(err) 123 | return 124 | } 125 | t.Log(res) 126 | } 127 | --------------------------------------------------------------------------------