jhipsteroktajhipster-gateway

JHipster with Okta Application Failed to Start due to UnsatisfiedDependencyException


Getting the following error when starting JHipster Gateway application after adding OKTA configuration:

$ cd saathratrigateway
$ ./mvnw

...
2020-11-13 22:31:16.278  WARN 80043 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authorizationHeaderUtil' defined in file [/Users/amar/workspace/saathratri-app-holder/saathratrigateway/target/classes/com/saathratri/security/oauth2/AuthorizationHeaderUtil.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2020-11-13 22:31:16.280 DEBUG 80043 --- [  restartedMain] c.e.c.E.saathratri.domain.Authority      : Close successful.
2020-11-13 22:31:16.281 DEBUG 80043 --- [  restartedMain] c.e.c.E.saathratri.domain.User           : Close successful.
2020-11-13 22:31:16.281 DEBUG 80043 --- [  restartedMain] c.e.c.E.s.domain.User.authorities        : Close successful.
2020-11-13 22:31:16.282 DEBUG 80043 --- [  restartedMain] c.ehcache.core.Ehcache-usersByEmail      : Close successful.
2020-11-13 22:31:16.282 DEBUG 80043 --- [  restartedMain] c.ehcache.core.Ehcache-usersByLogin      : Close successful.
2020-11-13 22:31:16.479 ERROR 80043 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.saathratri.security.oauth2.AuthorizationHeaderUtil required a bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientService' that could not be found.

The following candidates were found but could not be injected:
    - Bean method 'authorizedClientService' in 'OAuth2WebSecurityConfiguration' not loaded because @ConditionalOnBean (types: org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; SearchStrategy: all) did not find any beans of type org.springframework.security.oauth2.client.registration.ClientRegistrationRepository


Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientService' in your configuration.

Any advise would be appreciated greatly.


Solution

  • Okay - figured it out. I had to create ~/.okta.env and then run source ~/.okta.env. See below....

    $ vi ~/.okta.env
    
    ---
    export SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI="https://dev-XXXXXXX.okta.com/oauth2/default"
    export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID="XXXXXXXXXXXXXXXXXXXX"
    export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET="XXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    export OKTA_OAUTH2_ISSUER="https://dev-XXXXXXX.okta.com/oauth2/default"
    export OKTA_OAUTH2_CLIENT_ID_WEB="XXXXXXXXXXXXXXXXXXXX"
    export OKTA_OAUTH2_CLIENT_SECRET_WEB="XXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    ---
    
    $ source ~/.okta.env
    
    $ cd saathratrigateway
    $ ./mvnw
    
    

    I was following instructions from https://developer.okta.com/blog/2018/03/01/develop-microservices-jhipster-oauth.

    Thank you Matt Raible!

    Happy Diwali.