java - 我需要了解如何将 API 网关与身份验证微服务和其他微服务连接
问题描述
758/5000 大家好,我有几个问题在网上没有找到确切的答案。你应该知道,在微服务方面,我是一个血腥的初学者。
我创建了几个相互连接的微服务。一方面是 Zuul-Api-Gateway,一个用于登录的单独微服务和两个称为模板和联系人的微服务。
我也可以通过zuul寻址所有微服务,但我真的只希望登录微服务可以寻址。另一方面,登录微服务应该能够在成功登录后访问微服务模板和联系人。
问题1)如何禁止API网关直接寻址各种服务?
这是我的 ZuulFilter
@Component
public class ZuulLoggingFilter extends ZuulFilter {
private Logger logger= LoggerFactory.getLogger(this.getClass());
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() throws ZuulException {
RequestContext.getCurrentContext();
HttpServletRequest request = RequestContext.getCurrentContext().getRequest();
logger.info("request ->{} request uri -> {}", request, request.getRequestURI());
return null;
}
我来自 Zuul 的 Application.properties
spring.application.name=zuul
server.port=8800
eureka.client.serviceUrl.defaultZone = http://localhost:8762/eureka
#zuul.routes.contacts.path = /contacts/**
#zuul.routes.contacts.url = http://localhost:8100/
#zuul.routes.templates.path = /templates/**
#zuul.routes.templates.url = http://localhost:8200/
我的安全配置
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Autowired
UserDetailsService userDetailsService;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth.userDetailsService(userDetailsService);
}
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.antMatchers("/users").hasRole("ADMIN")
.antMatchers("/user").hasAnyRole("ADMIN","USER")
.antMatchers(HttpMethod.POST,"/users").hasRole("ADMIN")
.and().formLogin()
.and().
csrf().disable();
}
代码和路径变量来自我的登录微服务如果我忘记了什么,请让我知道我应该发布什么。
解决方案
你不把登录服务作为 api-gateway 的一部分吗?
推荐阅读
- java - 如何解决Kafka消息生产者NoSuchMethodError org.apache.kafka.common.security.ssl.SslFactory.sslEngineBuilder()
- python - 在各种服务之间共享 python 代码的最佳方式是什么?
- appium - 无法使用 webview 中的 setconnection 断开互联网连接
- spring-boot - 如果一个线程已经在spring boot rest api中开始处理,如何响应客户端
- twilio - 如何在回调函数中获取 Flow SID
- security - API 和数据库访问控制架构
- node.js - 在获取数据 react-Native 中实现循环
- r - R - 我有一个从事件时间中提取星期几的程序,现在我想更改它以提取事件时间当天的小时
- python - Python unittest ModuleNotFound 用于从同一模块导入
- arrays - 在 vba 中创建黑名单的最佳方法?