Merge branch '3.1.x'

Closes gh-2530
This commit is contained in:
Marcus Da Coregio
2023-10-19 10:35:43 -03:00
104 changed files with 732 additions and 634 deletions

View File

@@ -41,11 +41,12 @@ public class SessionConfig {
networkConfig.setPort(0);
networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false);
AttributeConfig attributeConfig = new AttributeConfig()
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
.setExtractorClassName(PrincipalNameExtractor.class.getName());
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
.setExtractorClassName(PrincipalNameExtractor.class.getName());
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
.addAttributeConfig(attributeConfig).addIndexConfig(
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
.addAttributeConfig(attributeConfig)
.addIndexConfig(
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
config.getSerializationConfig().addSerializerConfig(serializerConfig);

View File

@@ -70,8 +70,8 @@ public class HomePage {
public List<Attribute> attributes() {
List<Attribute> rows = this.trs.stream() //
.map(Attribute::new) //
.collect(Collectors.toList());
.map(Attribute::new) //
.collect(Collectors.toList());
this.attributes.addAll(rows);

View File

@@ -49,7 +49,7 @@ class RedisSerializerTest {
assertThat(this.sessionRedisTemplate).isNotNull();
assertThat(this.sessionRedisTemplate.getDefaultSerializer()).isNotNull();
assertThat(this.sessionRedisTemplate.getDefaultSerializer())
.isInstanceOf(GenericJackson2JsonRedisSerializer.class);
.isInstanceOf(GenericJackson2JsonRedisSerializer.class);
}
@TestConfiguration

View File

@@ -71,7 +71,7 @@ class ApplicationTests {
"ws://localhost:" + this.port + "/sockjs");
assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(() -> wsSession.get().sendMessage(new TextMessage("a")));
.isThrownBy(() -> wsSession.get().sendMessage(new TextMessage("a")));
}
@TestConfiguration

View File

@@ -32,7 +32,7 @@ public class SecurityConfig {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser(User.withUsername("user").password("{noop}password").roles("USER").build());
.withUser(User.withUsername("user").password("{noop}password").roles("USER").build());
}
}

View File

@@ -42,11 +42,12 @@ public class SessionConfig {
networkConfig.setPort(0);
networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false);
AttributeConfig attributeConfig = new AttributeConfig()
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
.setExtractorClassName(PrincipalNameExtractor.class.getName());
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
.setExtractorClassName(PrincipalNameExtractor.class.getName());
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
.addAttributeConfig(attributeConfig).addIndexConfig(
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
.addAttributeConfig(attributeConfig)
.addIndexConfig(
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
return Hazelcast.newHazelcastInstance(config);
}

View File

@@ -35,7 +35,9 @@ public class Config {
@Bean
public EmbeddedDatabase dataSource() {
return new EmbeddedDatabaseBuilder() // <2>
.setType(EmbeddedDatabaseType.H2).addScript("org/springframework/session/jdbc/schema-h2.sql").build();
.setType(EmbeddedDatabaseType.H2)
.addScript("org/springframework/session/jdbc/schema-h2.sql")
.build();
}
@Bean

View File

@@ -65,14 +65,18 @@ class RestMockMvcTests {
@BeforeEach
void setup() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).alwaysDo(print())
.addFilters(this.sessionRepositoryFilter).apply(springSecurity()).build();
this.mvc = MockMvcBuilders.webAppContextSetup(this.context)
.alwaysDo(print())
.addFilters(this.sessionRepositoryFilter)
.apply(springSecurity())
.build();
}
@Test
void noSessionOnNoCredentials() throws Exception {
this.mvc.perform(get("/")).andExpect(header().doesNotExist("X-Auth-Token"))
.andExpect(status().isUnauthorized());
this.mvc.perform(get("/"))
.andExpect(header().doesNotExist("X-Auth-Token"))
.andExpect(status().isUnauthorized());
}
@WithMockUser

View File

@@ -60,8 +60,8 @@ class RestTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
assertThatExceptionOfType(HttpClientErrorException.class)
.isThrownBy(() -> getForUser(this.baseUrl + "/", headers, String.class))
.satisfies((e) -> assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED));
.isThrownBy(() -> getForUser(this.baseUrl + "/", headers, String.class))
.satisfies((e) -> assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED));
}
@Test

View File

@@ -52,7 +52,7 @@ public class SecurityConfig {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser(User.withUsername("user").password("{noop}password").roles("USER").build());
.withUser(User.withUsername("user").password("{noop}password").roles("USER").build());
}
}

View File

@@ -32,7 +32,7 @@ public class SecurityConfig {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser(User.withUsername("user").password("{noop}password").roles("USER").build());
.withUser(User.withUsername("user").password("{noop}password").roles("USER").build());
}
}