JHipster:Rest服务调用返回“;401“未经授权”;通过网关进行路由时
我是micro services和JHipster的新手,因此请耐心等待,并在必要时帮助我 我认为这是一个配置问题,但我似乎找不到它。以下是一些细节: 我们正在运行一个带有KeyClope的JHipster网关。环境是Docker compose,据我所知,我们已经完成了JHipster Docker文档中规定的必要工作 我们使用oauth2作为身份验证类型 部署的是仅Rest资源。两次呼叫的最简单情况: /api/hello->应返回“我说你好” /自由/你好->应该返回“我自由了!” /api/hello调用应该是安全的,/free/hello调用显然不是 当我通过网关点击/free/hello服务时,即,我得到预期的响应“我有空!” 因此,我希望网关能够正常运行并路由流量 对于安全服务,我使用postman首先获取JWT令牌。JHipster:Rest服务调用返回“;401“未经授权”;通过网关进行路由时,jhipster,jhipster-registry,Jhipster,Jhipster Registry,我是micro services和JHipster的新手,因此请耐心等待,并在必要时帮助我 我认为这是一个配置问题,但我似乎找不到它。以下是一些细节: 我们正在运行一个带有KeyClope的JHipster网关。环境是Docker compose,据我所知,我们已经完成了JHipster Docker文档中规定的必要工作 我们使用oauth2作为身份验证类型 部署的是仅Rest资源。两次呼叫的最简单情况: /api/hello->应返回“我说你好” /自由/你好->应该返回“我自由了!” /ap
当我直接点击服务,即serverip:appPort/api/hello时,我得到了预期的响应 这对我来说意味着服务正在运行,spring security可以使用我的JWT令牌 现在,当我尝试通过网关路由到安全服务时,问题就开始了。我通过邮递员使用同样的代币 现在我的回答是: 类型“” 标题“未经授权” 状态401 详细信息“访问此资源需要完全身份验证” 路径“/api/hello” 消息“error.http.401” 是否有常见问题解答或检查表可供我参考,以尝试排除故障 请让我知道我可以添加哪些信息以提供帮助 编辑: 证券配置:
@EnableWebSecurity
@Import(SecurityProblemSupport.class)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Value("${spring.security.oauth2.client.provider.oidc.issuer-uri}")
private String issuerUri;
private final JHipsterProperties jHipsterProperties;
private final JwtAuthorityExtractor jwtAuthorityExtractor;
private final SecurityProblemSupport problemSupport;
public SecurityConfiguration(JwtAuthorityExtractor jwtAuthorityExtractor, JHipsterProperties jHipsterProperties, SecurityProblemSupport problemSupport) {
this.problemSupport = problemSupport;
this.jwtAuthorityExtractor = jwtAuthorityExtractor;
this.jHipsterProperties = jHipsterProperties;
}
@Override
public void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(problemSupport)
.accessDeniedHandler(problemSupport)
.and()
.headers()
.contentSecurityPolicy("default-src 'self'; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:")
.and()
.referrerPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN)
.and()
.featurePolicy("geolocation 'none'; midi 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'")
.and()
.frameOptions()
.deny()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/auth-info").permitAll()
.antMatchers("/api/**").authenticated()//hasAuthority(AuthoritiesConstants.USER)//permitAll()
.antMatchers("/management/health").permitAll()
.antMatchers("/management/info").permitAll()
.antMatchers("/management/prometheus").permitAll()
.antMatchers("/management/**").hasAuthority(AuthoritiesConstants.ADMIN)
.and()
.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(jwtAuthorityExtractor)
.and()
.and()
.oauth2Client();
// @formatter:on
}
编辑2:
Application.yml
security:
oauth2:
client:
access-token-uri: http://xxx.xxx.xxx.xxx:30080/auth/realms/test/protocol/openid-connect/token
user-authorization-uri: http://xxx.xxx.xxx.xxx:30080/auth/realms/test/protocol/openid-connect/auth
client-id: web_app
client-secret: web_app
scope: openid profile email
resource:
user-info-uri: http://xxx.xxx.xxx.xxx:30080/auth/realms/test/protocol/openid-connect/userinfo
server:
port: 40404
编辑3:
这个问题与我的问题类似:
没有给出答案,海报得到的解决方案是只允许/api/**路径上的permitAll()。这不是一个很好的选择,因为它会使端点不安全
另一个类似的问题是:
这收到了一些使用@EnableResourceServer的答案。这是一篇较旧的帖子,我的印象是,我运行的Jhipster应用程序的新版本很好地满足了这种情况——我这样说是不是错了?在打开SpringSecurity登录后,添加
@Override
public void configure(WebSecurity web){
web.debug(true);
}
在SecurityConfiguration.java类中,我们可以看到安全标头没有被网关转发
这使我们进入了这一页:
这就解释了原因
更改配置(gateway.yml/jhipster registry.yml)中的zuul参数时:
请注意,出于安全原因,默认配置不包括敏感头的转发,因此请确保您了解如果更改此配置将执行的操作
zuul: # those values must be configured depending on the application specific needs
.
.
ignore-security-headers: false
ignored-headers: cookie,set-cookie
sensitiveHeaders: Cookie,Set-Cookie
.