diff --git a/src/main/java/com/dsideal/Sso/Controller/WebLoginController.java b/src/main/java/com/dsideal/Sso/Controller/WebLoginController.java index e111ef4..0585efb 100644 --- a/src/main/java/com/dsideal/Sso/Controller/WebLoginController.java +++ b/src/main/java/com/dsideal/Sso/Controller/WebLoginController.java @@ -32,7 +32,7 @@ public class WebLoginController extends Controller { Set _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 需要加上随机数,否则会有浏览器缓存影响测试 - *

* 功能:票据验证 * http://10.10.21.20:9001/dsssoserver/check?token=2b4e9cc4-9357-45bf-a367-b61b0b5f4387 - *

* 上线前根据t_datashare_system中配置的服务器ip地址进行访问权限验证,目前不加限制 */ @Before({GET.class}) diff --git a/src/main/java/com/dsideal/Sso/Model/BaseModel.java b/src/main/java/com/dsideal/Sso/Model/BaseModel.java index 0fadb9b..e7a48ec 100644 --- a/src/main/java/com/dsideal/Sso/Model/BaseModel.java +++ b/src/main/java/com/dsideal/Sso/Model/BaseModel.java @@ -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 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 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 _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")); diff --git a/src/main/java/com/dsideal/Start.java b/src/main/java/com/dsideal/Start.java index 2fff933..39b3ae6 100644 --- a/src/main/java/com/dsideal/Start.java +++ b/src/main/java/com/dsideal/Start.java @@ -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()); } diff --git a/src/main/java/com/dsideal/Util/CommonUtil.java b/src/main/java/com/dsideal/Util/CommonUtil.java index 302a8be..bec9ee1 100644 --- a/src/main/java/com/dsideal/Util/CommonUtil.java +++ b/src/main/java/com/dsideal/Util/CommonUtil.java @@ -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 URLRequest(String URL) { Map mapRequest = new HashMap(); - - 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 parasMap = URLRequest(redirect_url); for (Map.Entry 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 ConvertLoginRs(Page page) { - List 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 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 map, String signKey) { - if (map == null) { - return null; - } - List 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 renderJsonForLayUI(List list, int count) { - Map result = new HashMap<>(); - result.put("code", 0); - result.put("msg", ""); - result.put("count", count); - result.put("data", list); - return result; - } - - public static Map renderJsonForLayUI(List list) { - Map 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 renderJsonForLayUI(Page dataPage) { - Map 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 map = new HashMap<>(); + public static Map returnMessageJson(boolean result, String message) { + Map map = new HashMap<>(); map.put("success", result); map.put("message", message); return map; } - public static Map returnMessageJson(boolean result, JSONObject jo) { - Map map = new HashMap<>(); - map.put("success", result); - map.put("result", jo); - return map; - } - - public static Map returnMessageJson(boolean result, List list) { - Map 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+除1和4的任意数 - * 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 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"); diff --git a/target/classes/com/dsideal/Sso/Controller/WebLoginController.class b/target/classes/com/dsideal/Sso/Controller/WebLoginController.class index b6ff55a..75528cb 100644 Binary files a/target/classes/com/dsideal/Sso/Controller/WebLoginController.class and b/target/classes/com/dsideal/Sso/Controller/WebLoginController.class differ diff --git a/target/classes/com/dsideal/Sso/Model/BaseModel.class b/target/classes/com/dsideal/Sso/Model/BaseModel.class index d5e0ffe..7b1badf 100644 Binary files a/target/classes/com/dsideal/Sso/Model/BaseModel.class and b/target/classes/com/dsideal/Sso/Model/BaseModel.class differ diff --git a/target/classes/com/dsideal/Start.class b/target/classes/com/dsideal/Start.class index 2850b88..bc02b34 100644 Binary files a/target/classes/com/dsideal/Start.class and b/target/classes/com/dsideal/Start.class differ diff --git a/target/classes/com/dsideal/Util/CommonUtil.class b/target/classes/com/dsideal/Util/CommonUtil.class index 564c927..61324e4 100644 Binary files a/target/classes/com/dsideal/Util/CommonUtil.class and b/target/classes/com/dsideal/Util/CommonUtil.class differ