Merge pull request #4672 from Doha2012/master

upgrade to spring boot 2
This commit is contained in:
Loredana Crusoveanu 2018-07-10 09:33:22 +03:00 committed by GitHub
commit f959cbe55a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 45 additions and 36 deletions

View File

@ -9,10 +9,10 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<parent> <parent>
<artifactId>parent-boot-1</artifactId> <artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-1</relativePath> <relativePath>../parent-boot-2</relativePath>
</parent> </parent>
<modules> <modules>
@ -22,7 +22,9 @@
</modules> </modules>
<properties> <properties>
<rest-assured.version>3.0.1</rest-assured.version> <rest-assured.version>3.1.0</rest-assured.version>
</properties> <oauth.version>2.3.3.RELEASE</oauth.version>
<oauth-auto.version>2.0.1.RELEASE</oauth-auto.version>
</properties>
</project> </project>

View File

@ -21,6 +21,7 @@
<dependency> <dependency>
<groupId>org.springframework.security.oauth</groupId> <groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId> <artifactId>spring-security-oauth2</artifactId>
<version>${oauth.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -2,19 +2,20 @@ package org.baeldung.config;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
@Configuration @Configuration
@EnableAuthorizationServer @EnableAuthorizationServer
public class AuthServerConfig extends AuthorizationServerConfigurerAdapter { public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager; @Autowired
private BCryptPasswordEncoder passwordEncoder;
@Override @Override
public void configure(final AuthorizationServerSecurityConfigurer oauthServer) throws Exception { public void configure(final AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.tokenKeyAccess("permitAll()") oauthServer.tokenKeyAccess("permitAll()")
@ -25,17 +26,14 @@ public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {
public void configure(final ClientDetailsServiceConfigurer clients) throws Exception { public void configure(final ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory() clients.inMemory()
.withClient("SampleClientId") .withClient("SampleClientId")
.secret("secret") .secret(passwordEncoder.encode("secret"))
.authorizedGrantTypes("authorization_code") .authorizedGrantTypes("authorization_code")
.scopes("user_info") .scopes("user_info")
.autoApprove(true) .autoApprove(true)
.redirectUris("http://localhost:8082/ui/login","http://localhost:8083/ui2/login")
// .accessTokenValiditySeconds(3600) // .accessTokenValiditySeconds(3600)
; // 1 hour ; // 1 hour
} }
@Override
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager);
}
} }

View File

@ -2,7 +2,7 @@ package org.baeldung.config;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
@SpringBootApplication @SpringBootApplication

View File

@ -1,18 +1,17 @@
package org.baeldung.config; package org.baeldung.config;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@Configuration @Configuration
@Order(1)
public class SecurityConfig extends WebSecurityConfigurerAdapter { public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Override @Override
protected void configure(HttpSecurity http) throws Exception { // @formatter:off protected void configure(HttpSecurity http) throws Exception { // @formatter:off
http.requestMatchers() http.requestMatchers()
@ -28,11 +27,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception { // @formatter:off protected void configure(AuthenticationManagerBuilder auth) throws Exception { // @formatter:off
auth.parentAuthenticationManager(authenticationManager) auth.inMemoryAuthentication()
.inMemoryAuthentication()
.withUser("john") .withUser("john")
.password("123") .password(passwordEncoder().encode("123"))
.roles("USER"); .roles("USER");
} // @formatter:on } // @formatter:on
@Bean
public BCryptPasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
} }

View File

@ -1,4 +1,3 @@
server.port=8081 server.port=8081
server.context-path=/auth server.servlet.context-path=/auth
security.basic.enabled=false
#logging.level.org.springframework=DEBUG #logging.level.org.springframework=DEBUG

View File

@ -25,8 +25,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.security.oauth</groupId> <groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2</artifactId> <artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>${oauth-auto.version}</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -2,7 +2,7 @@ package org.baeldung.config;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.web.context.request.RequestContextListener; import org.springframework.web.context.request.RequestContextListener;

View File

@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableOAuth2Sso @EnableOAuth2Sso
@Configuration @Configuration
public class UiSecurityConfig extends WebSecurityConfigurerAdapter { public class UiSecurityConfig extends WebSecurityConfigurerAdapter {

View File

@ -1,6 +1,7 @@
server: server:
port: 8083 port: 8083
context-path: /ui2 servlet:
context-path: /ui2
session: session:
cookie: cookie:
name: UI2SESSION name: UI2SESSION

View File

@ -23,11 +23,13 @@
<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.security.oauth</groupId> <groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2</artifactId> <artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>${oauth-auto.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -2,7 +2,7 @@ package org.baeldung.config;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.web.context.request.RequestContextListener; import org.springframework.web.context.request.RequestContextListener;

View File

@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableOAuth2Sso @EnableOAuth2Sso
@Configuration @Configuration
public class UiSecurityConfig extends WebSecurityConfigurerAdapter { public class UiSecurityConfig extends WebSecurityConfigurerAdapter {

View File

@ -1,6 +1,7 @@
server: server:
port: 8082 port: 8082
context-path: /ui servlet:
context-path: /ui
session: session:
cookie: cookie:
name: UISESSION name: UISESSION