# Why is the Spring Boot integration not working once deprecated APIs are upgraded?

**URL:** <https://community.auth0.com/t/why-is-the-spring-boot-integration-not-working-once-deprecated-apis-are-upgraded/97986>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, auth0-java\
**Created:** [January 11, 2023, 9:06pm UTC](https://community.auth0.com/t/why-is-the-spring-boot-integration-not-working-once-deprecated-apis-are-upgraded/97986 "2023-01-11T21:06:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [January 11, 2023, 9:06pm UTC](https://community.auth0.com/t/why-is-the-spring-boot-integration-not-working-once-deprecated-apis-are-upgraded/97986/1 "2023-01-11T21:06:24Z")

</div>

The current document suggests…

```auto
// src/main/java/com/auth0/example/security/SecurityConfig.java

import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .mvcMatchers("/api/public").permitAll()
                .mvcMatchers("/api/private").authenticated()
                .mvcMatchers("/api/private-scoped").hasAuthority("SCOPE_read:messages")
                .and().cors()
                .and().oauth2ResourceServer().jwt();
        return http.build();
    }
}

```

But `http.authorizeRequests` is deprecated. I tried to update to

```auto
@Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests()
                .requestMatchers("/").permitAll()
                .anyRequest().authenticated()
                .requestMatchers("/person").hasAuthority("SCOPE_blahablah");
        return http.build();
    }

```

But instead of passing a status code 403 when I don’t have the scope it is just giving the response and a 200. Since the documents are not up to date can anyone help me solve this?

I can also confirm that this…

```auto
@EnableWebSecurity
@Configuration
public class SecurityConfig {

    @Value("${auth0.audience}")
    private String audience;

    @Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}")
    private String issuer;
    @Bean
    private JwtDecoder jwtDecoder() {
        NimbusJwtDecoder jwtDecoder = (NimbusJwtDecoder)
                JwtDecoders.fromOidcIssuerLocation(issuer);

        OAuth2TokenValidator<Jwt> audienceValidator = new AudienceValidator(audience);
        OAuth2TokenValidator<Jwt> withIssuer = JwtValidators.createDefaultWithIssuer(issuer);
        OAuth2TokenValidator<Jwt> withAudience = new DelegatingOAuth2TokenValidator<>(withIssuer, audienceValidator);

        jwtDecoder.setJwtValidator(withAudience);

        return jwtDecoder;
    }
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.oauth2Login();
        return http.build();
    }
}
...
import org.springframework.security.oauth2.core.OAuth2Error;
import org.springframework.security.oauth2.core.OAuth2TokenValidator;
import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult;
import org.springframework.security.oauth2.jwt.Jwt;

/**
 * Validates that the JWT token contains the intended audience in its claims.
 */
public class AudienceValidator implements OAuth2TokenValidator<Jwt> {
    private final String audience;

    public AudienceValidator(String audience) {
        this.audience = audience;
    }

    public OAuth2TokenValidatorResult validate(Jwt jwt) {
        OAuth2Error error = new OAuth2Error("invalid_token", "The required audience is missing", null);

        if (jwt.getAudience().contains(audience)) {
            return OAuth2TokenValidatorResult.success();
        }

        return OAuth2TokenValidatorResult.failure(error);
    }
}

```

Doesn’t seem to be enforcing the audience check too

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 1, 2024, 4:00pm UTC](https://community.auth0.com/t/why-is-the-spring-boot-integration-not-working-once-deprecated-apis-are-upgraded/97986/3 "2024-11-01T16:00:01Z")

</div>

Hi @jgleason,

Yes, what you have observed is correct. The updated method is now `http.authorizeHttpRequests()`.

If you are experiencing issues with the scopes omitted but still permitting access with status code `200`, I recommend checking your access token to verify the claims.

This will help you validate if the `audience` and `scopes` claims contain the actual permissions required to access the app.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 15, 2024, 4:00pm UTC](https://community.auth0.com/t/why-is-the-spring-boot-integration-not-working-once-deprecated-apis-are-upgraded/97986/4 "2024-11-15T16:00:30Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
