| | |
| | | import com.auth0.jwt.interfaces.DecodedJWT; |
| | | import com.java110.core.context.ApiDataFlow; |
| | | import com.java110.core.context.DataFlow; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import com.java110.dto.reportData.ReportDataDto; |
| | | import com.java110.dto.reportData.ReportDataHeaderDto; |
| | | import com.java110.utils.cache.CommonCache; |
| | | import com.java110.utils.cache.JWTCache; |
| | | import com.java110.utils.cache.MappingCache; |
| | | import com.java110.utils.constant.CommonConstant; |
| | |
| | | import com.java110.utils.util.Base64Convert; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.slf4j.Logger; |
| | | |
| | | import javax.crypto.Cipher; |
| | | import javax.crypto.SecretKeyFactory; |
| | |
| | | * Created by wuxw on 2018/4/23. |
| | | */ |
| | | public class AuthenticationFactory { |
| | | private static Logger logger = LoggerFactory.getLogger(AuthenticationFactory.class); |
| | | |
| | | public final static String PASSWD_SALT = "hc@java110"; |
| | | |
| | |
| | | * 默认编码 |
| | | */ |
| | | private static final String CHARSET = "utf-8"; |
| | | |
| | | private static final String USER_ERROR_COUNT = "USER_ERROR_COUNT_";// 用户登录错误次数,防止暴力破解 |
| | | |
| | | |
| | | // 加密 |
| | |
| | | reqInfo += ((dataFlow.getReqBusiness() == null || dataFlow.getReqBusiness().size() == 0) |
| | | ? dataFlow.getReqData() : dataFlow.getReqBusiness().toJSONString()); |
| | | reqInfo += dataFlow.getAppRoutes().get(0).getSecurityCode(); |
| | | logger.debug("加密字符串={}",reqInfo); |
| | | return md5(reqInfo); |
| | | } |
| | | |
| | |
| | | reqInfo += "GET".equals(dataFlow.getRequestHeaders().get(CommonConstant.HTTP_METHOD)) ? |
| | | param : dataFlow.getReqData(); |
| | | reqInfo += dataFlow.getAppRoutes().get(0).getSecurityCode(); |
| | | logger.debug("加密字符串={}",reqInfo); |
| | | |
| | | return md5(reqInfo); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 登陆密码错误时 记录,连续输入错误7次后账号锁定 2小时 |
| | | * |
| | | * @param userName |
| | | */ |
| | | public static void userLoginError(String userName) { |
| | | String count = CommonCache.getValue(USER_ERROR_COUNT + userName); |
| | | int countNum = 0; |
| | | if (!StringUtil.isEmpty(count)) { |
| | | countNum = Integer.parseInt(count); |
| | | } |
| | | |
| | | countNum += 1; |
| | | |
| | | CommonCache.setValue(USER_ERROR_COUNT + userName, countNum + "", CommonCache.TOKEN_EXPIRE_TIME); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 校验 登录次数 |
| | | * |
| | | * @param userName 登录账号 |
| | | */ |
| | | public static void checkLoginErrorCount(String userName) { |
| | | String count = CommonCache.getValue(USER_ERROR_COUNT + userName); |
| | | int countNum = 0; |
| | | if (!StringUtil.isEmpty(count)) { |
| | | countNum = Integer.parseInt(count); |
| | | } |
| | | |
| | | if (countNum >= 5) { |
| | | throw new IllegalArgumentException("登陆错误次数过多,请休息一会再试"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /***********************************JWT start***************************************/ |
| | | |
| | | |
| | |
| | | // PrivateKey privateKey = keyPair.getPrivate(); |
| | | // System.out.println("私钥:" + new String(Base64.getEncoder().encode(privateKey.getEncoded()))); |
| | | |
| | | System.out.printf("passwdMd5 " + passwdMd5("397301")); |
| | | System.out.printf("passwdMd5 " + passwdMd5("V1TAj91GZXNNMlAR")); |
| | | System.out.printf("passwdMd5 " + md5("5616d148-c941-4873-9c1f-b59a08b4068320240108140611992020061452450002page=1&row=1123")); |
| | | |
| | | } |
| | | |