Commit 361ab204 authored by hubin's avatar hubin

删除一些无用代码

parent 321ba575
...@@ -59,12 +59,6 @@ ...@@ -59,12 +59,6 @@
<version>0.0.1</version> <version>0.0.1</version>
</dependency> </dependency>
<!--微信服务api-->
<dependency>
<groupId>com.hungraim.ism</groupId>
<artifactId>wechat-api</artifactId>
<version>0.0.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
...@@ -3,8 +3,6 @@ package com.hungraim.ism.gateway.config; ...@@ -3,8 +3,6 @@ package com.hungraim.ism.gateway.config;
import cn.hutool.http.HttpStatus; import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.hungraim.ism.api.WechatFeignService;
import com.hungraim.ism.gateway.config.tokenGranters.EnterpriseWechatTokenGranter;
import com.hungraim.ism.pojo.vo.system.UserLoginInfoVO; import com.hungraim.ism.pojo.vo.system.UserLoginInfoVO;
import com.hungraim.ism.service.UserDetailsServiceImpl; import com.hungraim.ism.service.UserDetailsServiceImpl;
import com.hungraim.ism.util.Result; import com.hungraim.ism.util.Result;
...@@ -59,14 +57,12 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu ...@@ -59,14 +57,12 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu
private final AuthenticationManager authenticationManager; private final AuthenticationManager authenticationManager;
private final UserDetailsServiceImpl userDetailsService; private final UserDetailsServiceImpl userDetailsService;
private final DataSource dataSource; private final DataSource dataSource;
private final WechatFeignService wechatFeignService;
@Autowired @Autowired
public AuthorizationServerConfiguration(AuthenticationManager authenticationManager, DataSource dataSource, UserDetailsServiceImpl userDetailsService, WechatFeignService wechatFeignService) { public AuthorizationServerConfiguration(AuthenticationManager authenticationManager, DataSource dataSource, UserDetailsServiceImpl userDetailsService) {
this.authenticationManager = authenticationManager; this.authenticationManager = authenticationManager;
this.dataSource = dataSource; this.dataSource = dataSource;
this.userDetailsService = userDetailsService; this.userDetailsService = userDetailsService;
this.wechatFeignService = wechatFeignService;
} }
...@@ -100,7 +96,6 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu ...@@ -100,7 +96,6 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu
.accessTokenConverter(jwtAccessTokenConverter()) .accessTokenConverter(jwtAccessTokenConverter())
.tokenEnhancer(tokenEnhancerChain) .tokenEnhancer(tokenEnhancerChain)
.userDetailsService(userDetailsService) .userDetailsService(userDetailsService)
.tokenGranter(tokenGranter(endpoints))
// refresh token有两种使用方式:重复使用(true)、非重复使用(false),默认为true // refresh token有两种使用方式:重复使用(true)、非重复使用(false),默认为true
// 1 重复使用:access token过期刷新时, refresh token过期时间未改变,仍以初次生成的时间为准 // 1 重复使用:access token过期刷新时, refresh token过期时间未改变,仍以初次生成的时间为准
// 2 非重复使用:access token过期刷新时, refresh token过期时间延续,在refresh token有效期内刷新便永不失效达到无需再次登录的目的 // 2 非重复使用:access token过期刷新时, refresh token过期时间延续,在refresh token有效期内刷新便永不失效达到无需再次登录的目的
...@@ -115,46 +110,6 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu ...@@ -115,46 +110,6 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu
.allowFormAuthenticationForClients(); .allowFormAuthenticationForClients();
} }
private TokenGranter tokenGranter(AuthorizationServerEndpointsConfigurer endpoints) {
List<TokenGranter> list = new ArrayList<>();
// 这里配置密码模式
if (authenticationManager != null) {
list.add(new ResourceOwnerPasswordTokenGranter(authenticationManager,
endpoints.getTokenServices(),
endpoints.getClientDetailsService(),
endpoints.getOAuth2RequestFactory()));
}
//刷新token模式、
list.add(new RefreshTokenGranter
(endpoints.getTokenServices(),
endpoints.getClientDetailsService(),
endpoints.getOAuth2RequestFactory()));
//授权码模式、
list.add(new AuthorizationCodeTokenGranter(
endpoints.getTokenServices(),
endpoints.getAuthorizationCodeServices(),
endpoints.getClientDetailsService(),
endpoints.getOAuth2RequestFactory()));
//、简化模式
list.add(new ImplicitTokenGranter(
endpoints.getTokenServices(),
endpoints.getClientDetailsService(),
endpoints.getOAuth2RequestFactory()));
//客户端模式
list.add(new ClientCredentialsTokenGranter(endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory()));
list.add(new EnterpriseWechatTokenGranter(
endpoints.getTokenServices(),
endpoints.getClientDetailsService(),
endpoints.getOAuth2RequestFactory(),
wechatFeignService));
return new CompositeTokenGranter(list);
}
/** /**
......
package com.hungraim.ism.gateway.config.tokenGranters;
import com.hungraim.ism.api.WechatFeignService;
import com.hungraim.ism.pojo.entity.system.SystemUser;
import com.hungraim.ism.pojo.vo.system.UserLoginInfoVO;
import com.hungraim.ism.util.Result;
import com.hungraim.ism.util.ResultCode;
import org.springframework.security.core.Authentication;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
import org.springframework.security.oauth2.provider.*;
import org.springframework.security.oauth2.provider.token.AbstractTokenGranter;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 自定义grant_type模式--企业微信认证
* @author hubin
*/
public class EnterpriseWechatTokenGranter extends AbstractTokenGranter {
private static final String GRANT_TYPE = "enterpriseWechat";
private final WechatFeignService wechatFeignService;
public EnterpriseWechatTokenGranter(AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory oAuth2RequestFactory, WechatFeignService wechatFeignService) {
super(tokenServices,clientDetailsService,oAuth2RequestFactory,GRANT_TYPE);
this.wechatFeignService = wechatFeignService;
}
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
@Override
protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
Map<String, String> parameters = new LinkedHashMap<>(tokenRequest.getRequestParameters());
String code = parameters.get("code");
//通过code去企业微信获取用户id 再组装成用户
Result<SystemUser> user = wechatFeignService.getUserInfoByCode(code);
if(user==null || !ResultCode.SUCCESS.getCode().equals(user.getCode())){
throw new InvalidGrantException(user.getMsg());
}
UserDetails userDTO = new UserLoginInfoVO(user.getData());
Authentication userAuth = new UsernamePasswordAuthenticationToken(userDTO, null, userDTO.getAuthorities());
return new OAuth2Authentication( getRequestFactory().createOAuth2Request(client, tokenRequest), userAuth);
}
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
echo '开始构建智能营销平台项目' echo '开始构建智能营销平台项目'
export PATH=${PATH}:/usr/local/maven/bin export PATH=${PATH}:/usr/local/maven/bin
buildDeploys=("common/common-core" "common/common-mybatis" "common/common-redis" "system/system-api" "wechat/wechat-api") buildDeploys=("common/common-core" "common/common-mybatis" "common/common-redis" "system/system-api")
mvn clean #清空历史数据 mvn clean #清空历史数据
buildDeploy(){ buildDeploy(){
for ((i=0;i<${#buildDeploys[*]};i++)) for ((i=0;i<${#buildDeploys[*]};i++))
...@@ -21,9 +21,6 @@ mvn install ...@@ -21,9 +21,6 @@ mvn install
kubectl delete deployment ism-auth-service -n ism-service kubectl delete deployment ism-auth-service -n ism-service
kubectl delete deployment ism-gateway-service -n ism-service kubectl delete deployment ism-gateway-service -n ism-service
kubectl delete deployment ism-system-user-service -n ism-service kubectl delete deployment ism-system-user-service -n ism-service
kubectl delete deployment ism-system-label-service -n ism-service
kubectl delete deployment ism-system-clue-service -n ism-service
kubectl delete deployment ism-wechat-service -n ism-service
docker images | grep -E "(ism)" | awk '{print $3}' | uniq | xargs -I {} docker rmi --force {} docker images | grep -E "(ism)" | awk '{print $3}' | uniq | xargs -I {} docker rmi --force {}
...@@ -38,15 +35,6 @@ docker push localhost:9999/ism/ism-gateway-service:latest ...@@ -38,15 +35,6 @@ docker push localhost:9999/ism/ism-gateway-service:latest
echo "==================system-user-service镜像===================" echo "==================system-user-service镜像==================="
docker build -t localhost:9999/ism/ism-system-user-service:latest -f system/system-user-service/DOCKERFILE . docker build -t localhost:9999/ism/ism-system-user-service:latest -f system/system-user-service/DOCKERFILE .
docker push localhost:9999/ism/ism-system-user-service:latest docker push localhost:9999/ism/ism-system-user-service:latest
echo "==================system-clue-service镜像==================="
docker build -t localhost:9999/ism/system-clue-service:latest -f system/system-clue-service/DOCKERFILE .
docker push localhost:9999/ism/system-clue-service:latest
echo "==================system-label-service镜像==================="
docker build -t localhost:9999/ism/system-label-service:latest -f system/system-label-service/DOCKERFILE .
docker push localhost:9999/ism/system-label-service:latest
echo "==================wechat-service镜像==================="
docker build -t localhost:9999/ism/ism-wechat-service:latest -f wechat/wechat-service/DOCKERFILE .
docker push localhost:9999/ism/ism-wechat-user-service:latest
echo "docker镜像上传完毕,智能营销平台项目构建完毕" echo "docker镜像上传完毕,智能营销平台项目构建完毕"
echo "清理缓存。。。" echo "清理缓存。。。"
mvn clean mvn clean
...@@ -57,11 +45,5 @@ echo "===========gateway-service==============" ...@@ -57,11 +45,5 @@ echo "===========gateway-service=============="
kubectl create -f ./gateway-service/deployment.yaml kubectl create -f ./gateway-service/deployment.yaml
echo "===========user-service==============" echo "===========user-service=============="
kubectl create -f ./system/system-user-service/deployment.yaml kubectl create -f ./system/system-user-service/deployment.yaml
echo "===========label-service=============="
kubectl create -f ./system/system-label-service/deployment.yaml
echo "===========clue-service=============="
kubectl create -f ./system/system-clue-service/deployment.yaml
echo "===========wechat-service=============="
kubectl create -f ./wechat/wechat-service/deployment.yaml
package com.hungraim.ism.constant;
/**
* @author hubin
*/
public interface WechatConstants {
/**
* 获取access_token接口地址
*/
String GET_TOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
String GET_USERID_FRO_CODE_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
String GET_MOBILE_HASHCODE_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/get_mobile_hashcode";
String WECHAT_REDIS_KEY = "ism:system:wechat";
String ACCESS_TOKEN_REDIS_KEY = "accessToken";
}
...@@ -13,9 +13,6 @@ public class SystemClientDetails { ...@@ -13,9 +13,6 @@ public class SystemClientDetails {
private String clientId; private String clientId;
private String resourceIds; private String resourceIds;
private String clientSecret; private String clientSecret;
/**
* 如果字段存的是enterpriseWechat,代表这个client是给到企业微信的app
*/
private String scope; private String scope;
private String authorizedGrantTypes; private String authorizedGrantTypes;
private String webServerRedirectUri; private String webServerRedirectUri;
......
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