Commit e63263ac authored by Szabolcs Gyurko's avatar Szabolcs Gyurko
Browse files

Upgraded spring boot to the 2.x train

parent 862145d5
Pipeline #328 failed with stage
in 9 seconds
......@@ -113,8 +113,9 @@
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>${jeff.spring.boot.version}</version>
</dependency>
<!-- Lombok for generating getters/setters -->
......@@ -192,6 +193,19 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<java.version>${java.version}</java.version>
<some.custom.property>some value</some.custom.property>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......
......@@ -28,9 +28,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
......
......@@ -30,8 +30,10 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
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.EnableAuthorizationServer;
......@@ -57,13 +59,13 @@ import java.util.Collections;
@Profile("!test")
public class AuthorisationServerConfig extends AuthorizationServerConfigurerAdapter {
private static final long MAX_AGE = 3600L;
private final AuthenticationManager authenticationManager;
private final AuthenticationConfiguration authenticationConfiguration;
private final DataSource dataSource;
private final UserDetailsService userDetailsService;
public AuthorisationServerConfig(final AuthenticationManager authenticationManager, final DataSource dataSource,
public AuthorisationServerConfig(final AuthenticationConfiguration authenticationConfiguration, final DataSource dataSource,
final H2UserDetailsService h2UserDetailsService) {
this.authenticationManager = authenticationManager;
this.authenticationConfiguration = authenticationConfiguration;
this.dataSource = dataSource;
this.userDetailsService = h2UserDetailsService;
}
......@@ -83,10 +85,15 @@ public class AuthorisationServerConfig extends AuthorizationServerConfigurerAdap
return new JdbcAuthorizationCodeServices(dataSource);
}
@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpointsConfigurer) throws Exception {
endpointsConfigurer
.authenticationManager(authenticationManager)
.authenticationManager(authenticationConfiguration.getAuthenticationManager())
.approvalStore(approvalStore())
.authorizationCodeServices(authorizationCodeServices())
.userDetailsService(userDetailsService)
......@@ -96,6 +103,7 @@ public class AuthorisationServerConfig extends AuthorizationServerConfigurerAdap
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security
.passwordEncoder(passwordEncoder())
.checkTokenAccess("isAuthenticated()")
.allowFormAuthenticationForClients();
}
......@@ -119,7 +127,7 @@ public class AuthorisationServerConfig extends AuthorizationServerConfigurerAdap
source.registerCorsConfiguration("/oauth/**", config);
final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
final FilterRegistrationBean bean = new FilterRegistrationBean<>(new CorsFilter(source));
bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return bean;
......
......@@ -52,6 +52,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@ActiveProfiles({"default", "test"})
@AutoConfigureMockMvc
public class OAuth2FlowsTest {
private static final String PASSWORD_HASH = "$2a$10$XAwe9oFkRLzESud3Zn6K0Ok0M7hj3ibxammXPFn0jiGiue.PCLWnS";
@MockBean
H2UserDetailsService h2UserDetailsService;
......@@ -61,7 +63,7 @@ public class OAuth2FlowsTest {
@Test
public void testPasswordFlow() throws Exception {
given(h2UserDetailsService.loadUserByUsername(any(String.class))).
willReturn(new org.springframework.security.core.userdetails.User("jeff", "pass",
willReturn(new org.springframework.security.core.userdetails.User("jeff", PASSWORD_HASH,
Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER"))));
mockMvc.perform(post("/oauth/token")
......@@ -74,7 +76,7 @@ public class OAuth2FlowsTest {
@Test
public void testClientCredentialsFlow() throws Exception {
given(h2UserDetailsService.loadUserByUsername(any(String.class))).
willReturn(new org.springframework.security.core.userdetails.User("jeff", "pass",
willReturn(new org.springframework.security.core.userdetails.User("jeff", PASSWORD_HASH,
Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER"))));
mockMvc.perform(post("/oauth/token")
......@@ -87,7 +89,7 @@ public class OAuth2FlowsTest {
@Test
public void testImplicitFlow() throws Exception {
given(h2UserDetailsService.loadUserByUsername(any(String.class))).
willReturn(new org.springframework.security.core.userdetails.User("jeff", "pass",
willReturn(new org.springframework.security.core.userdetails.User("jeff", PASSWORD_HASH,
Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER"))));
mockMvc.perform(post("/oauth/authorize")
......@@ -103,7 +105,7 @@ public class OAuth2FlowsTest {
@Test
public void testAuthorizationCodeFlow() throws Exception {
given(h2UserDetailsService.loadUserByUsername(any(String.class))).
willReturn(new org.springframework.security.core.userdetails.User("jeff", "pass",
willReturn(new org.springframework.security.core.userdetails.User("jeff", PASSWORD_HASH,
Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER"))));
MvcResult mvcResult = mockMvc.perform(post("/oauth/authorize")
......
......@@ -28,8 +28,10 @@ import com.jeff_cms.jeff.idm.service.H2UserDetailsService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
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.EnableAuthorizationServer;
......@@ -48,12 +50,12 @@ import javax.sql.DataSource;
public class TestAuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
private static final int ACCESS_TOKEN_VALIDITY = 600;
private final AuthenticationManager authenticationManager;
private final AuthenticationConfiguration authenticationConfiguration;
private final UserDetailsService userDetailsService;
public TestAuthorizationServerConfig(final AuthenticationManager authenticationManager, final DataSource dataSource,
final H2UserDetailsService h2UserDetailsService) {
this.authenticationManager = authenticationManager;
public TestAuthorizationServerConfig(final AuthenticationConfiguration authenticationConfiguration, final DataSource dataSource,
final H2UserDetailsService h2UserDetailsService) {
this.authenticationConfiguration = authenticationConfiguration;
this.userDetailsService = h2UserDetailsService;
}
......@@ -67,10 +69,15 @@ public class TestAuthorizationServerConfig extends AuthorizationServerConfigurer
return new InMemoryAuthorizationCodeServices();
}
@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpointsConfigurer) throws Exception {
endpointsConfigurer
.authenticationManager(authenticationManager)
.authenticationManager(authenticationConfiguration.getAuthenticationManager())
.approvalStoreDisabled()
.authorizationCodeServices(authorizationCodeServices())
.userDetailsService(userDetailsService)
......@@ -80,6 +87,7 @@ public class TestAuthorizationServerConfig extends AuthorizationServerConfigurer
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security
.passwordEncoder(passwordEncoder())
.checkTokenAccess("isAuthenticated()")
.allowFormAuthenticationForClients();
}
......@@ -87,7 +95,7 @@ public class TestAuthorizationServerConfig extends AuthorizationServerConfigurer
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("jeff").secret("jeff")
.withClient("jeff").secret("$2a$10$umOPlHGEbf9ZIdpBndHCGeh7hmMGhUBwOaoZDlWUL6U/fMeyeZM56").redirectUris("http://localhost:41810")
.authorizedGrantTypes("password", "refresh_token", "authorization_code", "client_credentials", "implicit")
.scopes("read", "write")
.autoApprove(true)
......
......@@ -68,8 +68,9 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>${jeff.spring.boot.version}</version>
</dependency>
<!-- Lombok for generating getters/setters -->
......@@ -201,6 +202,19 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<java.version>${java.version}</java.version>
<some.custom.property>some value</some.custom.property>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......
......@@ -28,9 +28,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
......
......@@ -40,6 +40,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.exceptions.base.MockitoException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
......@@ -55,7 +56,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
......@@ -111,7 +111,7 @@ public class MQReceiverTest {
when(session.getNode(any(String.class))).thenReturn(mock(javax.jcr.Node.class));
doNothing().when(session).logout();
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(PublishRequest.class), any(Class.class)))
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(Object.class), any(Class.class)))
.then(i -> {
if (i.getArguments()[1] instanceof PublishVersionRequest) {
return mockVersionResponse;
......@@ -135,7 +135,7 @@ public class MQReceiverTest {
mqReceiver.receiveStartPublication(startPublishRequest, null);
}
@Test(expected = ExecutionException.class)
@Test(expected = MockitoException.class)
@SuppressWarnings("unchecked")
public void testUnsuccessfulPublishWithException() throws Exception {
when(nodeConfiguration.getIgnorePublishErrors()).thenReturn(false);
......@@ -148,10 +148,9 @@ public class MQReceiverTest {
when(session.getNode(any(String.class))).thenReturn(mock(javax.jcr.Node.class));
doNothing().when(session).logout();
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(PublishRequest.class), any(Class.class)))
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(Object.class), any(Class.class)))
.thenThrow(UnknownHostException.class);
final StartPublishRequest.Entry entry = new StartPublishRequest.Entry();
entry.setRecursive(false);
entry.setPath("/");
......@@ -179,7 +178,7 @@ public class MQReceiverTest {
when(session.getNode(any(String.class))).thenReturn(mock(javax.jcr.Node.class));
doNothing().when(session).logout();
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(PublishRequest.class), any(Class.class)))
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(Object.class), any(Class.class)))
.then(i -> {
if (i.getArguments()[1] instanceof PublishVersionRequest) {
return mockVersionResponse;
......
......@@ -78,7 +78,7 @@ public class PublishServiceTest {
mockResponse.setUnsuccessful(new ArrayList<>());
mockVersionResponse.setNodes(Collections.EMPTY_LIST);
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(PublishRequest.class), any(Class.class)))
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(Object.class), any(Class.class)))
.then(i -> {
if (i.getArguments()[1] instanceof PublishVersionRequest) {
return mockVersionResponse;
......@@ -160,7 +160,7 @@ public class PublishServiceTest {
final PublishVersionResponse mockVersionResponse = new PublishVersionResponse();
mockVersionResponse.setNodes(Collections.EMPTY_LIST);
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(PublishRequest.class), any(Class.class)))
when(oAuth2RestOperations.<PublishResponse>postForObject(any(String.class), any(Object.class), any(Class.class)))
.then(i -> {
if (i.getArguments()[1] instanceof PublishVersionRequest) {
return mockVersionResponse;
......
......@@ -126,11 +126,11 @@ public class JcrUtilsTest {
when(principal.getName()).thenReturn("test");
when(node.setProperty(anyString(), anyString())).then(i -> {
res[1] = i.getArgumentAt(1, String.class);
res[1] = i.getArgument(1);
return null;
});
when(node.setProperty(anyString(), any(DateValue.class))).then(i -> {
res[0] = i.getArgumentAt(1, DateValue.class).getString();
res[0] = ((DateValue) i.getArgument(1)).getString();
return null;
});
......@@ -158,7 +158,7 @@ public class JcrUtilsTest {
when(propertyIterator.nextProperty()).thenReturn(property);
when(node.getProperties()).thenReturn(propertyIterator);
when(node.setProperty(anyString(), anyString())).then(i -> {
hash[0] = i.getArgumentAt(1, String.class);
hash[0] = i.getArgument(1);
return null;
});
......@@ -187,7 +187,7 @@ public class JcrUtilsTest {
when(propertyIterator.nextProperty()).thenReturn(property);
when(node.getProperties()).thenReturn(propertyIterator);
when(node.setProperty(anyString(), anyString())).then(i -> {
hash[0] = i.getArgumentAt(1, String.class);
hash[0] = i.getArgument(1);
return null;
});
......@@ -224,7 +224,7 @@ public class JcrUtilsTest {
when(propertyIterator.nextProperty()).thenReturn(property1, property2);
when(node.getProperties()).thenReturn(propertyIterator);
when(node.setProperty(anyString(), anyString())).then(i -> {
hash[0] = i.getArgumentAt(1, String.class);
hash[0] = i.getArgument(1);
return null;
});
......
......@@ -68,8 +68,9 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>${jeff.spring.boot.version}</version>
</dependency>
<!-- Actuator for exposing management endpoints -->
......@@ -159,6 +160,19 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<java.version>${java.version}</java.version>
<some.custom.property>some value</some.custom.property>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......
......@@ -28,9 +28,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
......
......@@ -36,7 +36,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.client.OAuth2RestOperations;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestOperations;
import java.util.regex.Pattern;
......@@ -49,7 +48,7 @@ import java.util.regex.Pattern;
public class InitializeNodes {
private static final Pattern PATH_PATTERN = Pattern.compile("^(/[^/]+)(/?.*)$");
private final RestOperations restOperations;
private final OAuth2RestOperations restOperations;
private final JeffConfiguration jeffConfiguration;
public InitializeNodes(@Qualifier("oauth2RestOperations") final OAuth2RestOperations restOperations,
......@@ -97,6 +96,6 @@ public class InitializeNodes {
nodePath = PATH_PATTERN.matcher(nodePath).replaceAll("$2");
}
LOGGER.info("Configured page node path ({}) exists.", jeffConfiguration.getPagesNodePath());
LOGGER.info("Configured page node path ({}) exists.", path);
}
}
......@@ -39,13 +39,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.14.RELEASE</version>
<version>2.1.1.RELEASE</version>
</parent>
<properties>
<java.version>1.11</java.version>
<lombok.version>1.18.8</lombok.version>
<h2.version>1.4.197</h2.version>
<jeff.spring.boot.version>2.1.1.RELEASE</jeff.spring.boot.version>
</properties>
<modules>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment