Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-7009 Spring-session implementation
- Loading branch information
1 parent
d0a8c0b
commit 2de17a5
Showing
40 changed files
with
1,721 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-parent</artifactId> | ||
<version>9.0.0-SNAPSHOT</version> | ||
<relativePath>../../parent/pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>infinispan-spring-boot-it</artifactId> | ||
<name>Integration tests: Spring Boot</name> | ||
<description>Integration tests for Infinispan and Spring Boot</description> | ||
|
||
<properties> | ||
<!-- Most or our tests require JUnit 4.11 for Aruquillian, however Spring needs 4.12 --> | ||
<!-- FIXME: https://issues.jboss.org/browse/ISPN-7034 --> | ||
<overriden.version.junit>4.12</overriden.version.junit> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${version.spring-boot}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!-- Those are normal dependencies that are recommended for Spring Boot users --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.session</groupId> | ||
<artifactId>spring-session</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>infinispan-spring4-embedded</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>infinispan-spring4-remote</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>infinispan-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>infinispan-client-hotrod</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Helper, test dependencies --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>infinispan-server-hotrod</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
<version>${overriden.version.junit}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>infinispan-server-hotrod</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>smoke</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-test</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration combine.self="override"> | ||
<excludedGroups>${suite.exclude.groups}</excludedGroups> | ||
<systemPropertyVariables> | ||
<log4j.configurationFile>${log4j.configurationFile}</log4j.configurationFile> | ||
<build.directory>${project.build.directory}</build.directory> | ||
</systemPropertyVariables> | ||
<trimStackTrace>false</trimStackTrace> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven.surefire</groupId> | ||
<artifactId>surefire-junit4</artifactId> | ||
<version>${version.maven.surefire}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
39 changes: 39 additions & 0 deletions
39
...st/java/org/infinispan/integrationtests/spring/boot/session/AbstractSpringSessionTCK.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.infinispan.integrationtests.spring.boot.session; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.embedded.LocalServerPort; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.session.MapSession; | ||
import org.springframework.session.SessionRepository; | ||
|
||
public class AbstractSpringSessionTCK { | ||
|
||
@Autowired | ||
private SessionRepository<MapSession> sessionRepository; | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
@Test | ||
public void testCreatingSessionWhenUsingREST() throws Exception { | ||
//given | ||
TestRestTemplate restTemplate = new TestRestTemplate("user", "password"); | ||
|
||
//when | ||
HttpHeaders httpHeaders = restTemplate.headForHeaders(getTestURL()); | ||
|
||
//then | ||
Assert.assertNotNull(sessionRepository.getSession(getSessionId(httpHeaders))); | ||
} | ||
|
||
private String getTestURL() { | ||
return "http://localhost:" + port + "/test"; | ||
} | ||
|
||
private String getSessionId(HttpHeaders httpHeaders) { | ||
return httpHeaders.getValuesAsList("x-auth-token").get(0); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ava/org/infinispan/integrationtests/spring/boot/session/configuration/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.infinispan.integrationtests.spring.boot.session.configuration; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
|
||
/** | ||
* Since Spring Session is heavily based on security - we need to define basic user/password. | ||
*/ | ||
@EnableWebSecurity | ||
public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
|
||
@Autowired | ||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { | ||
auth.inMemoryAuthentication().withUser("user").password("password").roles("USER"); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...est/java/org/infinispan/integrationtests/spring/boot/session/configuration/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.infinispan.integrationtests.spring.boot.session.configuration; | ||
|
||
import org.infinispan.integrationtests.spring.boot.session.web.TestRESTController; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.session.web.http.HeaderHttpSessionStrategy; | ||
import org.springframework.session.web.http.HttpSessionStrategy; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
public class WebConfig { | ||
|
||
@Bean | ||
public HttpSessionStrategy httpSessionStrategy() { | ||
return new HeaderHttpSessionStrategy(); | ||
} | ||
|
||
@Bean | ||
public TestRESTController sessionCreator() { | ||
return new TestRESTController(); | ||
} | ||
|
||
@Bean | ||
public SecurityConfig securityConfig() { | ||
return new SecurityConfig(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...a/org/infinispan/integrationtests/spring/boot/session/embedded/EmbeddedConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.infinispan.integrationtests.spring.boot.session.embedded; | ||
|
||
import org.infinispan.integrationtests.spring.boot.session.configuration.WebConfig; | ||
import org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean; | ||
import org.infinispan.spring.session.configuration.EnableInfinispanEmbeddedHttpSession; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Configuration | ||
@EnableAutoConfiguration | ||
@EnableInfinispanEmbeddedHttpSession | ||
@Import(WebConfig.class) | ||
public class EmbeddedConfiguration { | ||
|
||
@Bean | ||
public SpringEmbeddedCacheManagerFactoryBean springCacheManager() { | ||
return new SpringEmbeddedCacheManagerFactoryBean(); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...g/infinispan/integrationtests/spring/boot/session/embedded/EmbeddedSpringSessionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.infinispan.integrationtests.spring.boot.session.embedded; | ||
|
||
import org.infinispan.integrationtests.spring.boot.session.AbstractSpringSessionTCK; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = EmbeddedConfiguration.class, webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class EmbeddedSpringSessionTest extends AbstractSpringSessionTCK { | ||
|
||
} |
Oops, something went wrong.