BAEL-4628 - Spring Security SAMl with Okta
This commit is contained in:
parent
bc4ea42b7d
commit
bb5cf873c8
@ -23,14 +23,14 @@
|
|||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
@ -40,7 +40,7 @@
|
|||||||
<artifactId>spring-security-saml2-core</artifactId>
|
<artifactId>spring-security-saml2-core</artifactId>
|
||||||
<version>${saml2-core.spring.version}</version>
|
<version>${saml2-core.spring.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>spring-security-saml</finalName>
|
<finalName>spring-security-saml</finalName>
|
||||||
|
@ -129,12 +129,6 @@ public class SamlSecurityConfig {
|
|||||||
samlEntryPoint.setDefaultProfileOptions(defaultWebSSOProfileOptions());
|
samlEntryPoint.setDefaultProfileOptions(defaultWebSSOProfileOptions());
|
||||||
return samlEntryPoint;
|
return samlEntryPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public SAMLDiscovery samlIDPDiscovery() {
|
|
||||||
SAMLDiscovery idpDiscovery = new SAMLDiscovery();
|
|
||||||
return idpDiscovery;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ExtendedMetadata extendedMetadata() {
|
public ExtendedMetadata extendedMetadata() {
|
||||||
|
@ -53,8 +53,11 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SAMLLogoutProcessingFilter samlLogoutProcessingFilter;
|
private SAMLLogoutProcessingFilter samlLogoutProcessingFilter;
|
||||||
|
|
||||||
@Autowired
|
@Bean
|
||||||
private SAMLDiscovery samlDiscovery;
|
public SAMLDiscovery samlDiscovery() {
|
||||||
|
SAMLDiscovery idpDiscovery = new SAMLDiscovery();
|
||||||
|
return idpDiscovery;
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SAMLAuthenticationProvider samlAuthenticationProvider;
|
private SAMLAuthenticationProvider samlAuthenticationProvider;
|
||||||
@ -89,7 +92,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"),
|
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"),
|
||||||
samlWebSSOProcessingFilter()));
|
samlWebSSOProcessingFilter()));
|
||||||
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/discovery/**"),
|
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/discovery/**"),
|
||||||
samlDiscovery));
|
samlDiscovery()));
|
||||||
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"),
|
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"),
|
||||||
samlEntryPoint));
|
samlEntryPoint));
|
||||||
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"),
|
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"),
|
||||||
@ -115,21 +118,21 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
http
|
http
|
||||||
.csrf()
|
.csrf()
|
||||||
.disable();
|
.disable();
|
||||||
|
|
||||||
http
|
http
|
||||||
.httpBasic()
|
.httpBasic()
|
||||||
.authenticationEntryPoint(samlEntryPoint);
|
.authenticationEntryPoint(samlEntryPoint);
|
||||||
|
|
||||||
http
|
http
|
||||||
.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
|
.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
|
||||||
.addFilterAfter(samlFilter(), BasicAuthenticationFilter.class)
|
.addFilterAfter(samlFilter(), BasicAuthenticationFilter.class)
|
||||||
.addFilterBefore(samlFilter(), CsrfFilter.class);
|
.addFilterBefore(samlFilter(), CsrfFilter.class);
|
||||||
|
|
||||||
http
|
http
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers("/").permitAll()
|
.antMatchers("/").permitAll()
|
||||||
.anyRequest().authenticated();
|
.anyRequest().authenticated();
|
||||||
|
|
||||||
http
|
http
|
||||||
.logout()
|
.logout()
|
||||||
.addLogoutHandler((request, response, authentication) -> {
|
.addLogoutHandler((request, response, authentication) -> {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
saml.keystore.location=classpath:/saml/samlKeystore.jks
|
saml.keystore.location=classpath:/saml/samlKeystore.jks
|
||||||
saml.keystore.password=oktaiscool
|
saml.keystore.password=<key_pass>
|
||||||
saml.keystore.alias=oktasaml
|
saml.keystore.alias=<key_alias>
|
||||||
|
|
||||||
saml.idp=http://www.okta.com/exk26fxqrz8LLk9dV4x7
|
saml.idp=<idp_issuer_url>
|
||||||
saml.sp=http://localhost:8080/saml/metadata
|
saml.sp=http://localhost:8080/saml/metadata
|
@ -6,10 +6,8 @@
|
|||||||
<body>
|
<body>
|
||||||
<h3><Strong>Welcome!</strong><br/>You are successfully logged in!</h3>
|
<h3><Strong>Welcome!</strong><br/>You are successfully logged in!</h3>
|
||||||
<p>You are logged as <span class="badge badge-dark" th:text="${username}">null</span>.</p>
|
<p>You are logged as <span class="badge badge-dark" th:text="${username}">null</span>.</p>
|
||||||
<small class="d-block text-right mt-3" id="sso-btn">
|
<small>
|
||||||
<a th:href="@{/logout}" class="btn btn-spring btn-sm">
|
<a th:href="@{/logout}">Logout</a>
|
||||||
<i class="far fa-user-circle"></i> Logout
|
|
||||||
</a>
|
|
||||||
</small>
|
</small>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -5,8 +5,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h3><Strong>Welcome to Baeldung Spring Security SAML</strong></h3>
|
<h3><Strong>Welcome to Baeldung Spring Security SAML</strong></h3>
|
||||||
<a th:href="@{/auth}" class="btn btn-spring btn-sm">
|
<a th:href="@{/auth}">Login</a>
|
||||||
<i class="far fa-user-circle"></i> Login
|
|
||||||
</a>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user