| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.vci.ubcs.code.entity.TokenUserObject; |
| | | import com.vci.ubcs.code.service.IPasswordFreeLoginService; |
| | | import com.vci.ubcs.code.util.HttpUtils; |
| | | import com.vci.ubcs.starter.util.HttpUtils; |
| | | import io.jsonwebtoken.Claims; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.http.auth.AuthenticationException; |
| | | import org.springblade.core.jwt.JwtUtil; |
| | | import org.springblade.core.jwt.props.JwtProperties; |
| | | 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; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.logging.Logger; |
| | | |
| | | import static org.springblade.core.secure.utils.AuthUtil.parseJWT; |
| | | |
| | |
| | | * @date 2023/9/11 15:45 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class PasswordFreeLoginServiceImpl implements IPasswordFreeLoginService { |
| | | |
| | | // éè¿æå¡æ³¨åä¸å¿è·åç½å
³ç端å£å· |
| | |
| | | private DiscoveryClient discoveryClient; |
| | | // é
ç½®çå
å¯ç»å½çè´¦å·æå±çç§æ·id |
| | | @Value("${password-free.pwd-free-tenant-id}") |
| | | // é
ç½®çtokenå¨redisä¸ççåæ¶é´ |
| | | private String pwdFreeTenantId; |
| | | // é
ç½®çtokenå¨redisä¸ççåæ¶é´ |
| | | @Value("${password-free.token-redis-expire}") |
| | | private Long tokenRedisExpire; |
| | | @Value("${password-free.pwd-free-addr}") |
| | | private String pwdFreeAddr; |
| | | @Autowired |
| | | private BladeRedis bladeRedis; |
| | | |
| | |
| | | //ä¸åå¨å°±è¯·æ± |
| | | if(Func.isEmpty(authToken) || Func.isEmpty(user)){ |
| | | // å
å¯ç»å½æ¥å£å°å |
| | | String loginUrl = "http://localhost:"+this.getGatewayPort("ubcs-gateway")+"/ubcs-auth/oauth/token"; |
| | | String loginUrl = "http://"+pwdFreeAddr+":"+this.getGatewayPort("ubcs-gateway")+"/ubcs-auth/oauth/token"; |
| | | log.debug("å½åå
å¯ç»å½è°ç¨å°åï¼"+loginUrl); |
| | | // 请æ±ubcs-authæå¡è·åtokenï¼å
设置请æ±å¤´ |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | |
| | | token2 = JwtUtil.getToken(authToken); |
| | | user = this.getUser(token2); |
| | | } |
| | | |
| | | //request.setAttribute("Blade-Auth",token); |
| | | request.setAttribute("_BLADE_USER_REQUEST_ATTR_",user); |
| | | return true; |