Spring MVC + Okta

Hi All,

I am working on to integrate Okta in my Spring MVC project, I searched for Spring projects with Okta but I am finding only Okta with Spring boot project, could you help me with my query to integrate Okta in any spring MVC project?

Hello,

The Okta Spring SDK uses Spring Boot. This SDK relies on Spring Security for most the functionality.

Spring Security has a predefined OAuth provider for Okta, see here.

The following tutorial demonstrates OAuth with Spring Security in both Spring, and Spring Boot.

Hopefully that helps get you started.

Thank You,

1 Like

Thank you so much! I will take a look and come back with any questions.

I tried following this blog and having the below issue. Any help in this regard is much appreciated!

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers(β€œ/”).permitAll()
// all other requests
.anyRequest().authenticated()
// set logout URL
.and().logout().logoutSuccessUrl(β€œ/”)
.addLogoutHandler(new CustomLogoutHandler())
// enable OAuth2/OIDC
.and().oauth2Client()
.and().oauth2Login()
.defaultSuccessUrl(β€œ/loginSuccess.rest”, true);;
return http.build();
}

It kicks in Okta login widget and after login it’s going in a loop and not returning to the client application.

1 Like