增加ldap验证功能,添加测试。
This commit is contained in:
parent
8219016b9d
commit
ef4874962e
@ -1,4 +1,5 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.cpic.xim</groupId>
|
<groupId>com.cpic.xim</groupId>
|
||||||
@ -12,7 +13,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>4.13.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
|
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
|
||||||
@ -90,6 +91,14 @@
|
|||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.2.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.0.0-M6</version>
|
||||||
|
<configuration>
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* @Author: Kane
|
||||||
|
* @Date: 2022-12-15 09:51:12
|
||||||
|
* @LastEditors: Kane
|
||||||
|
* @LastEditTime: 2022-12-16 10:57:38
|
||||||
|
* @FilePath: \AdminSys\src\main\java\com\cpic\xim\myutils\account\LdapAccountCheck.java
|
||||||
|
* @Description:
|
||||||
|
*
|
||||||
|
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
package com.cpic.xim.myutils.account;
|
||||||
|
|
||||||
|
import javax.naming.CommunicationException;
|
||||||
|
import javax.naming.Context;
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
import javax.naming.directory.DirContext;
|
||||||
|
import javax.naming.directory.InitialDirContext;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
public class LdapAccountCheck
|
||||||
|
{
|
||||||
|
private static String ldapServerUrl = "ldap://10.39.0.205:389";
|
||||||
|
|
||||||
|
public static boolean ldapLogin( String userName, String password )
|
||||||
|
{
|
||||||
|
boolean result = false;
|
||||||
|
|
||||||
|
if ( userName.endsWith( "@pr.intra.cpic.com.cn" ) == false)
|
||||||
|
{
|
||||||
|
userName += "@pr.intra.cpic.com.cn";
|
||||||
|
}
|
||||||
|
|
||||||
|
DirContext ctx = null;
|
||||||
|
Hashtable<String, String> ldap = new Hashtable<String, String>();
|
||||||
|
|
||||||
|
ldap.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
|
||||||
|
ldap.put( Context.SECURITY_AUTHENTICATION, "simple" );
|
||||||
|
ldap.put( Context.PROVIDER_URL, ldapServerUrl );
|
||||||
|
ldap.put( Context.SECURITY_PRINCIPAL, userName );
|
||||||
|
ldap.put( Context.SECURITY_CREDENTIALS, password );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ctx = new InitialDirContext( ldap );
|
||||||
|
ctx.close();
|
||||||
|
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
catch ( CommunicationException error )
|
||||||
|
{
|
||||||
|
error.printStackTrace();
|
||||||
|
error.getMessage();
|
||||||
|
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
catch ( NamingException error )
|
||||||
|
{
|
||||||
|
error.printStackTrace();
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
/*
|
|
||||||
* @Author: Kane
|
|
||||||
* @Date: 2022-12-15 09:51:12
|
|
||||||
* @LastEditors: Kane
|
|
||||||
* @LastEditTime: 2022-12-15 10:04:36
|
|
||||||
* @FilePath: \AdminSys\src\main\java\com\cpicxim\myutils\account\P13AccountCheck.java
|
|
||||||
* @Description:
|
|
||||||
*
|
|
||||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
|
||||||
*/
|
|
||||||
package com.cpic.xim.myutils.account;
|
|
||||||
|
|
||||||
public class P13AccountCheck
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* @Author: Kane
|
||||||
|
* @Date: 2022-12-16 08:50:47
|
||||||
|
* @LastEditors: Kane
|
||||||
|
* @LastEditTime: 2022-12-16 10:15:11
|
||||||
|
* @FilePath: \AdminSys\src\main\java\com\cpic\xim\myutils\config\json\AppConfig.java
|
||||||
|
* @Description: 应用的JSON格式配置文件对象
|
||||||
|
*
|
||||||
|
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
package com.cpic.xim.myutils.config.json;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
@SuppressWarnings(
|
||||||
|
{ "unused"})
|
||||||
|
public class AppConfig
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* @Author: Kane
|
||||||
|
* @Date: 2022-12-16 08:55:32
|
||||||
|
* @LastEditors: Kane
|
||||||
|
* @LastEditTime: 2022-12-16 10:15:42
|
||||||
|
* @FilePath: \AdminSys\src\main\java\com\cpic\xim\myutils\config\json\DatabaseConfig.java
|
||||||
|
* @Description:
|
||||||
|
*
|
||||||
|
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
package com.cpic.xim.myutils.config.json;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
@SuppressWarnings(
|
||||||
|
{ "unused"})
|
||||||
|
public class DatabaseConfig
|
||||||
|
{
|
||||||
|
private String dbType;
|
||||||
|
private String userName;
|
||||||
|
private String password;
|
||||||
|
private String dbName;
|
||||||
|
private String jdbcURL;
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-12-15 11:11:21
|
* @Date: 2022-12-15 11:11:21
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-12-15 21:15:07
|
* @LastEditTime: 2022-12-16 10:17:24
|
||||||
* @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\controllers\account\P13AccountCheckController.java
|
* @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\controllers\account\P13AccountCheckController.java
|
||||||
* @Description: P13账号验证用Controller。
|
* @Description: P13账号验证用Controller。
|
||||||
*
|
*
|
||||||
@ -36,7 +36,7 @@ public class P13AccountCheckController
|
|||||||
P13AccountCheckResult result = new P13AccountCheckResult();
|
P13AccountCheckResult result = new P13AccountCheckResult();
|
||||||
ServletContext context = request.getServletContext();
|
ServletContext context = request.getServletContext();
|
||||||
|
|
||||||
context.getAttribute( null );
|
// context.getAttribute( null );
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-12-15 19:40:12
|
* @Date: 2022-12-15 19:40:12
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-12-15 19:53:22
|
* @LastEditTime: 2022-12-16 10:14:54
|
||||||
* @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\listener\ContextLoaderListener.java
|
* @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\listener\ContextLoaderListener.java
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
@ -10,17 +10,48 @@
|
|||||||
*/
|
*/
|
||||||
package com.cpic.xim.web.listener;
|
package com.cpic.xim.web.listener;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
@SuppressWarnings(
|
||||||
|
{ "unused"})
|
||||||
public class ContextLoaderListener implements ServletContextListener
|
public class ContextLoaderListener implements ServletContextListener
|
||||||
{
|
{
|
||||||
|
private static final int BUFFER_SIZE = 1024;
|
||||||
|
private static final String CONFIG_FILE_CHARSET = "UTF-8";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized( ServletContextEvent event )
|
public void contextInitialized( ServletContextEvent event )
|
||||||
{
|
{
|
||||||
ServletContext context = event.getServletContext();
|
ServletContext context = event.getServletContext();
|
||||||
|
|
||||||
|
String configFileLocation = context.getInitParameter( "config_file_location" );
|
||||||
|
|
||||||
|
// loadConfig( configFileLocation );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadConfig( String configFileLocation )
|
||||||
|
{
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
FileInputStream configFile = null;
|
||||||
|
InputStreamReader in = null;
|
||||||
|
StringBuilder json = null;
|
||||||
|
char[] buffer = new char[BUFFER_SIZE];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
configFile = new FileInputStream( configFileLocation );
|
||||||
|
}
|
||||||
|
catch ( IOException exception )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
<!--
|
|
||||||
* @Author: Kane
|
|
||||||
* @Date: 2022-09-29 16:33:30
|
|
||||||
* @LastEditors: Kane
|
|
||||||
* @LastEditTime: 2022-10-11 10:08:30
|
|
||||||
* @FilePath: \car_dealer\src\main\webapp\file_upload.html
|
|
||||||
* @Description:
|
|
||||||
*
|
|
||||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
|
||||||
-->
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>上传文件测试!</title>
|
|
||||||
<link rel="stylesheet" href="css/root.css" />
|
|
||||||
<link rel="stylesheet" href="css/normalize.css" />
|
|
||||||
<link rel="stylesheet" href="css/kane.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="app">
|
|
||||||
<form
|
|
||||||
action="http://localhost:8080/cardealer/upload.do"
|
|
||||||
id="uploadform"
|
|
||||||
enctype="multipart/form-data"
|
|
||||||
method="post"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
name="uploadFile"
|
|
||||||
id="upload"
|
|
||||||
style="display: none"
|
|
||||||
onchange="fileUploadChange()"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value="12345"
|
|
||||||
name="test"
|
|
||||||
style="display: none"
|
|
||||||
/>
|
|
||||||
</form>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="upload_text"
|
|
||||||
readonly
|
|
||||||
onclick="upload.click()"
|
|
||||||
/>
|
|
||||||
<button id="btnUpload">上传</button>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
<script>
|
|
||||||
//const reqeustURL = "upload/upload_file.do";
|
|
||||||
const reqeustURL =
|
|
||||||
"http://localhost:8080/cardealer/upload/upload_file.do";
|
|
||||||
const btnUpload = document.getElementById("btnUpload");
|
|
||||||
|
|
||||||
function fileUploadChange() {
|
|
||||||
document.getElementById("upload_text").value =
|
|
||||||
document.getElementById("upload").value;
|
|
||||||
}
|
|
||||||
|
|
||||||
btnUpload.onclick = function (event) {
|
|
||||||
const uploadForm = document.getElementById("uploadform");
|
|
||||||
const form = new FormData(uploadForm);
|
|
||||||
|
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
|
|
||||||
xhr.upload.onprogress = function (event) {
|
|
||||||
if (event.lengthComputable) {
|
|
||||||
let percent = Math.round(
|
|
||||||
(event.loaded * 100) / event.total,
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log("上传进度:" + percent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.onload = function (event) {
|
|
||||||
console.log(xhr.responseText);
|
|
||||||
|
|
||||||
let result = JSON.parse(xhr.responseText);
|
|
||||||
|
|
||||||
console.log(result);
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.open("post", reqeustURL, true);
|
|
||||||
xhr.send(form);
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
</html>
|
|
@ -1,37 +0,0 @@
|
|||||||
<!--
|
|
||||||
* @Author: Kane
|
|
||||||
* @Date: 2022-10-19 09:59:34
|
|
||||||
* @LastEditors: Kane
|
|
||||||
* @LastEditTime: 2022-10-19 17:21:25
|
|
||||||
* @FilePath: \car_dealer\src\main\webapp\test.html
|
|
||||||
* @Description:
|
|
||||||
*
|
|
||||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
|
||||||
-->
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Document</title>
|
|
||||||
<link rel="stylesheet" href="css/root.css" />
|
|
||||||
<link rel="stylesheet" href="css/normalize.css" />
|
|
||||||
<link rel="stylesheet" href="css/kane.css" />
|
|
||||||
<link rel="stylesheet" href="css/test.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="root">
|
|
||||||
<!-- <div><a>测试的文本!!!!</a> <a>第二行文本!!!</a></div>
|
|
||||||
<div class="warp_test"></div> -->
|
|
||||||
<ol>
|
|
||||||
<li>测试</li>
|
|
||||||
<li>测试</li>
|
|
||||||
<li>测试</li>
|
|
||||||
<li>测试</li>
|
|
||||||
<li>测试</li>
|
|
||||||
<li>测试</li>
|
|
||||||
</ol>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,8 +1,10 @@
|
|||||||
com\cpic\xim\myutils\config\json\ConfigLoader.class
|
com\cpic\xim\myutils\config\json\ConfigLoader.class
|
||||||
com\cpic\xim\web\controllers\account\P13AccountCheckResult.class
|
com\cpic\xim\web\controllers\account\P13AccountCheckResult.class
|
||||||
|
com\cpic\xim\myutils\config\json\AppConfig.class
|
||||||
com\cpic\xim\web\filters\cros\CrosFilter.class
|
com\cpic\xim\web\filters\cros\CrosFilter.class
|
||||||
com\cpic\xim\myutils\account\P13AccountCheck.class
|
|
||||||
com\cpic\xim\web\listener\ContextLoaderListener.class
|
com\cpic\xim\web\listener\ContextLoaderListener.class
|
||||||
|
com\cpic\xim\myutils\config\json\DatabaseConfig.class
|
||||||
com\cpic\xim\web\controllers\account\P13AccountCheckController.class
|
com\cpic\xim\web\controllers\account\P13AccountCheckController.class
|
||||||
com\cpic\xim\web\controllers\account\P13AccountCheckRequest.class
|
com\cpic\xim\web\controllers\account\P13AccountCheckRequest.class
|
||||||
com\cpic\xim\myutils\account\CpicXIMStaffInfo.class
|
com\cpic\xim\myutils\account\CpicXIMStaffInfo.class
|
||||||
|
com\cpic\xim\myutils\account\LdapAccountCheck.class
|
||||||
|
@ -3,6 +3,8 @@ F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\c
|
|||||||
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\web\controllers\account\P13AccountCheckController.java
|
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\web\controllers\account\P13AccountCheckController.java
|
||||||
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\web\filters\cros\CrosFilter.java
|
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\web\filters\cros\CrosFilter.java
|
||||||
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\myutils\account\CpicXIMStaffInfo.java
|
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\myutils\account\CpicXIMStaffInfo.java
|
||||||
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\myutils\account\P13AccountCheck.java
|
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\myutils\account\LdapAccountCheck.java
|
||||||
|
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\myutils\config\json\AppConfig.java
|
||||||
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\web\listener\ContextLoaderListener.java
|
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\web\listener\ContextLoaderListener.java
|
||||||
|
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\myutils\config\json\DatabaseConfig.java
|
||||||
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\myutils\config\json\ConfigLoader.java
|
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\main\java\com\cpic\xim\myutils\config\json\ConfigLoader.java
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
com\cpic\xim\myutils\account\LdapAccountCheckTest.class
|
@ -0,0 +1 @@
|
|||||||
|
F:\练手代码\vue-learning\企业级管理系统\java\AdminSys\src\test\java\com\cpic\xim\myutils\account\LdapAccountCheckTest.java
|
Loading…
x
Reference in New Issue
Block a user