I'm trying to configure OAuth2 authentication into an existing Spring MVC app that is currently configured to use simple FORM authentication. I'd like to use Facebook as authentication provider, but I also need to maintain form authentication and to register user data in application DB the same way for both authentication methods (obviously for social auth some fields will be absent, for ex. password
).
I'm using Spring Boot 1.4.1 with these additional dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
But I cannot find a tutorial or some clear documentation explaining how to solve my case (FORM + OAuth2).
I tried to follow this tutorial but it is based on Spring Boot + AngularJS, while I'm using plain HTML + Thymeleaf.
This is my current Spring Security configuration:
http.authorizeRequests() //
.antMatchers("/css/**").permitAll() // static resources
.antMatchers("/webjars/**").permitAll() // static resources
.antMatchers("/images/**").permitAll() // static resources
.antMatchers("/login").permitAll().anyRequest().authenticated();
http.formLogin()
.failureUrl("/login?error").defaultSuccessUrl("/").loginPage("/login").permitAll()//
.and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login?logout").permitAll();
What should I add to configure OAuth2 and to get user info once authenticated?
UPDATE After some googlin' I found that the way to go could be to use this dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-facebook</artifactId>
</dependency>
in place of plain spring-security-oauth2
, but I still can't find a simple way to achieve what I want.
The best tutorial I found is this, but is a bit dated and is not based on Spring Boot, so I can't understand if some utility and autoconfiguration exist.