BAEL-2587: Spring Security integration with Amazon Cognito (#6730)
* BAEL-2587: Spring Security integration with Amazon Cognito * BAEL-2587: Spring Security integration with Amazon Cognito - remove unnecessary stuff * BAEL-2587: Spring Security integration with Amazon Cognito - rename config file * BAEL-2587: Spring Security integration with Amazon Cognito - separate folder for cognito
This commit is contained in:
parent
b63f8882ea
commit
77338c7fb1
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.cognito;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("cognito/application_cognito.yml")
|
||||
public class CognitoWebConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/").setViewName("home");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.cognito;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@SpringBootApplication
|
||||
@PropertySource("cognito/application_cognito.yml")
|
||||
public class SpringCognitoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringCognitoApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
spring:
|
||||
security:
|
||||
oauth2:
|
||||
client:
|
||||
registration:
|
||||
cognito:
|
||||
client-id: clientId
|
||||
client-secret: clientSecret
|
||||
scope: openid
|
||||
redirectUriTemplate: "http://localhost:8080/login/oauth2/code/cognito"
|
||||
clientName: cognito-client-name
|
||||
provider:
|
||||
cognito:
|
||||
issuerUri: https://cognito-idp.{region}.amazonaws.com/{poolId}
|
||||
usernameAttribute: cognito:username
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>OAuth2 Cognito Demo</title>
|
||||
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css">
|
||||
<link rel="stylesheet" th:href="@{/cognito/style.css}">
|
||||
</head>
|
||||
<body>
|
||||
<section class="section">
|
||||
<div class="container has-text-centered">
|
||||
<div>
|
||||
<h1 class="title">OAuth2 Spring Security Cognito Demo</h1>
|
||||
|
||||
<div sec:authorize="isAuthenticated()">
|
||||
<div class="box">
|
||||
Hello, <strong th:text="${#authentication.name}"></strong>!
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div sec:authorize="isAnonymous()">
|
||||
<div class="box">
|
||||
<a class="button login is-primary" th:href="@{/oauth2/authorization/cognito}">Log in with Amazon Cognito</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,9 @@
|
|||
.login {
|
||||
background-color: #7289da;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.login:hover {
|
||||
background-color: #697ec4;
|
||||
color: #fff;
|
||||
}
|
Loading…
Reference in New Issue