Самозаверяющий сертификат о весенней безопасности oauth2 клиент провайдера эмитента-URI - PullRequest
0 голосов
/ 23 февраля 2020

Я пытаюсь создать пример клиентского приложения Spring Boot, которое может получить доступ к защищенной службе отдыха Keycloak.

Как описано почти в любом руководстве, должен быть определен spring.security.oauth2.client. Вот мой:

  security:
    oauth2:
      client:
        registration:
          keycloak:
            client-id: my-id
            client-secret: my-secret
            authorization-grant-type: client_credentials
        provider:
          keycloak:
            issuer-uri: https://myhost/auth/realms/master

Но у меня есть самозаверяющий сертификат на тестовом сервере myhost Keycloak, поэтому при запуске приложения я получаю следующее:

Caused by: java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "https://myhost/auth/realms/master"
    at org.springframework.security.oauth2.client.registration.ClientRegistrations.getConfiguration(ClientRegistrations.java:177)
    at org.springframework.security.oauth2.client.registration.ClientRegistrations.fromIssuerLocation(ClientRegistrations.java:140)
    at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getBuilderFromIssuerIfPossible(OAuth2ClientPropertiesRegistrationAdapter.java:83)
    at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getClientRegistration(OAuth2ClientPropertiesRegistrationAdapter.java:59)
    at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.lambda$getClientRegistrations$0(OAuth2ClientPropertiesRegistrationAdapter.java:53)
    at java.util.HashMap.forEach(HashMap.java:1289)
    at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(OAuth2ClientPropertiesRegistrationAdapter.java:52)
    at org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientRegistrationRepositoryConfiguration.clientRegistrationRepository(OAuth2ClientRegistrationRepositoryConfiguration.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 74 common frames omitted
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://myhost/auth/realms/master/.well-known/openid-configuration": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:751)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:654)
    at org.springframework.security.oauth2.client.registration.ClientRegistrations.getConfiguration(ClientRegistrations.java:170)
    ... 86 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Как отключить проверку сертификата в приложении запуск

1 Ответ

0 голосов
/ 24 февраля 2020

Пожалуйста, обратите внимание, когда вы пытаетесь подключиться с помощью keycloak из клиента restpi или любого веб-приложения, если вы получаете сообщение об ошибке, как показано ниже

Причина: org.springframework.web.client.ResourceAccessException: Ошибка ввода-вывода при запросе GET для «https://myhost/auth/realms/master/.well-known/openid-configuration»: sun.security.validator.ValidatorException: сбой построения пути PKIX: sun.security.provider.certpath.SunCertPathBuilderException: не удалось найти действительный путь сертификации для запрошенная цель; вложенное исключение - javax. net .ssl.SSLHandshakeException: sun.security.validator.ValidatorException: сбой построения пути PKIX: sun.security.provider.certpath.SunCertPathBuilderException: невозможно найти действительный путь сертификации для запрошенной цели

пытается сообщить вам, что сертификат не добавлен в java хранилище ключей или неверный сертификат добавлен в хранилище ключей.

Так как вы указали https в конечной точке, его обязательно нужно импортировать / добавить сертификат в Java хранилище ключей.

Необходимо импортировать сертификат на клиентский компьютер

Импорт сертификатов на клиентском компьютере

 keytool -import -noprompt -trustcacerts -alias "initcert" -file keycloak.cer -keystore "C:\Program Files\Java\jdk1.8.0_152\jre\lib\security\cacerts"

по умолчанию пароль для Java хранилища ключей changeit

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...