add
liyanqi
2022-09-07 71906ab85c871547c4082d5b53df31dafc4b5072
add
4个文件已修改
5个文件已添加
655 ■■■■■ 已修改文件
ycl-common/src/main/java/com/ycl/constant/SysConst.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/dto/UmsAdminParam.java 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/entity/user/UmsAdmin.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/utils/common/MacUtils.java 203 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/utils/common/NetworkUtil.java 328 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/utils/common/PojoUtils.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/component/DynamicSecurityFilter.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/constant/SysConst.java
New file
@@ -0,0 +1,17 @@
package com.ycl.constant;
/**
 * 全局常量
 * @author Lyq
 * @version 1.0
 * @date 2022/9/7
 */
public class SysConst {
    /**页面下拉框传 0表示 查询条件为全部*/
    public static final Integer COMBOBOX_ALL = 0;
    /**
     * 推荐hashMap的初始长度
     */
    public static final Integer REF_MAP_LENGTH = 20;
}
ycl-common/src/main/java/com/ycl/dto/UmsAdminParam.java
@@ -5,7 +5,9 @@
import lombok.Setter;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
 * 用户登录参数
@@ -13,19 +15,40 @@
@Getter
@Setter
public class UmsAdminParam {
    @NotEmpty
    @NotBlank(message = "用户名不能为空")
    @ApiModelProperty(value = "用户名", required = true)
    private String username;
    @ApiModelProperty(value = "手机号码")
    private String mobile;
    @NotEmpty
    @ApiModelProperty(value = "密码", required = true)
    private String password;
    @ApiModelProperty(value = "用户头像")
    private String icon;
    @Email
    @ApiModelProperty(value = "邮箱")
    private String email;
    @ApiModelProperty(value = "用户昵称")
    private String nickName;
    @ApiModelProperty(value = "备注")
    private String note;
    @ApiModelProperty(value = "是否党员,0:否,1:是")
    private byte isDy;
    @ApiModelProperty(value = "职务")
    private String jobTitle;
    @ApiModelProperty(value = "部门id")
    private Long departmentId;
    @ApiModelProperty(value = "用户类型")
    private byte userType;
    @ApiModelProperty(value = "座机/分机")
    private String zj;
}
ycl-common/src/main/java/com/ycl/entity/user/UmsAdmin.java
@@ -22,10 +22,10 @@
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("ums_admin")
@ApiModel(value="UmsAdmin对象", description="后台用户表")
@ApiModel(value = "UmsAdmin对象", description = "后台用户表")
public class UmsAdmin implements Serializable {
    private static final long serialVersionUID=1L;
    private static final long serialVersionUID = 1L;
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
@@ -40,7 +40,7 @@
    @ApiModelProperty(value = "邮箱")
    private String email;
    @ApiModelProperty(value = "昵称")
    @ApiModelProperty(value = "用户名(系统默认生成)")
    private String nickName;
    @ApiModelProperty(value = "备注信息")
@@ -55,5 +55,30 @@
    @ApiModelProperty(value = "帐号启用状态:0->禁用;1->启用")
    private Integer status;
    @ApiModelProperty(value = "mac地址")
    private String macAddress;
    @ApiModelProperty(value = "ip地址")
    private String ipAddress;
    @ApiModelProperty(value = "是否党员")
    private byte isDy;
    @ApiModelProperty(value = "职务")
    private String jobTitle;
    @ApiModelProperty(value = "部门id")
    private Long departmentId;
    @ApiModelProperty(value = "用户类型")
    private byte userType;
    @ApiModelProperty(value = "座机/分机")
    private String zj;
    @ApiModelProperty(value = "用户名")
    private String realName;
    @ApiModelProperty(value = "手机号码")
    private String mobile;
}
ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java
@@ -79,6 +79,7 @@
    @Override
    public UmsAdmin register(UmsAdminParam umsAdminParam) {
        UmsAdmin umsAdmin = new UmsAdmin();
        //TODO mac,ip,职务,用户类型
        BeanUtils.copyProperties(umsAdminParam, umsAdmin);
        umsAdmin.setCreateTime(new Date());
        umsAdmin.setStatus(1);
ycl-common/src/main/java/com/ycl/utils/common/MacUtils.java
New file
@@ -0,0 +1,203 @@
package com.ycl.utils.common;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 * @author Lyq
 * @version 1.0
 * @date 2022/9/7
 * 获取操作系统的mac地址
 */
public class MacUtils {
    /**
     * 获取当前操作系统名称. return 操作系统名称 例如:windows,Linux,Unix等.
     */
    public static String getOSName() {
        return System.getProperty("os.name").toLowerCase();
    }
    /**
     * 获取Unix网卡的mac地址.
     *
     * @return mac地址
     */
    public static String getUnixMACAddress() {
        String mac = null;
        BufferedReader bufferedReader = null;
        Process process = null;
        try {
            /**
             * Unix下的命令,一般取eth0作为本地主网卡 显示信息中包含有mac地址信息
             */
            process = Runtime.getRuntime().exec("ifconfig eth0");
            bufferedReader = new BufferedReader(new InputStreamReader(
                    process.getInputStream()));
            String line = null;
            int index = -1;
            while ((line = bufferedReader.readLine()) != null) {
                /**
                 * 寻找标示字符串[hwaddr]
                 */
                index = line.toLowerCase().indexOf("hwaddr");
                /**
                 * 找到了
                 */
                if (index != -1) {
                    /**
                     * 取出mac地址并去除2边空格
                     */
                    mac = line.substring(index + "hwaddr".length() + 1).trim();
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            bufferedReader = null;
            process = null;
        }
        return mac;
    }
    /**
     * 获取Linux网卡的mac地址.
     *
     * @return mac地址
     */
    public static String getLinuxMACAddress() {
        String mac = null;
        BufferedReader bufferedReader = null;
        Process process = null;
        try {
            /**
             * linux下的命令,一般取eth0作为本地主网卡 显示信息中包含有mac地址信息
             */
            process = Runtime.getRuntime().exec("ifconfig eth0");
            bufferedReader = new BufferedReader(new InputStreamReader(
                    process.getInputStream()));
            String line = null;
            int index = -1;
            while ((line = bufferedReader.readLine()) != null) {
                index = line.toLowerCase().indexOf("硬件地址");
                /**
                 * 找到了
                 */
                if (index != -1) {
                    /**
                     * 取出mac地址并去除2边空格
                     */
                    mac = line.substring(index + 4).trim();
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            bufferedReader = null;
            process = null;
        }
        // 取不到,试下Unix取发
        if (mac == null){
            return getUnixMACAddress();
        }
        return mac;
    }
    /**
     * 获取widnows网卡的mac地址.
     *
     * @return mac地址
     */
    public static String getWindowsMACAddress() {
        String mac = null;
        BufferedReader bufferedReader = null;
        Process process = null;
        try {
            /**
             * windows下的命令,显示信息中包含有mac地址信息
             */
            process = Runtime.getRuntime().exec("ipconfig /all");
            bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = null;
            int index = -1;
            while ((line = bufferedReader.readLine()) != null) {
                /**
                 * 寻找标示字符串[physical address 或  物理地址]
                 */
                if (line.split("-").length == 6){
                    index = line.indexOf(":");
                    if (index != -1) {
                        /**
                         * 取出mac地址并去除2边空格
                         */
                        mac = line.substring(index + 1).trim();
                    }
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            bufferedReader = null;
            process = null;
        }
        return mac;
    }
    public static String getMac(){
        String os = getOSName();
        String mac;
        if (os.startsWith("windows")) {
            mac = getWindowsMACAddress();
        } else if (os.startsWith("linux")) {
            mac = getLinuxMACAddress();
        } else {
            mac = getUnixMACAddress();
        }
        return mac == null ? "" : mac;
    }
    /**
     * 测试用的main方法.
     *
     * @param argc 运行参数.
     */
    public static void main(String[] argc) {
        String mac = MacUtils.getMac();
        System.out.println(mac);
    }
}
ycl-common/src/main/java/com/ycl/utils/common/NetworkUtil.java
New file
@@ -0,0 +1,328 @@
package com.ycl.utils.common;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.StrTokenizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.regex.Pattern;
/**
 * @author Lyq
 * @version 1.0
 * @date 2022/9/7
 */
public class NetworkUtil {
    public static final String  REQ_TOKEY_KEY = "Authorization";
    /**
     * Logger for this class
     */
    private static final Logger LOGGER        = LoggerFactory.getLogger(NetworkUtil.class);
    /**
     * 方法名: getIpAddress
     * 方法描述: 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址;
     * 参数 @param request
     * 参数 @return
     * 参数 @throws IOException 参数说明
     * 返回类型 String 返回类型
     */
    public final static String getIpAddress(HttpServletRequest request) {
        // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址
        if(null==request){
            return "";
        }
        String ip = request.getHeader("x-original-forwarded-for");
//        if (LOGGER.isInfoEnabled()) {
//            LOGGER.info("getIpAddress(HttpServletRequest) - x-original-forwarded-for - String ip=" + ip);
//        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("X-Forwarded-For");
//            if (LOGGER.isInfoEnabled()) {
//                LOGGER.info("getIpAddress(HttpServletRequest) - X-Forwarded-For - String ip=" + ip);
//            }
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
//            if (LOGGER.isInfoEnabled()) {
//                LOGGER.info(
//                        "getIpAddress(HttpServletRequest) - Proxy-Client-IP - String ip=" + ip);
//            }
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
//            if (LOGGER.isInfoEnabled()) {
//                LOGGER.info(
//                        "getIpAddress(HttpServletRequest) - WL-Proxy-Client-IP - String ip=" + ip);
//            }
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
//            if (LOGGER.isInfoEnabled()) {
//                LOGGER.info(
//                        "getIpAddress(HttpServletRequest) - HTTP_CLIENT_IP - String ip=" + ip);
//            }
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
//            if (LOGGER.isInfoEnabled()) {
//                LOGGER
//                        .info("getIpAddress(HttpServletRequest) - HTTP_X_FORWARDED_FOR - String ip="
//                                + ip);
//            }
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
//            if (LOGGER.isInfoEnabled()) {
//                LOGGER.info("getIpAddress(HttpServletRequest) - getRemoteAddr - String ip=" + ip);
//            }
        }
        //防范ip欺骗,如果有多个逗号分隔的ip,必须读最后一个
        if (ip.length() > 15) {
            String[] ips = ip.split(",");
            ip = ips[ips.length -1];
        }
        return ip;
    }
    public static final String _255 = "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
    public static final Pattern pattern = Pattern.compile("^(?:" + _255 + "\\.){3}" + _255 + "$");
    public static String longToIpV4(long longIp) {
        int octet3 = (int) ((longIp >> 24) % 256);
        int octet2 = (int) ((longIp >> 16) % 256);
        int octet1 = (int) ((longIp >> 8) % 256);
        int octet0 = (int) ((longIp) % 256);
        return octet3 + "." + octet2 + "." + octet1 + "." + octet0;
    }
    public static long ipV4ToLong(String ip) {
        String[] octets = ip.split("\\.");
        return (Long.parseLong(octets[0]) << 24) + (Integer.parseInt(octets[1]) << 16)
                + (Integer.parseInt(octets[2]) << 8) + Integer.parseInt(octets[3]);
    }
    public static boolean isIPv4Private(String ip) {
        long longIp = ipV4ToLong(ip);
        return (longIp >= ipV4ToLong("10.0.0.0") && longIp <= ipV4ToLong("10.255.255.255"))
                || (longIp >= ipV4ToLong("172.16.0.0") && longIp <= ipV4ToLong("172.31.255.255"))
                || longIp >= ipV4ToLong("192.168.0.0") && longIp <= ipV4ToLong("192.168.255.255");
    }
    public static boolean isIPv4Valid(String ip) {
        return pattern.matcher(ip).matches();
    }
    public static String getIpFromRequest(HttpServletRequest request) {
        String ip;
        boolean found = false;
        if ((ip = request.getHeader("x-forwarded-for")) != null) {
            StrTokenizer tokenizer = new StrTokenizer(ip, ",");
            while (tokenizer.hasNext()) {
                ip = tokenizer.nextToken().trim();
                if (isIPv4Valid(ip) && !isIPv4Private(ip)) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
    /**
     * 方法名: getAccessToken
     * 方法描述: 获取token
     * 参数 @param request
     * 参数 @return 参数说明
     * 返回类型 String 返回类型
     */
    public static String getAccessToken(HttpServletRequest request) {
        String tokenNumber = request.getHeader(REQ_TOKEY_KEY);
        if (StringUtils.isBlank(tokenNumber)) {
            tokenNumber = request.getParameter("Authorization");
            LOGGER.debug("tokenNumber=" + tokenNumber);
        }
        return tokenNumber;
    }
    /**
     /**
     * 从请求头中获取指定key的值
     *
     * @param request
     * @param key
     * @return
     */
    public static String getHeaderByKey(HttpServletRequest request, String key) {
        if (StringUtils.isBlank(key)) {
            return null;
        }
        return request.getHeader(key);
    }
    /**
     * 从请求头中获取是否需要显示英文
     *
     * @param request
     * @param
     * @return true 显示英文、false 显示中文
     */
    public static boolean isEnglish(HttpServletRequest request) {
        if ("en".equalsIgnoreCase(getHeaderByKey(request,"language"))) {
            return true;
        }else{
            return false;
        }
    }
    public static String getHostNameForLiunx() {
        try {
            return (InetAddress.getLocalHost()).getHostName();
        } catch (UnknownHostException uhe) {
            String host = uhe.getMessage(); // host = "hostname: hostname"
            if (host != null) {
                int colon = host.indexOf(':');
                if (colon > 0) {
                    return host.substring(0, colon);
                }
            }
            return "UnknownHost";
        }
    }
    public static String getHostName() {
        if (System.getenv("COMPUTERNAME") != null) {
            return System.getenv("COMPUTERNAME");
        } else {
            return getHostNameForLiunx();
        }
    }
    public static boolean internalIp(String ip) {
        byte[] addr = textToNumericFormatV4(ip);
        if (null != addr) {
            return internalIp(addr) || "127.0.0.1".equals(ip);
        }
        return false;
    }
    private static boolean internalIp(byte[] addr) {
        final byte b0 = addr[0];
        final byte b1 = addr[1];
        // 10.x.x.x/8
        final byte SECTION_1 = 0x0A;
        // 172.16.x.x/12
        final byte SECTION_2 = (byte) 0xAC;
        final byte SECTION_3 = (byte) 0x10;
        final byte SECTION_4 = (byte) 0x1F;
        // 192.168.x.x/16
        final byte SECTION_5 = (byte) 0xC0;
        final byte SECTION_6 = (byte) 0xA8;
        switch (b0) {
            case SECTION_1:
                return true;
            case SECTION_2:
                if (b1 >= SECTION_3 && b1 <= SECTION_4) {
                    return true;
                }
            case SECTION_5:
                switch (b1) {
                    case SECTION_6:
                        return true;
                }
            default:
                return false;
        }
    }
    /**
     * 将IPv4地址转换成字节
     *
     * @param text IPv4地址
     * @return byte 字节
     */
    public static byte[] textToNumericFormatV4(String text) {
        if (text.length() == 0) {
            return null;
        }
        byte[] bytes = new byte[4];
        String[] elements = text.split("\\.", -1);
        try {
            long l;
            int i;
            switch (elements.length) {
                case 1:
                    l = Long.parseLong(elements[0]);
                    if ((l < 0L) || (l > 4294967295L)) {
                        return null;
                    }
                    bytes[0] = (byte) (int) (l >> 24 & 0xFF);
                    bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF);
                    bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
                    bytes[3] = (byte) (int) (l & 0xFF);
                    break;
                case 2:
                    l = Integer.parseInt(elements[0]);
                    if ((l < 0L) || (l > 255L)) {
                        return null;
                    }
                    bytes[0] = (byte) (int) (l & 0xFF);
                    l = Integer.parseInt(elements[1]);
                    if ((l < 0L) || (l > 16777215L)) {
                        return null;
                    }
                    bytes[1] = (byte) (int) (l >> 16 & 0xFF);
                    bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
                    bytes[3] = (byte) (int) (l & 0xFF);
                    break;
                case 3:
                    for (i = 0; i < 2; ++i) {
                        l = Integer.parseInt(elements[i]);
                        if ((l < 0L) || (l > 255L)) {
                            return null;
                        }
                        bytes[i] = (byte) (int) (l & 0xFF);
                    }
                    l = Integer.parseInt(elements[2]);
                    if ((l < 0L) || (l > 65535L)) {
                        return null;
                    }
                    bytes[2] = (byte) (int) (l >> 8 & 0xFF);
                    bytes[3] = (byte) (int) (l & 0xFF);
                    break;
                case 4:
                    for (i = 0; i < 4; ++i) {
                        l = Integer.parseInt(elements[i]);
                        if ((l < 0L) || (l > 255L)) {
                            return null;
                        }
                        bytes[i] = (byte) (int) (l & 0xFF);
                    }
                    break;
                default:
                    return null;
            }
        } catch (NumberFormatException e) {
            return null;
        }
        return bytes;
    }
}
ycl-common/src/main/java/com/ycl/utils/common/PojoUtils.java
New file
@@ -0,0 +1,35 @@
package com.ycl.utils.common;
import com.ycl.constant.SysConst;
/**
 * <p>
 * pojo工具类,dto,vo,使用
 * </p>
 *
 * @author Lyq
 * @version 1.0
 * @date 2022/9/7
 */
public class PojoUtils {
    private PojoUtils() {
    }
    static public class Vo{
        private Vo(){
        }
        /**
         * 前端combobox通过VO传递到后台的值是否是有效的查询条件。
         * 前端选(全部)时就不是有效的查询参数,在查询条件中去掉
         * @param n 传入的变量
         * @return 是否是有效查询参数
         */
        public static boolean isUsefulSearchParam(Number n){
            return n != null && n.intValue() != SysConst.COMBOBOX_ALL;
        }
    }
}
ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java
New file
@@ -0,0 +1,9 @@
package com.ycl.utils.common;
/**
 * @author Lyq
 * @version 1.0
 * @date 2022/9/7
 */
public class RandomUtils {
}
ycl-platform/src/main/java/com/ycl/component/DynamicSecurityFilter.java
@@ -45,7 +45,7 @@
        //白名单请求直接放行
        PathMatcher pathMatcher = new AntPathMatcher();
        for (String path : ignoreUrlsConfig.getUrls()) {
            if(pathMatcher.match(path,request.getRequestURI())){
            if(pathMatcher.match(path,request.getServletPath())){
                fi.getChain().doFilter(fi.getRequest(), fi.getResponse());
                return;
            }