Commit 32fad388 authored by xuepeng.chang's avatar xuepeng.chang

1.Apollo 动态刷新配置

2.限制用户小程序登陆
parent 58b47a33
package cn.quantgroup.xyqb; package cn.quantgroup.xyqb;
import cn.quantgroup.xyqb.config.SequencerProperties; import cn.quantgroup.xyqb.config.SequencerProperties;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
...@@ -26,6 +27,7 @@ import org.springframework.scheduling.annotation.EnableAsync; ...@@ -26,6 +27,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableConfigurationProperties({SequencerProperties.class}) @EnableConfigurationProperties({SequencerProperties.class})
@EnableFeignClients @EnableFeignClients
@EnableApolloConfig
public class Bootstrap { public class Bootstrap {
public static void main(String[] args) { public static void main(String[] args) {
......
package cn.quantgroup.xyqb.config;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.Set;
/**
* 配置文件监听
* 当apollo配置文件发生变更的时候,监听所有被{@link RefreshScope}修饰的类,这些类进行删除,在使用的是重新加载
*/
@Component
@Slf4j
public class ApolloConfigListener implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Autowired
RefreshScope refreshScope;
@ApolloConfigChangeListener(value = {"application"})
public void configChange(ConfigChangeEvent event) {
Set<String> changedKeys = event.changedKeys();
for (String changedKey : changedKeys) {
log.info("changed key = {}", changedKey);
log.info("oldValue={},newValue= {}", event.getChange(changedKey).getOldValue(),
event.getChange(changedKey).getNewValue());
}
this.applicationContext.publishEvent(new EnvironmentChangeEvent(event.changedKeys()));
refreshScope.refreshAll();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
\ No newline at end of file
package cn.quantgroup.xyqb.constant;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
@NoArgsConstructor
@Data
@Component
@RefreshScope
public class CommonProperties {
/** 限制用户小程序登陆*/
@Value("${wechat.black.userIds:}")
private String wechatBlackUserIds;
}
package cn.quantgroup.xyqb.service.v2; package cn.quantgroup.xyqb.service.v2;
import cn.quantgroup.xyqb.constant.CommonProperties;
import cn.quantgroup.xyqb.constant.enums.LoginType; import cn.quantgroup.xyqb.constant.enums.LoginType;
import cn.quantgroup.xyqb.controller.req.v2.LoginReq; import cn.quantgroup.xyqb.controller.req.v2.LoginReq;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
...@@ -35,11 +36,15 @@ public class InterLoginStrategy implements LoginStrategy { ...@@ -35,11 +36,15 @@ public class InterLoginStrategy implements LoginStrategy {
private final IWechatService wechatService; private final IWechatService wechatService;
private final ISessionService sessionService; private final ISessionService sessionService;
public InterLoginStrategy(ILockIpv4Service lockIpv4Service, IUserService userService, IWechatService wechatService, ISessionService sessionService) { private final CommonProperties commonProperties;
public InterLoginStrategy(ILockIpv4Service lockIpv4Service, IUserService userService,
IWechatService wechatService, ISessionService sessionService,CommonProperties commonProperties) {
this.lockIpv4Service = lockIpv4Service; this.lockIpv4Service = lockIpv4Service;
this.userService = userService; this.userService = userService;
this.wechatService = wechatService; this.wechatService = wechatService;
this.sessionService = sessionService; this.sessionService = sessionService;
this.commonProperties= commonProperties;
} }
@Override @Override
...@@ -88,10 +93,10 @@ public class InterLoginStrategy implements LoginStrategy { ...@@ -88,10 +93,10 @@ public class InterLoginStrategy implements LoginStrategy {
} }
// 临时的限制泄露账户的用户不让用户的小程序登陆,在上线微信解绑功能后删除 // 临时的限制泄露账户的用户不让用户的小程序登陆,在上线微信解绑功能后删除
if (StringUtils.isNotEmpty(interLoginParam.getAppId()) && StringUtils.isNotEmpty(interLoginParam.getOpenId())){ if (StringUtils.isNotEmpty(interLoginParam.getAppId()) && StringUtils.isNotEmpty(interLoginParam.getOpenId())){
if(user.getId().equals(53007786L) || user.getId().equals(9440153L)){ if(StringUtils.isNotEmpty(commonProperties.getWechatBlackUserIds())
&& commonProperties.getWechatBlackUserIds().contains(user.getId().toString()))
log.info("用户,限制小程序登陆,userId:{}", user.getId()); log.info("用户,限制小程序登陆,userId:{}", user.getId());
throw new SilentBizException(BizExceptionEnum.ERROR_WECHAT_LOGIN); throw new SilentBizException(BizExceptionEnum.ERROR_WECHAT_LOGIN);
}
} }
//2、需要判断是否是否启用 //2、需要判断是否是否启用
......
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