增加ldap验证功能,添加测试。
This commit is contained in:
@@ -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
|
||||
* @Date: 2022-12-15 11:11:21
|
||||
* @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
|
||||
* @Description: P13账号验证用Controller。
|
||||
*
|
||||
@@ -36,7 +36,7 @@ public class P13AccountCheckController
|
||||
P13AccountCheckResult result = new P13AccountCheckResult();
|
||||
ServletContext context = request.getServletContext();
|
||||
|
||||
context.getAttribute( null );
|
||||
// context.getAttribute( null );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-15 19:40:12
|
||||
* @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
|
||||
* @Description:
|
||||
*
|
||||
@@ -10,17 +10,48 @@
|
||||
*/
|
||||
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.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@SuppressWarnings(
|
||||
{ "unused"})
|
||||
public class ContextLoaderListener implements ServletContextListener
|
||||
{
|
||||
private static final int BUFFER_SIZE = 1024;
|
||||
private static final String CONFIG_FILE_CHARSET = "UTF-8";
|
||||
|
||||
@Override
|
||||
public void contextInitialized( ServletContextEvent event )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user