记得上下班打卡 | git大法好,push需谨慎

Commit f2c26e4b authored by 张国柄's avatar 张国柄

fix sso token;

parent 20dc9510
...@@ -9,7 +9,7 @@ public class AdamRedisConst { ...@@ -9,7 +9,7 @@ public class AdamRedisConst {
public static final String INFO_IDENTITY = ADAM.concat(":identity"); public static final String INFO_IDENTITY = ADAM.concat(":identity");
public static final String INFO_IDENTITY_MOBILE = INFO_IDENTITY.concat(":mobile"); public static final String INFO_IDENTITY_MOBILE = INFO_IDENTITY.concat(":mobile");
public static final String INFO_IDENTITY_THIRD_PARTY = INFO_IDENTITY.concat(":third_party"); public static final String INFO_IDENTITY_THIRD_PARTY = INFO_IDENTITY.concat(":third_party");
public static final String INFO_USER = ADAM.concat(":list:users"); public static final String INFO_USER = ADAM.concat(":list:user");
public static final String INFO_REAL_NAME = ADAM.concat(":list:real_name"); public static final String INFO_REAL_NAME = ADAM.concat(":list:real_name");
public static final String INFO_THIRD_PARTY = ADAM.concat(":list:third_party"); public static final String INFO_THIRD_PARTY = ADAM.concat(":list:third_party");
public static final String INFO_ENTERS = ADAM.concat(":list:enters:"); public static final String INFO_ENTERS = ADAM.concat(":list:enters:");
......
...@@ -121,11 +121,11 @@ public class AdamLoginController { ...@@ -121,11 +121,11 @@ public class AdamLoginController {
AdamUserInfoVo userInfoVo = AdamUserInfoVo userInfoVo =
StringUtils.isEmpty(uid) ? adamUserService.register(mobile) : adamUserService.queryByUid(uid); StringUtils.isEmpty(uid) ? adamUserService.register(mobile) : adamUserService.queryByUid(uid);
AdamLoginInfoVo loginInfoVo = AdamLoginInfoVo.getNew(); AdamLoginInfoVo loginInfoVo = AdamLoginInfoVo.getNew();
if (userInfoVo.getIsComplete() == 1) { // if (userInfoVo.getIsComplete() == 1) {
loginInfoVo.setRealNameInfo(adamRealNameService.queryByUid(userInfoVo.getUid())); loginInfoVo.setRealNameInfo(adamRealNameService.queryByUid(userInfoVo.getUid()));
loginInfoVo.setThirdPartInfo(adamThirdPartyService.queryByUid(userInfoVo.getUid())); loginInfoVo.setThirdPartInfo(adamThirdPartyService.queryByUid(userInfoVo.getUid()));
loginInfoVo.setMemberInfo(adamUserMemberService.getUserMemberInfo(userInfoVo.getUid())); loginInfoVo.setMemberInfo(adamUserMemberService.getUserMemberInfo(userInfoVo.getUid()));
} // }
loginInfoVo.setUserInfo(userInfoVo); loginInfoVo.setUserInfo(userInfoVo);
Map<String, Object> claimsMap = new HashMap<>(); Map<String, Object> claimsMap = new HashMap<>();
...@@ -151,11 +151,11 @@ public class AdamLoginController { ...@@ -151,11 +151,11 @@ public class AdamLoginController {
AdamUserInfoVo userInfoVo = AdamUserInfoVo userInfoVo =
StringUtils.isEmpty(uid) ? adamUserService.register(mobile) : adamUserService.queryByUid(uid); StringUtils.isEmpty(uid) ? adamUserService.register(mobile) : adamUserService.queryByUid(uid);
AdamLoginInfoVo loginInfoVo = AdamLoginInfoVo.getNew(); AdamLoginInfoVo loginInfoVo = AdamLoginInfoVo.getNew();
if (loginInfoVo.getUserInfo().getIsComplete() == 1) { // if (loginInfoVo.getUserInfo().getIsComplete() == 1) {
loginInfoVo.setRealNameInfo(adamRealNameService.queryByUid(userInfoVo.getUid())); loginInfoVo.setRealNameInfo(adamRealNameService.queryByUid(userInfoVo.getUid()));
loginInfoVo.setThirdPartInfo(adamThirdPartyService.queryByUid(userInfoVo.getUid())); loginInfoVo.setThirdPartInfo(adamThirdPartyService.queryByUid(userInfoVo.getUid()));
loginInfoVo.setMemberInfo(adamUserMemberService.getUserMemberInfo(userInfoVo.getUid())); loginInfoVo.setMemberInfo(adamUserMemberService.getUserMemberInfo(userInfoVo.getUid()));
} // }
loginInfoVo.setUserInfo(userInfoVo); loginInfoVo.setUserInfo(userInfoVo);
Map<String, Object> claimsMap = new HashMap<>(); Map<String, Object> claimsMap = new HashMap<>();
...@@ -262,11 +262,15 @@ public class AdamLoginController { ...@@ -262,11 +262,15 @@ public class AdamLoginController {
} }
private String ssoProcess(Map<String, Object> claimsMap) { private String ssoProcess(Map<String, Object> claimsMap) {
redisUtil.delKeysByPrefix(jwtValidator.getSsoRedisKey()); String uid = (String) claimsMap.get("uid");
String uidSso = jwtValidator.getSsoRedisKey().concat(uid);
redisUtil.delKeysByPrefix(uidSso);
String token = jwtValidator.create(claimsMap); String token = jwtValidator.create(claimsMap);
String ssoKey = jwtValidator.getSsoRedisKey().concat(DigestUtils.md5DigestAsHex(token.getBytes(StandardCharsets.UTF_8))); String ssoKey = uidSso.concat(DigestUtils.md5DigestAsHex(token.getBytes(StandardCharsets.UTF_8)));
redisUtil.set(ssoKey, true, jwtValidator.getExpireTtl() * 60); redisUtil.set(ssoKey, true, jwtValidator.getExpireTtl() * 60);
......
...@@ -38,7 +38,7 @@ public class AdamThirdPartyServiceImpl extends ServiceImpl<AdamThirdPartyMapper, ...@@ -38,7 +38,7 @@ public class AdamThirdPartyServiceImpl extends ServiceImpl<AdamThirdPartyMapper,
thirdPartInfoVos = mongoTemplate.find(Query.query(Criteria.where("uid").is(uid).and("state").is(1)), thirdPartInfoVos = mongoTemplate.find(Query.query(Criteria.where("uid").is(uid).and("state").is(1)),
AdamThirdPartInfoVo.class); AdamThirdPartInfoVo.class);
redisUtil.hset(AdamRedisConst.INFO_THIRD_PARTY, uid, thirdPartInfoVos); if (!CollectionUtils.isEmpty(thirdPartInfoVos)) redisUtil.hset(AdamRedisConst.INFO_THIRD_PARTY, uid, thirdPartInfoVos);
} }
return thirdPartInfoVos; return thirdPartInfoVos;
} }
......
...@@ -68,8 +68,8 @@ public class AdamUserInfoServiceImpl extends ServiceImpl<AdamUserInfoMapper, Ada ...@@ -68,8 +68,8 @@ public class AdamUserInfoServiceImpl extends ServiceImpl<AdamUserInfoMapper, Ada
userInfoVo.getTagMe(), userInfoVo.getTagMe(),
userInfoVo.getUid() userInfoVo.getUid()
); );
rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL, MQConst.ROUTING_KEY_SQL, // rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL, MQConst.ROUTING_KEY_SQL,
SqlMapping.get(userInfoVo.getIsComplete() == 0 ? "adam_user_info.add" : "adam_user_info.edit", paramList.toArray())); // SqlMapping.get(userInfoVo.getIsComplete() == 0 ? "adam_user_info.add" : "adam_user_info.edit", paramList.toArray()));
redisUtil.hset(AdamRedisConst.INFO_USER, userInfoVo.getUid(), userInfoVo); redisUtil.hset(AdamRedisConst.INFO_USER, userInfoVo.getUid(), userInfoVo);
} }
......
...@@ -84,15 +84,6 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i ...@@ -84,15 +84,6 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i
@Override @Override
public String queryUidByRedis(String mobile) { public String queryUidByRedis(String mobile) {
return (String) redisUtil.hget(AdamRedisConst.INFO_IDENTITY_MOBILE, mobile); return (String) redisUtil.hget(AdamRedisConst.INFO_IDENTITY_MOBILE, mobile);
// AdamUserInfoVo userInfoVo;
// if (null == (userInfoVo = (AdamUserInfoVo) redisUtil.hget(AdamRedisConst.INFO_MOBILES, mobile))) {
// userInfoVo = mongoTemplate.findOne(Query.query(Criteria.where("mobile").is(mobile).and("state").is(1)),
// AdamUserInfoVo.class, AdamUserInfoVo.class.getSimpleName());
//
// redisUtil.hset(AdamRedisConst.INFO_MOBILES, mobile, userInfoVo);
// }
// return userInfoVo;
} }
@Override @Override
...@@ -102,15 +93,22 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i ...@@ -102,15 +93,22 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i
@Override @Override
public AdamUserInfoVo register(String mobile) { public AdamUserInfoVo register(String mobile) {
LocalDateTime now = LocalDateTime.now();
String nowStr = DateUtil.format(now, DateUtil.Formatter.yyyyMMddHHmmss);
AdamUserInfoVo userInfoVo = AdamUserInfoVo.getNew(); AdamUserInfoVo userInfoVo = AdamUserInfoVo.getNew();
userInfoVo.setMobile(mobile); userInfoVo.setMobile(mobile);
userInfoVo.setUid(IDGenerator.nextSnowId() + ""); userInfoVo.setUid(IDGenerator.nextSnowId() + "");
userInfoVo.setIsComplete(0); userInfoVo.setIsComplete(0);
userInfoVo.setState(1); userInfoVo.setState(1);
userInfoVo.setQrCode("lN".concat(userInfoVo.getUid()).concat(RandomStringUtils.randomAlphanumeric(5).toUpperCase())); userInfoVo.setQrCode("lN".concat(userInfoVo.getUid()).concat(RandomStringUtils.randomAlphanumeric(5).toUpperCase()));
userInfoVo.setCreateAt(DateUtil.getNowTime()); userInfoVo.setCreateAt(nowStr);
Collection<AdamUserInfoVo> vos = mongoTemplate.insert(Collections.singletonList(userInfoVo), AdamUserInfoVo.class.getSimpleName()); AdamUserInfoVo insert = mongoTemplate.insert(userInfoVo, AdamUserInfoVo.class.getSimpleName());
List<Object> paramList = Arrays.asList(userInfoVo.getUid(), userInfoVo.getMobile(), userInfoVo.getState(), now);
// rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL, MQConst.ROUTING_KEY_SQL,
// SqlMapping.get("adam_user.add", paramList.toArray()));
redisUtil.hset(AdamRedisConst.INFO_IDENTITY_MOBILE, mobile, userInfoVo.getUid()); redisUtil.hset(AdamRedisConst.INFO_IDENTITY_MOBILE, mobile, userInfoVo.getUid());
...@@ -133,7 +131,7 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i ...@@ -133,7 +131,7 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i
userInfoVo.setQrCode("lN".concat(userInfoVo.getUid()).concat(RandomStringUtils.randomAlphanumeric(5).toUpperCase())); userInfoVo.setQrCode("lN".concat(userInfoVo.getUid()).concat(RandomStringUtils.randomAlphanumeric(5).toUpperCase()));
userInfoVo.setCreateAt(nowStr); userInfoVo.setCreateAt(nowStr);
Collection<AdamUserInfoVo> userInfoVos = mongoTemplate.insert(Collections.singletonList(userInfoVo), AdamUserInfoVo.class); AdamUserInfoVo insert = mongoTemplate.insert(userInfoVo, AdamUserInfoVo.class.getSimpleName());
} else { } else {
userInfoVo = this.queryByUid(uid); userInfoVo = this.queryByUid(uid);
} }
...@@ -144,17 +142,22 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i ...@@ -144,17 +142,22 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i
thirdPartInfoVo.setUid(userInfoVo.getUid()); thirdPartInfoVo.setUid(userInfoVo.getUid());
thirdPartInfoVo.setState(1);// 1-绑定 thirdPartInfoVo.setState(1);// 1-绑定
// boolean userInfoSetRst = redisUtil.hset(AdamRedisConst.INFO_MOBILES, thirdPartParam.getMobile(), userInfoVo); AdamThirdPartInfoVo insert = mongoTemplate.insert(thirdPartInfoVo, AdamThirdPartInfoVo.class.getSimpleName());
// boolean thirdPartSetRst = redisUtil.hset(AdamRedisConst.INFO_THIRD_PARTY.concat(thirdPartInfoVo.getPlatform()), thirdPartInfoVo.getOpenId(), thirdPartInfoVo);
Collection<AdamThirdPartInfoVo> thirdPartInfoVos = mongoTemplate.insert(Collections.singletonList(thirdPartInfoVo), AdamThirdPartInfoVo.class); List<Object> paramList = Arrays.asList(
// TODO: 2021/5/14 Execute sql to mq thirdPartInfoVo.getUid(),
thirdPartInfoVo.getOpenId(),
thirdPartInfoVo.getAvatar(),
thirdPartInfoVo.getNickname(),
thirdPartInfoVo.getPlatform(),
thirdPartInfoVo.getState(),
thirdPartInfoVo.getCreatedAt()
);
// rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL, MQConst.ROUTING_KEY_SQL,
// SqlMapping.get("adam_third_party.add", paramList.toArray()));
redisUtil.hset(AdamRedisConst.INFO_IDENTITY_THIRD_PARTY, param.getPlatform().concat(param.getOpenId()), userInfoVo.getUid()); redisUtil.hset(AdamRedisConst.INFO_IDENTITY_THIRD_PARTY, param.getPlatform().concat(param.getOpenId()), userInfoVo.getUid());
// List<Object> paramList = Arrays.asList();
// rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL, MQConst.ROUTING_KEY_SQL,
// SqlMapping.get("adam_user.add", paramList.toArray()));
return userInfoVo; return userInfoVo;
} }
...@@ -251,7 +254,6 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i ...@@ -251,7 +254,6 @@ public class AdamUserServiceImpl extends ServiceImpl<AdamUserMapper, AdamUser> i
List<Object> paramList = Arrays.asList(closeUserInfoVo.getState(), now, now, uid); List<Object> paramList = Arrays.asList(closeUserInfoVo.getState(), now, now, uid);
// rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL, MQConst.ROUTING_KEY_SQL, // rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL, MQConst.ROUTING_KEY_SQL,
// SqlMapping.get("adam_user.close", paramList.toArray())); // SqlMapping.get("adam_user.close", paramList.toArray()));
// TODO: 2021/5/14 Execute sql to mq
redisUtil.hdel(AdamRedisConst.INFO_USER, uid); redisUtil.hdel(AdamRedisConst.INFO_USER, uid);
......
adam_third_party.add=insert into ln_adam.adam_third_party (`uid`, open_id, avatar, nickname, platform, `state`, created_at, updated_at, `comment`) values (?,?,?,?,?,?,?,?,?) adam_third_party.add=INSERT INTO ln_adam.adam_third_party (`uid`, open_id, avatar, nickname, platform, `state`, created_at) values (?,?,?,?,?,?,?)
\ No newline at end of file \ No newline at end of file
adam_user.add=INSERT INTO ln_adam.adam_user (`uid`, mobile, passwd, pay_code, `state`, created_at, updated_at, closed_at, `comment`) VALUES (?,?,?,?,?,?,?,?,?) adam_user.add=INSERT INTO ln_adam.adam_user (`uid`, mobile, `state`, created_at) VALUES (?,?,?,?)
adam_user.close=UPDATE ln_adam.adam_user SET `state`=2, updated_at=?, closed_at=? WHERE `uid`=? adam_user.close=UPDATE ln_adam.adam_user SET `state`=2, updated_at=?, closed_at=? WHERE `uid`=?
\ No newline at end of file
...@@ -80,13 +80,15 @@ public class GlobalAuthFilter extends ZuulFilter { ...@@ -80,13 +80,15 @@ public class GlobalAuthFilter extends ZuulFilter {
} else { } else {
String token = authorization.substring(7); String token = authorization.substring(7);
String ssoKey = jwtValidator.getSsoRedisKey().concat(DigestUtils.md5DigestAsHex(token.getBytes(StandardCharsets.UTF_8))); // 解析没有异常则表示token验证通过,如有必要可根据自身需求增加验证逻辑
Claims claims = jwtValidator.parse(token);
String uid = (String) claims.get("uid");
String ssoKey = jwtValidator.getSsoRedisKey().concat(uid).concat(DigestUtils.md5DigestAsHex(token.getBytes(StandardCharsets.UTF_8)));
if (redisUtil.hasKey(ssoKey)) { if (redisUtil.hasKey(ssoKey)) {
if ((boolean) redisUtil.get(ssoKey)) { if ((boolean) redisUtil.get(ssoKey)) {
// 解析没有异常则表示token验证通过,如有必要可根据自身需求增加验证逻辑
Claims claims = jwtValidator.parse(token);
requestContext.setSendZuulResponse(true); requestContext.setSendZuulResponse(true);
// requestContext.addZuulRequestHeader("uid", claims.get("uid").toString()); // requestContext.addZuulRequestHeader("uid", claims.get("uid").toString());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment