JAVA-29305 Upgrade spring-security-web-boot-2 (#15510)
* JAVA-29305 Upgrade spring-security-web-boot-2 * JAVA-29305 Formatting code --------- Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
+6
-5
@@ -7,7 +7,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -21,7 +21,8 @@ import com.baeldung.customlogouthandler.services.UserCache;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = { CustomLogoutApplication.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@SqlGroup({ @Sql(value = "classpath:customlogouthandler/before.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD), @Sql(value = "classpath:customlogouthandler/after.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) })
|
||||
@SqlGroup({ @Sql(value = "classpath:customlogouthandler/before.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD),
|
||||
@Sql(value = "classpath:customlogouthandler/after.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) })
|
||||
@TestPropertySource(locations="classpath:customlogouthandler/application.properties")
|
||||
class CustomLogoutHandlerIntegrationTest {
|
||||
|
||||
@@ -37,7 +38,7 @@ class CustomLogoutHandlerIntegrationTest {
|
||||
@Test
|
||||
public void whenLogin_thenUseUserCache() {
|
||||
// User cache should be empty on start
|
||||
assertThat(userCache.size()).isEqualTo(0);
|
||||
assertThat(userCache.size()).isZero();
|
||||
|
||||
// Request using first login
|
||||
ResponseEntity<String> response = restTemplate.withBasicAuth("user", "pass")
|
||||
@@ -66,7 +67,7 @@ class CustomLogoutHandlerIntegrationTest {
|
||||
@Test
|
||||
public void whenLogout_thenCacheIsEmpty() {
|
||||
// User cache should be empty on start
|
||||
assertThat(userCache.size()).isEqualTo(0);
|
||||
assertThat(userCache.size()).isZero();
|
||||
|
||||
// Request using first login
|
||||
ResponseEntity<String> response = restTemplate.withBasicAuth("user", "pass")
|
||||
@@ -89,7 +90,7 @@ class CustomLogoutHandlerIntegrationTest {
|
||||
|
||||
// User cache must be empty now
|
||||
// this is the reaction on custom logout filter execution
|
||||
assertThat(userCache.size()).isEqualTo(0);
|
||||
assertThat(userCache.size()).isZero();
|
||||
|
||||
// Assert unauthorized request
|
||||
response = restTemplate.exchange(getLanguageUrl(), HttpMethod.GET, new HttpEntity<String>(requestHeaders), String.class);
|
||||
|
||||
+2
-2
@@ -17,10 +17,10 @@ public class UserControllerLiveTest {
|
||||
private static final String PRINCIPAL_SVC_URL = "http://localhost:8082/principal";
|
||||
|
||||
@Test
|
||||
public void givenExisting_whenRequestPrincipal_thenRetrieveData() throws Exception {
|
||||
public void givenExisting_whenRequestPrincipal_thenRetrieveData() {
|
||||
SessionFilter filter = new SessionFilter();
|
||||
given().auth()
|
||||
.form("user", "pass", new FormAuthConfig("/login", "username", "password").withCsrfFieldName("_csrf"))
|
||||
.form("user", "pass", new FormAuthConfig("/login", "username", "password").withAdditionalField("_csrf"))
|
||||
.and()
|
||||
.filter(filter)
|
||||
.when()
|
||||
|
||||
+7
-4
@@ -1,8 +1,10 @@
|
||||
package com.baeldung.web;
|
||||
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.hc.client5.http.classic.HttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
|
||||
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
|
||||
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import com.baeldung.ssl.HttpsEnabledApplication;
|
||||
import org.junit.Test;
|
||||
@@ -47,8 +49,9 @@ public class HttpsApplicationIntegrationTest {
|
||||
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray())
|
||||
.build();
|
||||
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext);
|
||||
HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(socketFactory).build();
|
||||
HttpClient httpClient = HttpClients.custom()
|
||||
.setSSLSocketFactory(socketFactory)
|
||||
.setConnectionManager(connectionManager)
|
||||
.build();
|
||||
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
return new RestTemplate(factory);
|
||||
|
||||
+4
-4
@@ -24,7 +24,7 @@ public class MultipleAuthProvidersApplicationIntegrationTest {
|
||||
public void givenMemUsers_whenGetPingWithValidUser_thenOk() {
|
||||
ResponseEntity<String> result = makeRestCallToGetPing("memuser", "pass");
|
||||
|
||||
assertThat(result.getStatusCodeValue()).isEqualTo(200);
|
||||
assertThat(result.getStatusCode().value()).isEqualTo(200);
|
||||
assertThat(result.getBody()).isEqualTo("OK");
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class MultipleAuthProvidersApplicationIntegrationTest {
|
||||
public void givenExternalUsers_whenGetPingWithValidUser_thenOK() {
|
||||
ResponseEntity<String> result = makeRestCallToGetPing("externaluser", "pass");
|
||||
|
||||
assertThat(result.getStatusCodeValue()).isEqualTo(200);
|
||||
assertThat(result.getStatusCode().value()).isEqualTo(200);
|
||||
assertThat(result.getBody()).isEqualTo("OK");
|
||||
}
|
||||
|
||||
@@ -40,14 +40,14 @@ public class MultipleAuthProvidersApplicationIntegrationTest {
|
||||
public void givenAuthProviders_whenGetPingWithNoCred_then401() {
|
||||
ResponseEntity<String> result = makeRestCallToGetPing();
|
||||
|
||||
assertThat(result.getStatusCodeValue()).isEqualTo(401);
|
||||
assertThat(result.getStatusCode().value()).isEqualTo(401);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAuthProviders_whenGetPingWithBadCred_then401() {
|
||||
ResponseEntity<String> result = makeRestCallToGetPing("user", "bad_password");
|
||||
|
||||
assertThat(result.getStatusCodeValue()).isEqualTo(401);
|
||||
assertThat(result.getStatusCode().value()).isEqualTo(401);
|
||||
}
|
||||
|
||||
private ResponseEntity<String> makeRestCallToGetPing(String username, String password) {
|
||||
|
||||
Reference in New Issue
Block a user