Search code examples
springoauth-2.0jhipster

JHipster - Spring. Oauth2 resource server configuration. Create resource server


When using simple spring boot configuration with normal spring parent in pom.xml I have no problem configuring oauth2 resource server.

However with JHipster dependency management by no means i can configure it. I was trying to do it just by adding

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
    <version>[spring version]</version>
</dependency>

or by using some older configuration with other dependencies like here: https://docs.spring.io/spring-security-oauth2-boot/docs/2.2.x-SNAPSHOT/reference/html/boot-features-security-oauth2-resource-server.html And normally it works, but with JHipster I get @EnableResourceServer annotation, but I dont have in IntelliJ spring.security.oauth2.resourceserver property. So I cant configure by what server should the token be validated, and I dont have .oauth2ResourceServer() method in HttpSecurity http (WebSecurityConfigurerAdapter). I don't understand why is this happening. How can I get these properties? Or maybe I can override it by custom configuration somehow?


Solution

  • JHipster is configured to be a resource server by default, so you don't need to add any additional configuration.

    From SecurityConfiguration.java:

    .oauth2ResourceServer()
        .jwt()
        .jwtAuthenticationConverter(authenticationConverter())
        .and()
    .and()
        .oauth2Client();