增加注释,优化代码
parent
65abc667b0
commit
13a9405082
|
@ -56,6 +56,8 @@ import static java.util.Collections.singleton;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SysAuthServiceImpl implements SysAuthService {
|
public class SysAuthServiceImpl implements SysAuthService {
|
||||||
|
|
||||||
|
private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.ADMIN;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Lazy // 延迟加载,因为存在相互依赖的问题
|
@Lazy // 延迟加载,因为存在相互依赖的问题
|
||||||
private AuthenticationManager authenticationManager;
|
private AuthenticationManager authenticationManager;
|
||||||
|
@ -75,7 +77,6 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||||
@Resource
|
@Resource
|
||||||
private SysSocialCoreService socialService;
|
private SysSocialCoreService socialService;
|
||||||
|
|
||||||
private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.ADMIN;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
|
|
|
@ -1,24 +1,21 @@
|
||||||
package cn.iocoder.yudao.framework.social.core;
|
package cn.iocoder.yudao.framework.social.core;
|
||||||
|
|
||||||
import cn.hutool.core.util.EnumUtil;
|
import cn.hutool.core.util.EnumUtil;
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource;
|
import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource;
|
||||||
import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMiniProgramRequest;
|
import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMiniProgramRequest;
|
||||||
import com.xkcoding.http.config.HttpConfig;
|
|
||||||
import com.xkcoding.justauth.AuthRequestFactory;
|
import com.xkcoding.justauth.AuthRequestFactory;
|
||||||
import com.xkcoding.justauth.autoconfigure.JustAuthProperties;
|
import com.xkcoding.justauth.autoconfigure.JustAuthProperties;
|
||||||
import me.zhyd.oauth.cache.AuthStateCache;
|
import me.zhyd.oauth.cache.AuthStateCache;
|
||||||
import me.zhyd.oauth.config.AuthConfig;
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
import me.zhyd.oauth.config.AuthSource;
|
import me.zhyd.oauth.config.AuthSource;
|
||||||
import me.zhyd.oauth.request.AuthRequest;
|
import me.zhyd.oauth.request.AuthRequest;
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.lang.reflect.Method;
|
||||||
import java.net.Proxy;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 第三方授权拓展 request 工厂类
|
* 第三方授权拓展 request 工厂类
|
||||||
* TODO @timfruit 可以说明下,为啥有了 AuthRequestFactory 类,咱还需要自定义
|
* (为使得拓展配置和默认配置齐平,自定义本工厂类)
|
||||||
*
|
*
|
||||||
* @author timfruit
|
* @author timfruit
|
||||||
* @date 2021-10-31
|
* @date 2021-10-31
|
||||||
|
@ -70,7 +67,10 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 配置 http config
|
// 配置 http config
|
||||||
configureHttpConfig(authExtendSource.name(), config, properties.getHttpConfig());
|
Method method = ReflectUtil.getMethod(AuthRequestFactory.class, "configureHttpConfig",
|
||||||
|
String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class);
|
||||||
|
ReflectUtil.invoke(this, method,
|
||||||
|
authExtendSource.name(), config, properties.getHttpConfig());
|
||||||
|
|
||||||
switch (authExtendSource) {
|
switch (authExtendSource) {
|
||||||
case WECHAT_MINI_PROGRAM:
|
case WECHAT_MINI_PROGRAM:
|
||||||
|
@ -80,31 +80,4 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置 http 相关的配置
|
|
||||||
*
|
|
||||||
* @param authSource {@link AuthSource}
|
|
||||||
* @param authConfig {@link AuthConfig}
|
|
||||||
*/
|
|
||||||
protected void configureHttpConfig(String authSource, AuthConfig authConfig, JustAuthProperties.JustAuthHttpConfig httpConfig) {
|
|
||||||
// TODO @timfruit:可以改成反射调用父类的方法。可能有一定的损耗,但是可以忽略不计的
|
|
||||||
if (null == httpConfig) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Map<String, JustAuthProperties.JustAuthProxyConfig> proxyConfigMap = httpConfig.getProxy();
|
|
||||||
if (CollectionUtils.isEmpty(proxyConfigMap)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JustAuthProperties.JustAuthProxyConfig proxyConfig = proxyConfigMap.get(authSource);
|
|
||||||
|
|
||||||
if (null == proxyConfig) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
authConfig.setHttpConfig(HttpConfig.builder()
|
|
||||||
.timeout(httpConfig.getTimeout())
|
|
||||||
.proxy(new Proxy(Proxy.Type.valueOf(proxyConfig.getType()), new InetSocketAddress(proxyConfig.getHostname(), proxyConfig.getPort())))
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,11 @@ package cn.iocoder.yudao.framework.social.core.enums;
|
||||||
|
|
||||||
import me.zhyd.oauth.config.AuthSource;
|
import me.zhyd.oauth.config.AuthSource;
|
||||||
|
|
||||||
// TODO @timfruit:类注释
|
/**
|
||||||
|
* 拓展JustAuth各api需要的url, 用枚举类分平台类型管理<br>
|
||||||
|
*
|
||||||
|
* 默认配置{@link me.zhyd.oauth.config.AuthDefaultSource}
|
||||||
|
*/
|
||||||
public enum AuthExtendSource implements AuthSource {
|
public enum AuthExtendSource implements AuthSource {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.social.core.request;
|
||||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||||
import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource;
|
import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource;
|
||||||
import cn.iocoder.yudao.framework.social.core.model.AuthExtendToken;
|
import cn.iocoder.yudao.framework.social.core.model.AuthExtendToken;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import me.zhyd.oauth.cache.AuthStateCache;
|
import me.zhyd.oauth.cache.AuthStateCache;
|
||||||
import me.zhyd.oauth.config.AuthConfig;
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
|
@ -39,7 +40,7 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest {
|
||||||
this.checkResponse(accessTokenObject);
|
this.checkResponse(accessTokenObject);
|
||||||
|
|
||||||
AuthExtendToken token = new AuthExtendToken();
|
AuthExtendToken token = new AuthExtendToken();
|
||||||
token.setMiniSessionKey(accessTokenObject.session_key);
|
token.setMiniSessionKey(accessTokenObject.sessionKey);
|
||||||
token.setOpenId(accessTokenObject.openid);
|
token.setOpenId(accessTokenObject.openid);
|
||||||
token.setUnionId(accessTokenObject.unionid);
|
token.setUnionId(accessTokenObject.unionid);
|
||||||
return token;
|
return token;
|
||||||
|
@ -86,12 +87,12 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @timfruit:我们要采用驼峰的命名方式。不匹配的,可以通过 jackson 的自定义注解映射
|
|
||||||
@Data
|
@Data
|
||||||
private static class CodeSessionResponse {
|
private static class CodeSessionResponse {
|
||||||
private int errcode;
|
private int errcode;
|
||||||
private String errmsg;
|
private String errmsg;
|
||||||
private String session_key;
|
@JsonProperty("session_key")
|
||||||
|
private String sessionKey;
|
||||||
private String openid;
|
private String openid;
|
||||||
private String unionid;
|
private String unionid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConst
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SysAuthServiceImpl implements SysAuthService {
|
public class SysAuthServiceImpl implements SysAuthService {
|
||||||
|
|
||||||
|
private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.MEMBER;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Lazy // 延迟加载,因为存在相互依赖的问题
|
@Lazy // 延迟加载,因为存在相互依赖的问题
|
||||||
private AuthenticationManager authenticationManager;
|
private AuthenticationManager authenticationManager;
|
||||||
|
@ -65,7 +67,7 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||||
private SysUserSessionCoreService userSessionCoreService;
|
private SysUserSessionCoreService userSessionCoreService;
|
||||||
@Resource
|
@Resource
|
||||||
private SysSocialCoreService socialService;
|
private SysSocialCoreService socialService;
|
||||||
private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.MEMBER; // TODO @timfruit 挪到类的最前面。一般是 静态变量,到成员变量的顺序。
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException {
|
||||||
|
|
Loading…
Reference in New Issue