Spring Authorization Server OAuth2AuthorizationServerConfigurer.authorizationServer() method not found

1 week ago 12
ARTICLE AD BOX

I am new to spring security. I have been looking to build an authorization server and I have went through a couple of documentations. I saw that all of them have used something like:

OAuth2AuthorizationServerConfigurer configurer = OAuth2AuthorizationServerConfigurer.authorizationServer();

But when I do the same code in my app I get an error that the method is not defined.

My build.gradle file is like:

plugins { id 'java' id 'org.springframework.boot' version '4.0.1' id 'io.spring.dependency-management' version '1.1.7' } group = 'com.example' version = '0.0.1-SNAPSHOT' description = 'Auth Server' java { toolchain { languageVersion = JavaLanguageVersion.of(21) } } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-security-oauth2-authorization-server' implementation 'org.springframework.boot:spring-boot-starter-webmvc' implementation 'org.springframework.boot:spring-boot-starter-validation' testImplementation 'org.springframework.boot:spring-boot-starter-security-oauth2-authorization-server-test' testImplementation 'org.springframework.boot:spring-boot-starter-security-test' testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } tasks.named('test') { useJUnitPlatform() }

Here is my full code:

package com.example.auth; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.core.annotation.Order; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.oauth2.server.authorization.OAuth2AuthorizationServerConfigurer; import org.springframework.security.web.SecurityFilterChain; @SpringBootApplication @EnableWebSecurity public class AuthApplication { public static void main(String[] args) { SpringApplication.run(AuthApplication.class, args); } @Bean @Order(1) public SecurityFilterChain authorizatFilterChain(HttpSecurity http) throws Exception { OAuth2AuthorizationServerConfigurer configurer = OAuth2AuthorizationServerConfigurer.authorizationServer(); return http.build(); } }

And here is the output when I run ./gradlew build

$ ./gradlew build > Task :compileJava FAILED /home/nous/auth/src/main/java/com/farhadzada/auth/AuthApplication.java:23: error: cannot find symbol OAuth2AuthorizationServerConfigurer configurer = OAuth2AuthorizationServerConfigurer.authorizationServer(); ^ symbol: method authorizationServer() location: class OAuth2AuthorizationServerConfigurer 1 error [Incubating] Problems report is available at: file:///home/nous/auth/build/reports/problems/problems-report.html FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileJava'. > Compilation failed; see the compiler output below. /home/nous/auth/src/main/java/com/farhadzada/auth/AuthApplication.java:23: error: cannot find symbol OAuth2AuthorizationServerConfigurer configurer = OAuth2AuthorizationServerConfigurer.authorizationServer(); ^ symbol: method authorizationServer() location: class OAuth2AuthorizationServerConfigurer 1 error * Try: > Check your code and dependencies to fix the compilation error(s) > Run with --scan to generate a Build Scan (powered by Develocity). BUILD FAILED in 1s 1 actionable task: 1 executed
Read Entire Article