gpt4 book ai didi

spring-boot - Spring Boot + Keycloak 使用私有(private)证书

转载 作者:太空宇宙 更新时间:2023-11-03 14:24:12 26 4
gpt4 key购买 nike

我的 Spring Boot 应用程序使用公共(public)证书与 KeyCloak 一起正常工作。但是由于我的 Keycloak 已更改为私有(private)证书,因此出现以下错误:

"An I/O error occurred while reading from the JWK Set source: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

我已经获得了私有(private)证书,但还没有想出一个成功的方法来设置它;如果我对 Keycloack 端点进行 curl ,将证书作为参数传递就可以正常工作。

curl --cacert mycertificate.crt -X GET \                                                                                                                                      130 ↵
https://keycloak.address.bla/auth/realms/my-app/protocol/openid-connect/certs

我试图调整我的 ResourceServerConfiguration 类以使用证书,方法是使用我的私有(private)证书中的 keytool 生成 keystore.jks,但我没有成功;当我尝试下面的代码时,出现以下错误:“无法从商店加载 key :类路径资源 [keystore.jks]”

  @Bean
@Primary
public JwtAccessTokenConverter createJwtAccessTokenConverter() {
var jwtAccessTokenConverter = new JwtAccessTokenConverter();

KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("/keystore.jks"), "changeit".toCharArray());
jwtAccessTokenConverter.setKeyPair(keyStoreKeyFactory.getKeyPair("myAlias"));
jwtAccessTokenConverter.setAccessTokenConverter(keycloakAccessTokenConverter);
return jwtAccessTokenConverter;
}

我的应用程序.properties

security.oauth2.resource.id=account
security.oauth2.resource.jwk.key-set-uri=${app.keycloak.api}/protocol/openid-connect/certs

最佳答案

只需将私有(private)证书导入我的 JVM 即可解决问题。导入“.crt”文件后,我所有的请求都成功了;

将.crt文件导入JVM的命令如下:keytool -importcert -file my_certificate.crt -noprompt -alias certificate_alias -storepass changeit -keystore $JAVA_HOME/lib/security/cacerts

关于spring-boot - Spring Boot + Keycloak 使用私有(private)证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58312963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com