| | |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.ObjectUtil; |
| | |
| | | String ipAddr = request.getRemoteAddr(); |
| | | // 先尝试从缓存当中取,存在就直接从缓存中获取 |
| | | String authToken = bladeRedis.get(PWD_FREE_LOGIN_TOKEN+ipAddr+":"+userName); |
| | | BladeUser user = null; |
| | | // 解析token存放进attr中 |
| | | String token2 = JwtUtil.getToken(authToken); |
| | | BladeUser user = this.getUser(token2); |
| | | //不存在就请求 |
| | | if(Func.isEmpty(authToken)){ |
| | | if(Func.isEmpty(authToken) || Func.isEmpty(user)){ |
| | | // 免密登录接口地址 |
| | | String loginUrl = "http://localhost:"+this.getGatewayPort("ubcs-gateway")+"/ubcs-auth/oauth/token"; |
| | | // 请求ubcs-auth服务获取token,先设置请求头 |
| | |
| | | authToken = "bearer " + tokenUserObject.getAccess_token(); |
| | | // 将token存入缓存当中,过期时间为24小时 |
| | | bladeRedis.setEx(PWD_FREE_LOGIN_TOKEN+ipAddr+":"+userName,"bearer "+tokenUserObject.getAccess_token(),tokenRedisExpire); |
| | | } |
| | | // 解析token存放进attr中 |
| | | String token2 = JwtUtil.getToken(authToken); |
| | | token2 = JwtUtil.getToken(authToken); |
| | | user = this.getUser(token2); |
| | | } |
| | | |
| | | //request.setAttribute("Blade-Auth",token); |
| | | request.setAttribute("_BLADE_USER_REQUEST_ATTR_",user); |
| | | return true; |
| | |
| | | if (StringUtil.isNotBlank(authToken)) { |
| | | token = JwtUtil.getToken(authToken); |
| | | } |
| | | |
| | | if (StringUtil.isNotBlank(token)) { |
| | | claims = parseJWT(token); |
| | | } |
| | | |
| | | if (ObjectUtil.isNotEmpty(claims) && getJwtProperties().getState()) { |
| | | tenantId = Func.toStr(claims.get("tenant_id")); |
| | | String userId = Func.toStr(claims.get("user_id")); |