I need a JwtDecoder bean, can I autoconfigure this?

Viewed 1179

I have this problem:

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


Description:

Method springSecurityFilterChain in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration required a bean of type 'org.springframework.security.oauth2.jwt.JwtDecoder' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.security.oauth2.jwt.JwtDecoder' in your configuration.

If I add this to my spring boot project, everything works as intended:

@Value("${spring.security.oauth2.keycloak.jwt.issuer-uri}")
private String issuerUri;

@Bean
public JwtDecoder jwtDecoder() {
    return JwtDecoders.fromOidcIssuerLocation(issuerUri);
}

My application.properties:

spring.security.oauth2.keycloak.jwt.issuer-uri=http://localhost:8180/auth/realms/dev

Is it possible to somehow remove the @Bean method and still make it work? Somehow make the project to create that bean for itself?

1 Answers

According to this post, adding the following configuration to properties.yml file will eliminate the error:

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          jwk-set-uri: https://dev-.....okta.com/oauth2/default

Where jwk-set-uri is the issuer id of the authorization server.

Related