jhipster / jhipster-registry

JHipster Registry, based on Spring Cloud Netflix Eureka and Spring Cloud Config
Apache License 2.0
698 stars 657 forks source link

Eureka won't start with customized keycloak server #540

Closed paris0120 closed 1 year ago

paris0120 commented 2 years ago
Overview of the issue

I have a customized keycloak server (https://github.com/paris0120/keycloak-server). However, eureka works fine with docker image but won't start with this server.

I got docker-jhipster-registry-1 | 2022-07-06 21:06:38.097 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'OAuth2SecurityConfiguration' defined in file [/app/classes/tech/jhipster/registry/config/OAuth2SecurityConfiguration.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.zalando.problem.spring.web.advice.security.SecurityProblemSupport': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2ClientWebMvcSecurityConfiguration': Unsatisfied dependency expressed through method 'setClientRegistrationRepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception; nested exception is java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "http://keycloak:9080/auth/realms/jhipster" docker-jhipster-registry-1 | 2022-07-06 21:06:38.123 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed

Motivation for or Use Case

Replace docker keycloak with customized one.

Reproduce the error

start mysql server, start keycloak server from https://github.com/paris0120/keycloak-server start register docker image: docker compose -f src/main/docker/jhipster-registry.yml up realm profile: https://github.com/paris0120/keycloak-server/blob/main/src/main/resources/realm-export.json

Related issues
Suggest a Fix
JHipster Registry Version(s)
Browsers and Operating System
Tcharl commented 2 years ago

Hi,

Can you try to add an alias in your hosts file 127.0.0.1 keycloak and align your keycloak and application-*.yml configuration accordingly?

paris0120 commented 2 years ago

keycloak

I did. This works fine with the docker version of keycloak. I also found that the issue exists only with the docker version of the registry. The image here works fine.

juliensadaoui commented 1 year ago

This behaviour is correct, it is not an issue with the JHipster Registry. To understand your problem, you need to know the concept of Docker Networking and how the applications can access each other, using internal network created by docker.

There are several network drivers: Bridge, Host, None, ... The Bridge driver is a private default internal network created by docker on the host. This network is usually used when your applications run in standalone containers that need to communicate. So, all containers get an internal IP address and these containers can access each other, using this internal IP.

In your case, you try to communicate with the Keycloak server using the service name keycloak. This service name works only when you deployed your containers using Docker Compose. When your Keycloak server run on your operating system, the jhispter-register container doesn't access at the keycloak server on your operating system.