diff --git a/pom.xml b/pom.xml
index 508a8f5bb6..9bf12725c0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -146,6 +146,7 @@
spring-5-reactive
spring-5-mvc
+ spring-5-security
spring-activiti
spring-akka
spring-amqp
diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml
new file mode 100644
index 0000000000..c0f73b1bdd
--- /dev/null
+++ b/spring-5-security/pom.xml
@@ -0,0 +1,95 @@
+
+ 4.0.0
+ com.baeldung
+ spring-5-security
+ 0.0.1-SNAPSHOT
+ jar
+
+ spring-5-security
+ spring 5 security sample project
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.0.0.M7
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-security
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+
+
+
+ org.springframework.security
+ spring-security-oauth2-client
+
+
+ org.springframework.security
+ spring-security-oauth2-jose
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ 3
+ true
+ methods
+ true
+
+ **/*IntegrationTest.java
+ **/*LiveTest.java
+
+
+
+
+
+
+
+
+ spring-milestones
+ Spring Milestones
+ https://repo.spring.io/milestone
+
+ false
+
+
+
+
+
+ spring-milestones
+ Spring Milestones
+ https://repo.spring.io/milestone
+
+ false
+
+
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+
+
\ No newline at end of file
diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/LoginController.java b/spring-5-security/src/main/java/com/baeldung/oauth2/LoginController.java
new file mode 100644
index 0000000000..5d6c13bb0e
--- /dev/null
+++ b/spring-5-security/src/main/java/com/baeldung/oauth2/LoginController.java
@@ -0,0 +1,75 @@
+package com.baeldung.oauth2;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.ResolvableType;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
+import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
+import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
+import org.springframework.security.oauth2.client.registration.ClientRegistration;
+import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.client.RestTemplate;
+
+@Controller
+public class LoginController {
+
+ private static final String authorizationRequestBaseUri = "oauth2/authorize-client";
+ Map oauth2AuthenticationUrls = new HashMap<>();
+
+ @Autowired
+ private ClientRegistrationRepository clientRegistrationRepository;
+ @Autowired
+ private OAuth2AuthorizedClientService authorizedClientService;
+
+ @GetMapping("/oauth_login")
+ public String getLoginPage(Model model) {
+ Iterable clientRegistrations = null;
+ ResolvableType type = ResolvableType.forInstance(clientRegistrationRepository)
+ .as(Iterable.class);
+ if (type != ResolvableType.NONE && ClientRegistration.class.isAssignableFrom(type.resolveGenerics()[0])) {
+ clientRegistrations = (Iterable) clientRegistrationRepository;
+ }
+
+ clientRegistrations.forEach(registration -> oauth2AuthenticationUrls.put(registration.getClientName(), authorizationRequestBaseUri + "/" + registration.getRegistrationId()));
+ model.addAttribute("urls", oauth2AuthenticationUrls);
+
+ return "oauth_login";
+ }
+
+ @GetMapping("/loginSuccess")
+ public String getLoginInfo(Model model, OAuth2AuthenticationToken authentication) {
+
+ OAuth2AuthorizedClient client = authorizedClientService.loadAuthorizedClient(authentication.getAuthorizedClientRegistrationId(), authentication.getName());
+
+ String userInfoEndpointUri = client.getClientRegistration()
+ .getProviderDetails()
+ .getUserInfoEndpoint()
+ .getUri();
+
+ if (!StringUtils.isEmpty(userInfoEndpointUri)) {
+ RestTemplate restTemplate = new RestTemplate();
+ HttpHeaders headers = new HttpHeaders();
+ headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + client.getAccessToken()
+ .getTokenValue());
+
+ HttpEntity entity = new HttpEntity("", headers);
+
+ ResponseEntity