+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *
+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.epmet.jwt;
+
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
+import org.apache.commons.codec.binary.Base64;
+import org.joda.time.DateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Jwt工具类
+ *
+ * @author Mark sunlightcs@gmail.com
+ * @since 1.0.0
+ */
+@Component
+public class JwtTokenUtils {
+ private static final Logger logger = LoggerFactory.getLogger(JwtTokenUtils.class);
+
+ @Autowired
+ private JwtTokenProperties jwtProperties;
+
+ /**
+ * 生成jwt token 弃用
+ */
+ @Deprecated
+ public String generateToken(String userId) {
+ return Jwts.builder()
+ .setHeaderParam("typ", "JWT")
+ .setSubject(userId)
+ .setIssuedAt(new Date())
+ .setExpiration(DateTime.now().plusSeconds(jwtProperties.getExpire()).toDate())
+ .signWith(SignatureAlgorithm.HS512, jwtProperties.getSecret())
+ .compact();
+ }
+
+ public Claims getClaimByToken(String token) {
+ try {
+ return Jwts.parser()
+ .setSigningKey(jwtProperties.getSecret())
+ .parseClaimsJws(token)
+ .getBody();
+ } catch (Exception e) {
+ logger.debug("validate is token error, token = " + token, e);
+ return null;
+ }
+ }
+ public String createToken(Map
* https://www.renren.io
- *
+ *
* 版权所有,侵权必究!
*/
@@ -14,95 +14,101 @@ package com.epmet.commons.tools.redis;
*/
public class RedisKeys {
- /**
- * 党群e事通redis前缀
- */
- private static String rootPrefix = "epdc:";
-
- /**
- * 系统参数Key
- */
- public static String getSysParamsKey() {
- return rootPrefix.concat("sys:params");
- }
-
- /**
- * 登录验证码Key
- */
- public static String getLoginCaptchaKey(String uuid) {
- return rootPrefix.concat("sys:captcha:").concat(uuid);
- }
-
- /**
- * 登录用户Key
- */
- public static String getSecurityUserKey(Long id) {
- return rootPrefix.concat("sys:security:user:").concat(String.valueOf(id));
- }
-
- /**
- * 系统日志Key
- */
- public static String getSysLogKey() {
- return rootPrefix.concat("sys:log");
- }
-
- /**
- * 系统资源Key
- */
- public static String getSysResourceKey() {
- return rootPrefix.concat("sys:resource");
- }
-
- /**
- * 用户菜单导航Key
- */
- public static String getUserMenuNavKey(Long userId, String language) {
- return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_").concat(language);
- }
-
- /**
- * 用户菜单导航Key
- */
- public static String getUserMenuNavKey(Long userId) {
- return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_*");
- }
-
- /**
- * 用户权限标识Key
- */
- public static String getUserPermissionsKey(Long userId) {
- return rootPrefix.concat("sys:user:permissions:").concat(String.valueOf(userId));
- }
-
- public static String getCpUserKey(String id) {
- return rootPrefix.concat("sys:security:cpuser:").concat(id);
- }
-
- /**
- * 拼接手机验证码key---后面需要改!!!
- *
- * @param phone
- * @return java.lang.String
- * @author yujintao
- * @date 2019/9/6 17:03
- */
- public static String getPhoneSmsCodeKey(String phone) {
- return rootPrefix.concat("phone:sms:code:").concat(phone);
- }
-
- /**
- * 用户请求发送短信接口,记录本次请求时间,保存一分钟
- * ---后面需要改!!!
- * @param phone
- * @return java.lang.String
- * @author work@yujt.net.cn
- * @date 2019/12/6 19:05
- */
- public static String getPhoneSmsHistoryKey(String phone) {
- return rootPrefix.concat("phone:sms:history:").concat(phone);
- }
-
+ /**
+ * 党群e事通redis前缀
+ */
+ private static String rootPrefix = "epmet:";
+
+ /**
+ * 系统参数Key
+ */
+ public static String getSysParamsKey() {
+ return rootPrefix.concat("sys:params");
+ }
+
+ /**
+ * 登录验证码Key
+ */
+ public static String getLoginCaptchaKey(String uuid) {
+ return rootPrefix.concat("sys:captcha:").concat(uuid);
+ }
+
+ /**
+ * 登录用户Key
+ */
+ public static String getSecurityUserKey(Long id) {
+ return rootPrefix.concat("sys:security:user:").concat(String.valueOf(id));
+ }
+
+ /**
+ * 系统日志Key
+ */
+ public static String getSysLogKey() {
+ return rootPrefix.concat("sys:log");
+ }
+
+ /**
+ * 系统资源Key
+ */
+ public static String getSysResourceKey() {
+ return rootPrefix.concat("sys:resource");
+ }
+
+ /**
+ * 用户菜单导航Key
+ */
+ public static String getUserMenuNavKey(Long userId, String language) {
+ return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_").concat(language);
+ }
+
+ /**
+ * 用户菜单导航Key
+ */
+ public static String getUserMenuNavKey(Long userId) {
+ return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_*");
+ }
+
+ /**
+ * 用户权限标识Key
+ */
+ public static String getUserPermissionsKey(Long userId) {
+ return rootPrefix.concat("sys:user:permissions:").concat(String.valueOf(userId));
+ }
+
+ /**
+ * 用户token Key
+ * epmet:sys:security:user:resi:wxmp:100051424889632
+ * epmet:sys:security:user:gov:wxmp:5048212821254821
+ * epmet:sys:security:user:oper:web:eeedsfsdfds512551
+ */
+ public static String getCpUserKey(String app, String client, String id) {
+ return rootPrefix.concat("sys:security:user:").concat(app).concat(":").concat(client).concat(":").concat(id);
+ }
+
+ /**
+ * 拼接手机验证码key---后面需要改!!!
+ *
+ * @param phone
+ * @return java.lang.String
+ * @author yujintao
+ * @date 2019/9/6 17:03
+ */
+ public static String getPhoneSmsCodeKey(String phone) {
+ return rootPrefix.concat("phone:sms:code:").concat(phone);
+ }
+
+ /**
+ * 用户请求发送短信接口,记录本次请求时间,保存一分钟
+ * ---后面需要改!!!
+ *
+ * @param phone
+ * @return java.lang.String
+ * @author work@yujt.net.cn
+ * @date 2019/12/6 19:05
+ */
+ public static String getPhoneSmsHistoryKey(String phone) {
+ return rootPrefix.concat("phone:sms:history:").concat(phone);
+ }
}