Skip to content

Commit

Permalink
IGNITE-22077 Add spring 6 support to spring session extension (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
shnus authored May 22, 2024
1 parent 4c23d61 commit 8f50f51
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ getJavaSpecificOpts() {
--add-opens=java.base/java.time=ALL-UNNAMED \
--add-opens=java.base/java.text=ALL-UNNAMED \
--add-opens=java.management/sun.management=ALL-UNNAMED \
--add-opens java.desktop/java.awt.font=ALL-UNNAMED \
--add-opens=java.desktop/java.awt.font=ALL-UNNAMED \
${current_value}"
fi

Expand Down
28 changes: 18 additions & 10 deletions modules/spring-session-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@
</parent>

<artifactId>ignite-spring-session-ext</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<url>https://ignite.apache.org</url>

<properties>
<spring.session.version>2.5.0</spring.session.version>
<spring.security.version>5.5.0</spring.security.version>
<javax.annotation.version>1.3.2</javax.annotation.version>
<maven.compiler.release>17</maven.compiler.release>

<spring.session.version>3.2.2</spring.session.version>
<spring.security.version>6.2.4</spring.security.version>
<jakarta.annotation.version>3.0.0</jakarta.annotation.version>
<assertj.version>3.20.0</assertj.version>
<junit.jupiter.version>5.7.2</junit.jupiter.version>
<junit.jupiter.version>5.10.2</junit.jupiter.version>
<javax.servlet.version>3.0.1</javax.servlet.version>
</properties>

Expand All @@ -48,7 +50,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring53.version}</version>
<version>${spring61.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -99,9 +101,9 @@
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax.annotation.version}</version>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta.annotation.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
Expand Down Expand Up @@ -151,8 +153,14 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import jakarta.annotation.PostConstruct;
import org.apache.ignite.Ignite;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.client.IgniteClient;
Expand Down Expand Up @@ -79,6 +80,9 @@ public class IgniteHttpSessionConfiguration extends SpringHttpSessionConfigurati
/** */
private List<SessionRepositoryCustomizer<IgniteIndexedSessionRepository>> sesRepoCustomizers;

/** */
private Object connObj;

/**
* @return Session repository.
*/
Expand Down Expand Up @@ -134,7 +138,15 @@ public void setSessions(
if (connObj == null)
connObj = cli.getIfAvailable();

this.sessions = createSessionProxy(connObj);
this.connObj = connObj;
}

/**
* Init sessions.
*/
@PostConstruct
public void initSessions() {
this.sessions = createSessionProxy(this.connObj);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.PreDestroy;
import jakarta.annotation.PreDestroy;
import javax.cache.configuration.CacheEntryListenerConfiguration;
import javax.cache.configuration.Factory;
import javax.cache.event.CacheEntryCreatedListener;
Expand All @@ -47,6 +47,8 @@
import org.springframework.session.PrincipalNameIndexResolver;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.events.AbstractSessionEvent;
import org.springframework.session.events.SessionCreatedEvent;
import org.springframework.session.events.SessionDeletedEvent;
Expand Down Expand Up @@ -121,6 +123,9 @@ public class IgniteIndexedSessionRepository
/** The index resolver. */
private IndexResolver<Session> idxResolver = new DelegatingIndexResolver<>(new PrincipalNameIndexResolver<>());

/** Session id generator. */
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();

/** Sessions cache proxy. */
private final SessionProxy sessions;

Expand Down Expand Up @@ -216,18 +221,31 @@ public void setSaveMode(SaveMode saveMode) {
this.saveMode = saveMode;
}

/**
* Set session id generator.
* @param sesIdGenerator Session id generator.
*/
public void setSessionIdGenerator(SessionIdGenerator sesIdGenerator) {
Assert.notNull(sesIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sesIdGenerator;
}

/** {@inheritDoc} */
@Override public IgniteSession createSession() {
MapSession cached = new MapSession();

if (this.dfltMaxInactiveInterval != null)
cached.setMaxInactiveInterval(Duration.ofSeconds(this.dfltMaxInactiveInterval));

cached.setSessionIdGenerator(this.sessionIdGenerator);

return new IgniteSession(cached, idxResolver, true, saveMode, this::flushImmediateIfNecessary);
}

/** {@inheritDoc} */
@Override public void save(IgniteSession ses) {
ses.getDelegate().setSessionIdGenerator(this.sessionIdGenerator);

if (ses.isNew())
ttlSessions(ses.getMaxInactiveInterval()).put(ses.getId(), ses);
else {
Expand Down Expand Up @@ -263,7 +281,10 @@ else if (ses.hasChanges()) {
return null;
}

return new IgniteSession(saved.getDelegate(), idxResolver, false, saveMode, this::flushImmediateIfNecessary);
MapSession mapSession = saved.getDelegate();
mapSession.setSessionIdGenerator(this.sessionIdGenerator);

return new IgniteSession(mapSession, idxResolver, false, saveMode, this::flushImmediateIfNecessary);
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -389,7 +410,7 @@ private void updatePartial(IgniteSession ses) {
if (oldSes == null)
break;

updatedSes = new IgniteSession(oldSes.getDelegate(), idxResolver, false, saveMode, this::flushImmediateIfNecessary);
updatedSes = new IgniteSession(new MapSession(oldSes.getDelegate()), idxResolver, false, saveMode, this::flushImmediateIfNecessary);
copyChanges(updatedSes, ses);

if (attempt > MAX_UPDATE_ATTEMPT) {
Expand All @@ -399,6 +420,6 @@ private void updatePartial(IgniteSession ses) {
ttlSessions(ses.getMaxInactiveInterval()).replace(ses.getId(), updatedSes);
break;
}
} while (ttlSessions(ses.getMaxInactiveInterval()).replace(ses.getId(), oldSes, updatedSes));
} while (!ttlSessions(ses.getMaxInactiveInterval()).replace(ses.getId(), oldSes, updatedSes));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void namedIgniteConfiguration() {
void multipleIgniteConfiguration() {
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> registerAndRefresh(MultipleIgniteConfiguration.class))
.withMessageContaining("expected single matching bean but found 2");
.withStackTraceContaining("expected single matching bean but found 2");
}

/** */
Expand Down Expand Up @@ -410,6 +410,7 @@ static class NamedIgniteConfiguration extends BaseConfiguration {

/** */
@Bean
@Primary
Ignite ignite() {
return mockedIgnite(igniteSessions);
}
Expand Down
97 changes: 97 additions & 0 deletions parent-internal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<spring-boot.version>2.2.13.RELEASE</spring-boot.version>
<spring.data.version>2.2.13.RELEASE</spring.data.version>
<spring53.version>5.3.19</spring53.version>
<spring61.version>6.1.6</spring61.version>

<!--
NOTE: The dependency versions below must be changed in the release branch up to
Expand Down Expand Up @@ -191,5 +192,101 @@
</plugins>
</build>
</profile>
<profile>
<id>java-9+</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<properties>
<maven.compiler.release>8</maven.compiler.release>
</properties>
</profile>
<profile>
<id>java-15+</id>
<activation>
<jdk>[15,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- Do not bring ignite logic -->
<inherited>false</inherited>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<argLine>
--add-opens=java.base/jdk.internal.access=ALL-UNNAMED
--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED
--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED
--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
--add-opens=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED
--add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED
--add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED
--add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.net=ALL-UNNAMED
--add-opens=java.base/java.nio=ALL-UNNAMED
--add-opens=java.base/java.security.cert=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=java.base/java.util.concurrent=ALL-UNNAMED
--add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED
--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
--add-opens=java.base/java.time=ALL-UNNAMED
--add-opens=java.base/sun.security.ssl=ALL-UNNAMED
--add-opens=java.base/sun.security.x509=ALL-UNNAMED
--add-opens=java.base/sun.net.util=ALL-UNNAMED
--add-opens=java.sql/java.sql=ALL-UNNAMED
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED
--add-opens=java.base/java.text=ALL-UNNAMED
--add-opens=java.desktop/java.awt.font=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<configuration>
<jvmArgs>
<jvmArg>--add-opens=java.base/jdk.internal.access=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/sun.nio.ch=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.io=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.net=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.nio=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.security.cert=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.util=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.util.concurrent=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.lang=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.lang.invoke=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.time=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/sun.security.ssl=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/sun.security.x509=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/sun.net.util=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.sql/java.sql=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.lang.reflect=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.base/java.text=ALL-UNNAMED</jvmArg>
<jvmArg>--add-opens=java.desktop/java.awt.font=ALL-UNNAMED</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<module>modules/performance-statistics-ext</module>
<module>modules/spring-tx-ext</module>
<module>modules/spring-cache-ext</module>
<module>modules/spring-session-ext</module>
<module>modules/cdc-ext</module>
<module>modules/aws-ext</module>
<module>modules/azure-ext</module>
Expand All @@ -74,6 +73,15 @@
<module>../ignite</module>
</modules>
</profile>
<profile>
<id>java-17+</id>
<activation>
<jdk>[17,)</jdk>
</activation>
<modules>
<module>modules/spring-session-ext</module>
</modules>
</profile>
</profiles>

<build>
Expand Down

0 comments on commit 8f50f51

Please sign in to comment.