main
黄海 1 year ago
parent 9ed30fbfe4
commit 9277a5a222

@ -32,7 +32,7 @@ public class WebLoginController extends Controller {
Set<String> _set = RedisKit.SMembers(PropKit.get("SYS_JRXT"));
boolean found = false;
for (String s : _set) {
if (redirect_url.indexOf(s) >= 0) {
if (redirect_url.contains(s)) {
found = true;
break;
}
@ -48,7 +48,7 @@ public class WebLoginController extends Controller {
Kv kv = SsoLoginHelper.loginCheck(getRequest());
if (kv.getBoolean("success")) {
String ssoSessionId = PropKit.get("sso.sessionid");
if (redirect_url.indexOf("?") == -1) {
if (!redirect_url.contains("?")) {
redirect301(redirect_url + "?" + ssoSessionId + "=" + kv.getStr("session_id"));
} else {
redirect301(redirect_url + "&" + ssoSessionId + "=" + kv.getStr("session_id"));
@ -152,7 +152,7 @@ public class WebLoginController extends Controller {
BaseModel bm = new BaseModel();
Record loginMap = bm.getLoginInfoByUserName(username);
if (loginMap == null || !passwordEncode.equals(loginMap.get("pwd").toString())) {
if (passwordEncode != null && (loginMap == null || !passwordEncode.equals(loginMap.get("pwd").toString()))) {
//扩展支持连续输入用户名密码错误停用账号5分钟功能 2022.06.07
cntNum = 1;
if (RedisKit.Exists(PassWordKey))
@ -227,10 +227,8 @@ public class WebLoginController extends Controller {
/**
*
* http://10.10.21.20:9001/dsssoserver/login?redirect_url=http://www.163.com/&random=123 需要加上随机数,否则会有浏览器缓存影响测试
* <p>
*
* http://10.10.21.20:9001/dsssoserver/check?token=2b4e9cc4-9357-45bf-a367-b61b0b5f4387
* <p>
* 线t_datashare_systemip访
*/
@Before({GET.class})

@ -21,14 +21,10 @@ public class BaseModel {
String redisKey = "global_" + key;
if (RedisKit.Exists(redisKey)) return RedisKit.Get(redisKey);
String result = "";
try {
String sql = "select * from t_base_global where global_code=?";
List<Record> list = Db.find(sql, key);
if (list.size() > 0) {
result = list.get(0).getStr("global_value");
}
} catch (Exception e) {
e.printStackTrace();
String sql = "select * from t_base_global where global_code=?";
List<Record> list = Db.find(sql, key);
if (!list.isEmpty()) {
result = list.getFirst().getStr("global_value");
}
RedisKit.Set(redisKey, result);
return result;
@ -39,16 +35,15 @@ public class BaseModel {
if (RedisKit.Exists(redisKey)) {
Map<String, String> _map = RedisKit.HGetAll(redisKey);
Record record = new Record();
for (Map.Entry entry : _map.entrySet()) {
String key = entry.getKey().toString();
String value = entry.getValue().toString();
for (var entry : _map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
record.set(key, value);
}
return record;
}
String sql = "select login_name,pwd,identity_id,person_id from t_sys_loginperson where login_name=? and b_use=1";
Record record = Db.findFirst(sql, username);
RedisKit.HSet(redisKey, "login_name", record.getStr("login_name"));
RedisKit.HSet(redisKey, "pwd", record.getStr("pwd"));
RedisKit.HSet(redisKey, "identity_id", record.getStr("identity_id"));

@ -2,14 +2,11 @@ package com.dsideal;
import Plugin.LogBackLogFactory;
import cn.hutool.core.io.FileUtil;
import com.dsideal.Const.OsSystemConst;
import com.dsideal.Interceptor.EmptyInterceptor;
import com.dsideal.Sso.Controller.CommomController;
import com.dsideal.Sso.Controller.WebLoginController;
import com.dsideal.Util.CommonUtil;
import com.jfinal.config.*;
import com.jfinal.kit.PropKit;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
@ -17,9 +14,9 @@ import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;
import java.io.File;
import java.util.Objects;
public class Start extends JFinalConfig {
private static Log log = Log.getLog(Start.class);
public static void main(String[] args) {
UndertowServer.create(Start.class, "undertow.properties").start();
@ -27,7 +24,7 @@ public class Start extends JFinalConfig {
public void onStart() {
//打印 启动Logo
String path = Start.class.getClassLoader().getResource("logo.txt").getPath();
String path = Objects.requireNonNull(Start.class.getClassLoader().getResource("logo.txt")).getPath();
File file = new File(path);
System.out.println(FileUtil.readUtf8String(file));
}
@ -39,7 +36,7 @@ public class Start extends JFinalConfig {
//配置日志框架logback
me.setLogFactory(new LogBackLogFactory());
PropKit.use("application.properties");
}
}
/**
*
@ -74,7 +71,6 @@ public class Start extends JFinalConfig {
*
*/
public void configInterceptor(Interceptors me) {
//注册非空拦截器
me.add(new EmptyInterceptor());
}

@ -1,24 +1,12 @@
package com.dsideal.Util;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.Const.OsSystemConst;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
@ -29,39 +17,10 @@ public class CommonUtil {
//在独立的main函数中使用下面的方式进行声明logback对象
private static Logger log = LoggerFactory.getLogger(CommonUtil.class);
//获取当前年份
public static String getCurrentYear() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
Date date = new Date();
return sdf.format(date);
}
/**
*
*
* 2019-01-19
*
* @param pwd
* @return
*/
public static boolean getPwdLegal(String pwd) {
boolean flag = false;
try {
String regExp = "[a-z0-9A-Z]+";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(pwd);
return m.matches();
} catch (Exception e) {
return false;
}
}
private static String TruncateUrlPage(String strURL) {
String strAllParam = null;
String[] arrSplit = null;
strURL = strURL.trim();
arrSplit = strURL.split("[?]");
String[] arrSplit = strURL.split("[?]");
if (strURL.length() > 1) {
if (arrSplit.length > 1) {
if (arrSplit[1] != null) {
@ -69,14 +28,12 @@ public class CommonUtil {
}
}
}
return strAllParam;
}
private static Map<String, String> URLRequest(String URL) {
Map<String, String> mapRequest = new HashMap<String, String>();
String[] arrSplit = null;
String[] arrSplit;
String strUrlParam = TruncateUrlPage(URL);
if (strUrlParam == null) {
return mapRequest;
@ -93,7 +50,7 @@ public class CommonUtil {
mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);
} else {
if (arrSplitEqual[0] != "") {
if (!Objects.equals(arrSplitEqual[0], "")) {
// 只有参数没有值,不加入
mapRequest.put(arrSplitEqual[0], "");
}
@ -110,10 +67,10 @@ public class CommonUtil {
Map<String, String> parasMap = URLRequest(redirect_url);
for (Map.Entry<String, String> entry : parasMap.entrySet()) {
if (!entry.getKey().equals(PropKit.get("sso.sessionid"))) {
if (uri.indexOf("?") == -1) {
uri += "?"+entry.getKey()+"="+entry.getValue();
}else{
uri += "&"+entry.getKey()+"="+entry.getValue();
if (!uri.contains("?")) {
uri += "?" + entry.getKey() + "=" + entry.getValue();
} else {
uri += "&" + entry.getKey() + "=" + entry.getValue();
}
}
}
@ -123,202 +80,6 @@ public class CommonUtil {
return redirectUrl;
}
/**
*
*
* 2019-04-22
*
* @return
*/
public static int getOsSystemType() {
String os = System.getProperty("os.name");
if (os.toLowerCase().startsWith("win")) {
return OsSystemConst.WINDOWS;
} else {
return OsSystemConst.CENTOS;
}
}
/**
*
*
* 2019-01-03
*
* @param tempPath
*/
public static void clearFile(String tempPath) {
File file = new File(tempPath);
File[] tempList = file.listFiles();
if (tempList != null) {
for (int i = 0; i < tempList.length; i++) {
if (tempList[i].isFile()) {
tempList[i].delete();
}
}
}
}
/**
*
*
* 2018-12-20
*
* @param str
* @return
*/
public static boolean isValidDate(String str) {
boolean convertSuccess = true;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
format.setLenient(false);
format.parse(str);
} catch (ParseException e) {
convertSuccess = false;
}
return convertSuccess;
}
/**
*
*
* 2018-12-12
*
* @return
*/
public static Page<Record> ConvertLoginRs(Page<Record> page) {
List<Record> list = new ArrayList<>();
for (int i = 0; i < page.getList().size(); i++) {
Record record = page.getList().get(i);
String original_pwd = record.get("original_pwd");
String database_pwd = record.get("pwd");
//将明文密码加密
String pwd = CommonUtil.getLdapPassword(original_pwd);
if (!pwd.equals(database_pwd)) {
record.set("original_pwd", "用户已修改");
}
record.remove("pwd");
list.add(record);
}
Page<Record> pageRecords = new Page(list, page.getPageNumber(), page.getPageSize(), page.getTotalPage(), page.getTotalRow());
return pageRecords;
}
/**
* JSONArray
*
* :2018-12-12
*
* @param content
* @return
*/
public static boolean isJsonArray(String content) {
try {
JSONArray.parseArray(content);
return true;
} catch (Exception e) {
return false;
}
}
/**
* +
*
* 2018-11-30
*
* @return
*/
public static String GetCurrentTimeString() {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
String nowTime = sdf.format(date);
return nowTime;
}
/**
*
*
* @param map
* @return
*/
public static String Sign(Map<String, Object> map, String signKey) {
if (map == null) {
return null;
}
List<String> keyList = new ArrayList<>(map.keySet());
Collections.sort(keyList);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
Object value = map.get(key);
sb.append(key + "=" + value + "&");
}
String signStr = sb.substring(0, sb.length() - 1) + signKey;
String md5Str = DigestUtils.md5Hex(signStr);
return md5Str;
}
/**
* layUI
*/
public static Map<String, Object> renderJsonForLayUI(List<Record> list, int count) {
Map<String, Object> result = new HashMap<>();
result.put("code", 0);
result.put("msg", "");
result.put("count", count);
result.put("data", list);
return result;
}
public static Map<String, Object> renderJsonForLayUI(List<Record> list) {
Map<String, Object> result = new HashMap<>();
result.put("code", 0);
result.put("msg", "");
result.put("count", list.size());
result.put("data", list);
return result;
}
/**
* layUI
*
* @param dataPage
* @return
*/
public static Map<String, Object> renderJsonForLayUI(Page<Record> dataPage) {
Map<String, Object> result = new HashMap<>();
result.put("code", 0);
result.put("msg", "");
result.put("count", dataPage.getTotalRow());
result.put("data", dataPage.getList());
return result;
}
/**
*
*
* 2018-11-19
*
* @param str
* @return
*/
public static boolean isNumeric(String str) {
try {
for (int i = str.length(); --i >= 0; ) {
if (str.charAt(0) == '-') {
continue;
} else {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
}
return true;
} catch (Exception err) {
return false;
}
}
/**
* json
*
@ -327,26 +88,13 @@ public class CommonUtil {
* @param result
* @param message
*/
public static Map returnMessageJson(boolean result, String message) {
Map<String,Object> map = new HashMap<>();
public static Map<String, Object> returnMessageJson(boolean result, String message) {
Map<String, Object> map = new HashMap<>();
map.put("success", result);
map.put("message", message);
return map;
}
public static Map returnMessageJson(boolean result, JSONObject jo) {
Map<String,Object> map = new HashMap<>();
map.put("success", result);
map.put("result", jo);
return map;
}
public static Map returnMessageJson(boolean result, List<Record> list) {
Map<String,Object> map = new HashMap<>();
map.put("success", result);
map.put("result", list);
return map;
}
/**
* md5
@ -382,280 +130,6 @@ public class CommonUtil {
}
}
/**
* 6
*
* 2018-11-27
*
* @return
*/
public static String getSixRandom() {
String sources = "0123456789";
Random rand = new Random();
StringBuffer flag = new StringBuffer();
for (int j = 0; j < 6; j++) {
flag.append(sources.charAt(rand.nextInt(9)) + "");
}
return flag.toString();
}
/**
* shell
*
* 2019-01-19
*
* @param cmd
*/
public static void ExecShellWaitFinish(String cmd) {
Process process = null;
String ls_1;
try {
process = Runtime.getRuntime().exec(cmd);
BufferedReader bufferedReader1 = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
while ((ls_1 = bufferedReader1.readLine()) != null)
log.info(ls_1);
bufferedReader1.close();
process.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
try {
if (process.waitFor() == 0) {
return;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
/**
*
*
* 2018-11-27
* 13+
* 15+4
* 18+14
* 17+9
* 147
*
* @param phoneNum
* @return
*/
public static boolean getIsPhoneLegal(String phoneNum) {
try {
String regExp = "^((13[0-9])|(19[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(phoneNum);
return m.matches();
} catch (Exception e) {
return false;
}
}
/**
*
*
* 2018-11-27
*
* @param eMail
* @return
*/
public static boolean getIsEmailLegal(String eMail) {
try {
String regExp = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(eMail);
return m.matches();
} catch (Exception e) {
return false;
}
}
/**
*
*
* 2018-12-07
*
* @param date
* @return
*/
public static boolean getIsDateLegal(String date) {
if (date == null || StrKit.isBlank(date)) return false;
try {
String regExp = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(date);
return m.matches();
} catch (Exception e) {
return false;
}
}
/**
*
*
* 2018-12-07
*
* @param xb
* @return
*/
public static boolean getXbCorrectRange(String xb) {
String[] stageArr = new String[]{"1", "2"};
for (String s : stageArr) {
if (s.equals(xb)) {
return true;
}
}
return false;
}
/**
*
*
* 2018-12-07
*
* @param mz
* @return
*/
public static boolean getMzCorrectRange(String mz) {
String[] stageArr = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "97", "98"};
for (String s : stageArr) {
if (s.equals(mz)) {
return true;
}
}
return false;
}
/**
*
*
* 2019-01-05
*
* @param zzmm
* @return
*/
public static boolean getZzmmCorrectRange(String zzmm) {
String[] stageArr = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13"};
for (String s : stageArr) {
if (s.equals(zzmm)) {
return true;
}
}
return false;
}
/**
* SQL
*
* 2021-11-01
*
* @param findSql
* @return
*/
public static String getTotalSql(String findSql) {
String totalRowSql = "select count(*) from (" + findSql + ") as t100";
return totalRowSql;
}
/**
* 便IN
*
* 2021-10-22
*
* @param list
* @param key
* @return
*/
public static String getIds(List<Record> list, String key) {
String s = "";
if (list.size() == 0) return "-1";
for (Record record1 : list) s += "'" + record1.getStr(key) + "',";
s = s.substring(0, s.length() - 1);
return s;
}
/**
*
*
* @param str
*/
public static void printf(String str) {
System.out.println(DateTime.now() + " " + str);
}
/***
* delete CRLF; delete empty line ;delete blank lines
*
* @param input
* @return
*/
private static String deleteCRLFOnce(String input) {
return input.replaceAll("((\r\n)|\n)[\\s\t ]*(\\1)+", "$1");
}
/**
* delete CRLF; delete empty line ;delete blank lines
*
* @param input
* @return
*/
public static String deleteCRLF(String input) {
input = deleteCRLFOnce(input);
return deleteCRLFOnce(input);
}
public static void changeEncode(String source, String target) throws IOException {
InputStreamReader isr = new InputStreamReader(new FileInputStream(source), "gbk");
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(target), "utf-8");
int len = 0;
char[] chars = new char[1024];
while ((len = isr.read(chars)) != -1) {
osw.write(chars, 0, len);
}
osw.close();
isr.close();
}
public static boolean checkPass(String pass) {
//注释掉必须要有符号这个要求:&& pass.matches(".*[~!@#$%^&*\\.?]{1,}.*")
// if (pass.matches(".*[a-z]{1,}.*") && pass.matches(".*[A-Z]{1,}.*") && pass.matches(".*\\d{1,}.*") && pass.length()>=7 ) {
// return true;
// }
// return false;
return true;
}
public static boolean isBase64(String str) {
String base64Rule = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$";
return Pattern.matches(base64Rule, str);
}
/**
* class
*
* @return
*/
public static String getClassPath() throws URISyntaxException {
String path = PathKit.class.getClassLoader().getResource("").toURI().getPath();
if (getOsSystemType() == OsSystemConst.WINDOWS) {
if (path.startsWith("/")) path = path.substring(1);
}
return path;
}
public static void log(String msg) {
System.out.println(DateTime.now() + " " + msg);
}
public static JSONObject getJsonFile(String filePath) {
return JSONObject.parseObject(FileUtil.readUtf8String((filePath)));
}
public static void Print(String msg) {
System.out.println(DateTime.now() + " " + msg);
}
public static boolean isLinux() {
return System.getProperty("os.name").toLowerCase().contains("linux");

Loading…
Cancel
Save