From 7877faffa5d2ab8a04de3e4b7c2b987c5832d1b4 Mon Sep 17 00:00:00 2001 From: "qiangsheng.ye" Date: Tue, 12 May 2020 18:31:59 +0800 Subject: [PATCH 01/15] init kylin spring-session --- .gitignore | 1 + gradle.properties | 4 ++++ spring-session-core/spring-session-core.gradle | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/.gitignore b/.gitignore index 9bb8bbf66..f35982eab 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ out *.rdb .checkstyle !etc/eclipse/.checkstyle +gradle/ !**/src/**/build .DS_Store spring-session-docs/package-lock.json diff --git a/gradle.properties b/gradle.properties index 3f1517d65..4036c52c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,7 @@ org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.parallel=true version=3.5.6 + +group_id=org.springframework.session +artifact_id=spring-session-core +release_url=https://repository.kyligence.io/repository/maven-releases/ diff --git a/spring-session-core/spring-session-core.gradle b/spring-session-core/spring-session-core.gradle index 4e7f9b7c8..257f39107 100644 --- a/spring-session-core/spring-session-core.gradle +++ b/spring-session-core/spring-session-core.gradle @@ -31,3 +31,19 @@ dependencies { testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine" testRuntimeOnly "org.junit.platform:junit-platform-launcher" } + + +apply plugin: 'maven' + +uploadArchives { + repositories { + mavenDeployer { + repository(url: release_url) { + authentication(userName: "admin", password: "Kyligence@2016") + } + pom.version = version + pom.artifactId = artifact_id + pom.groupId = group_id + } + } +} From 69f7577facadc13cc3f4ac27bbe6584d38e22457 Mon Sep 17 00:00:00 2001 From: "qiangsheng.ye" Date: Fri, 15 May 2020 10:30:16 +0800 Subject: [PATCH 02/15] KE-13728 use plugin nebula.optional-base and check http header name 'auto' --- .../http/SpringHttpSessionConfiguration.java | 9 ++++++++ .../web/http/SessionRepositoryFilter.java | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java index ecf6b588c..eb1b97ee9 100644 --- a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java +++ b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java @@ -28,6 +28,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; @@ -106,6 +107,12 @@ public class SpringHttpSessionConfiguration implements InitializingBean, Applica private List httpSessionListeners = new ArrayList<>(); + @Value("${kylin.web.session-skip-header-name:Auto}") + private String skipUpdateSessionHeaderName; + + @Value("${kylin.web.session-timeout:-1}") + private int sessionTimeout; + @Override public void afterPropertiesSet() { this.defaultHttpSessionIdResolver.setCookieSerializer(getCookieSerializer()); @@ -121,6 +128,8 @@ public SessionRepositoryFilter springSess SessionRepository sessionRepository) { SessionRepositoryFilter sessionRepositoryFilter = new SessionRepositoryFilter<>(sessionRepository); sessionRepositoryFilter.setHttpSessionIdResolver(this.httpSessionIdResolver); + sessionRepositoryFilter.setSessionTimeout(this.sessionTimeout); + sessionRepositoryFilter.setSkipCommitSessionHeaderName(this.skipUpdateSessionHeaderName); return sessionRepositoryFilter; } diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java index 32415a211..05044ff84 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java @@ -17,6 +17,7 @@ package org.springframework.session.web.http; import java.io.IOException; +import java.time.Duration; import java.time.Instant; import java.util.List; @@ -105,6 +106,18 @@ public class SessionRepositoryFilter extends OncePerRequestFi private HttpSessionIdResolver httpSessionIdResolver = new CookieHttpSessionIdResolver(); + private String skipCommitSessionHeaderName = "Auto"; + + public void setSkipCommitSessionHeaderName(String skipCommitSessionHeaderName) { + this.skipCommitSessionHeaderName = skipCommitSessionHeaderName; + } + + private int sessionTimeout = -1; + + public void setSessionTimeout(int sessionTimeout) { + this.sessionTimeout = sessionTimeout; + } + /** * Creates a new instance. * @param sessionRepository the SessionRepository to use. Cannot be null. @@ -223,6 +236,10 @@ private void commitSession() { } } else { + if (Boolean.valueOf(this.getHeader(skipCommitSessionHeaderName))) { + return; + } + S session = wrappedSession.getSession(); String requestedSessionId = getRequestedSessionId(); clearRequestedSessionCache(); @@ -317,6 +334,11 @@ public HttpSessionWrapper getSession(boolean create) { new RuntimeException("For debugging purposes only (not an error)")); } S session = SessionRepositoryFilter.this.sessionRepository.createSession(); + if (sessionTimeout > 60) { + session.setMaxInactiveInterval(Duration.ofSeconds(sessionTimeout)); + } else if (sessionTimeout > 0) { + session.setMaxInactiveInterval(Duration.ofSeconds(60)); + } session.setLastAccessedTime(Instant.now()); currentSession = new HttpSessionWrapper(session, getServletContext()); setCurrentSession(currentSession); From d8253ceb29563b95b29886692804421f84d892c8 Mon Sep 17 00:00:00 2001 From: zhoujiazhi <2529026882@qq.com> Date: Mon, 18 May 2020 18:27:53 +0800 Subject: [PATCH 03/15] KE-13712 KE-13713 secure session id & encode id to jdbc --- .../springframework/session/MapSession.java | 15 ++++++++++- .../http/SpringHttpSessionConfiguration.java | 13 ++++++++++ .../jdbc/JdbcIndexedSessionRepository.java | 26 ++++++++++++++++--- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/spring-session-core/src/main/java/org/springframework/session/MapSession.java b/spring-session-core/src/main/java/org/springframework/session/MapSession.java index 4f6949e08..5137f9745 100644 --- a/spring-session-core/src/main/java/org/springframework/session/MapSession.java +++ b/spring-session-core/src/main/java/org/springframework/session/MapSession.java @@ -16,7 +16,11 @@ package org.springframework.session; +import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration; +import org.springframework.util.DigestUtils; + import java.io.Serializable; +import java.security.SecureRandom; import java.time.Duration; import java.time.Instant; import java.util.HashMap; @@ -242,7 +246,16 @@ public int hashCode() { } private static String generateId() { - return UUID.randomUUID().toString(); + if(SpringHttpSessionConfiguration.secureRandomCreateEnabled){ + byte[] salt = new byte[36]; + SecureRandom secureRandom = new SecureRandom(); + secureRandom.setSeed(System.currentTimeMillis()); + secureRandom.nextBytes(salt); + return DigestUtils.md5DigestAsHex(salt); + } + else{ + return UUID.randomUUID().toString(); + } } /** diff --git a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java index eb1b97ee9..59642b82f 100644 --- a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java +++ b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java @@ -113,11 +113,24 @@ public class SpringHttpSessionConfiguration implements InitializingBean, Applica @Value("${kylin.web.session-timeout:-1}") private int sessionTimeout; + public static boolean secureRandomCreateEnabled; + @Override public void afterPropertiesSet() { this.defaultHttpSessionIdResolver.setCookieSerializer(getCookieSerializer()); } + @Value("${kylin.web.session.secure-random-create-enabled:false}") + public void setSecureRandomCreateEnabled(boolean enabled) { + secureRandomCreateEnabled = enabled; + } + + public static boolean jdbcEncodeEnable; + @Value("${kylin.web.session.jdbc-encode-enabled:false}") + public void setJdbcEncodeEnable(boolean enabled) { + jdbcEncodeEnable = enabled; + } + @Bean public SessionEventHttpSessionListenerAdapter sessionEventHttpSessionListenerAdapter() { return new SessionEventHttpSessionListenerAdapter(this.httpSessionListeners); diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java index 98b46de85..09d8b5823 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java @@ -22,6 +22,7 @@ import java.time.Duration; import java.time.Instant; import java.util.ArrayList; +import java.util.Base64; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -64,6 +65,7 @@ import org.springframework.session.Session; import org.springframework.session.SessionIdGenerator; import org.springframework.session.UuidSessionIdGenerator; +import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration; import org.springframework.transaction.support.TransactionOperations; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -885,6 +887,15 @@ private void flushIfRequired() { } } + private String getEncodeSessionId(final String sessionId){ + if(SpringHttpSessionConfiguration.jdbcEncodeEnable){ + return new String(Base64.getEncoder().encode(sessionId.getBytes())); + } + else{ + return sessionId; + } + } + private void save() { if (this.isNew) { JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> { @@ -893,7 +904,7 @@ private void save() { JdbcIndexedSessionRepository.this.jdbcOperations .update(JdbcIndexedSessionRepository.this.createSessionQuery, (ps) -> { ps.setString(1, JdbcSession.this.primaryKey); - ps.setString(2, getId()); + ps.setString(2, getEncodeSessionId(getId())); ps.setLong(3, getCreationTime().toEpochMilli()); ps.setLong(4, getLastAccessedTime().toEpochMilli()); ps.setInt(5, (int) getMaxInactiveInterval().getSeconds()); @@ -914,7 +925,7 @@ private void save() { .resolveIndexesFor(JdbcSession.this); JdbcIndexedSessionRepository.this.jdbcOperations .update(JdbcIndexedSessionRepository.this.updateSessionQuery, (ps) -> { - ps.setString(1, getId()); + ps.setString(1, getEncodeSessionId(getId())); ps.setLong(2, getLastAccessedTime().toEpochMilli()); ps.setInt(3, (int) getMaxInactiveInterval().getSeconds()); ps.setLong(4, getExpiryTime().toEpochMilli()); @@ -970,7 +981,7 @@ private class SessionResultSetExtractor implements ResultSetExtractor extractData(ResultSet rs) throws SQLException, DataAccessException { List sessions = new ArrayList<>(); while (rs.next()) { - String id = rs.getString("SESSION_ID"); + String id = getDecodeSessionId(rs.getString("SESSION_ID")); JdbcSession session; if (sessions.size() > 0 && getLast(sessions).getId().equals(id)) { session = getLast(sessions); @@ -997,6 +1008,15 @@ private JdbcSession getLast(List sessions) { return sessions.get(sessions.size() - 1); } + private String getDecodeSessionId(final String sessionId){ + if(SpringHttpSessionConfiguration.jdbcEncodeEnable){ + return new String(Base64.getDecoder().decode(sessionId.getBytes())); + } + else{ + return sessionId; + } + } + } } From 7c16a1c1538324fd8b132a5a199a4bfbcfb43614 Mon Sep 17 00:00:00 2001 From: "qiangsheng.ye" Date: Wed, 20 May 2020 17:56:12 +0800 Subject: [PATCH 04/15] KE-13728 change kylin config to spring.session.timeout --- .../annotation/web/http/SpringHttpSessionConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java index 59642b82f..5880b27ba 100644 --- a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java +++ b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java @@ -110,7 +110,7 @@ public class SpringHttpSessionConfiguration implements InitializingBean, Applica @Value("${kylin.web.session-skip-header-name:Auto}") private String skipUpdateSessionHeaderName; - @Value("${kylin.web.session-timeout:-1}") + @Value("${spring.session.timeout:-1}") private int sessionTimeout; public static boolean secureRandomCreateEnabled; From 24e7aed93451d741d8ae7d265d95f670d491ac8b Mon Sep 17 00:00:00 2001 From: zhoujiazhi <2529026882@qq.com> Date: Mon, 25 May 2020 15:57:45 +0800 Subject: [PATCH 05/15] KE-14497 catch exception for hide sql expression --- .../springframework/session/MapSession.java | 8 +- .../jdbc/JdbcIndexedSessionRepository.java | 135 +++++++++--------- 2 files changed, 74 insertions(+), 69 deletions(-) diff --git a/spring-session-core/src/main/java/org/springframework/session/MapSession.java b/spring-session-core/src/main/java/org/springframework/session/MapSession.java index 5137f9745..bb3167bdc 100644 --- a/spring-session-core/src/main/java/org/springframework/session/MapSession.java +++ b/spring-session-core/src/main/java/org/springframework/session/MapSession.java @@ -247,11 +247,13 @@ public int hashCode() { private static String generateId() { if(SpringHttpSessionConfiguration.secureRandomCreateEnabled){ - byte[] salt = new byte[36]; + byte[] salt1 = new byte[36]; + byte[] salt2 = new byte[36]; SecureRandom secureRandom = new SecureRandom(); secureRandom.setSeed(System.currentTimeMillis()); - secureRandom.nextBytes(salt); - return DigestUtils.md5DigestAsHex(salt); + secureRandom.nextBytes(salt1); + secureRandom.nextBytes(salt2); + return DigestUtils.md5DigestAsHex(salt1) + DigestUtils.md5DigestAsHex(salt2); } else{ return UUID.randomUUID().toString(); diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java index 09d8b5823..521761dfd 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java @@ -897,82 +897,85 @@ private String getEncodeSessionId(final String sessionId){ } private void save() { - if (this.isNew) { - JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> { - Map indexes = JdbcIndexedSessionRepository.this.indexResolver - .resolveIndexesFor(JdbcSession.this); - JdbcIndexedSessionRepository.this.jdbcOperations - .update(JdbcIndexedSessionRepository.this.createSessionQuery, (ps) -> { - ps.setString(1, JdbcSession.this.primaryKey); - ps.setString(2, getEncodeSessionId(getId())); - ps.setLong(3, getCreationTime().toEpochMilli()); - ps.setLong(4, getLastAccessedTime().toEpochMilli()); - ps.setInt(5, (int) getMaxInactiveInterval().getSeconds()); - ps.setLong(6, getExpiryTime().toEpochMilli()); - ps.setString(7, indexes.get(PRINCIPAL_NAME_INDEX_NAME)); - }); - Set attributeNames = getAttributeNames(); - if (!attributeNames.isEmpty()) { - insertSessionAttributes(JdbcSession.this, new ArrayList<>(attributeNames)); - } - }); - } - else { - List deltaActions = JdbcSession.this.changed ? new ArrayList<>(4) : new ArrayList<>(); - if (JdbcSession.this.changed) { - deltaActions.add(() -> { + try { + if (this.isNew) { + JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> { Map indexes = JdbcIndexedSessionRepository.this.indexResolver - .resolveIndexesFor(JdbcSession.this); + .resolveIndexesFor(JdbcSession.this); JdbcIndexedSessionRepository.this.jdbcOperations - .update(JdbcIndexedSessionRepository.this.updateSessionQuery, (ps) -> { - ps.setString(1, getEncodeSessionId(getId())); - ps.setLong(2, getLastAccessedTime().toEpochMilli()); - ps.setInt(3, (int) getMaxInactiveInterval().getSeconds()); - ps.setLong(4, getExpiryTime().toEpochMilli()); - ps.setString(5, indexes.get(PRINCIPAL_NAME_INDEX_NAME)); - ps.setString(6, JdbcSession.this.primaryKey); - }); + .update(JdbcIndexedSessionRepository.this.createSessionQuery, (ps) -> { + ps.setString(1, JdbcSession.this.primaryKey); + ps.setString(2, getEncodeSessionId(getId())); + ps.setLong(3, getCreationTime().toEpochMilli()); + ps.setLong(4, getLastAccessedTime().toEpochMilli()); + ps.setInt(5, (int) getMaxInactiveInterval().getSeconds()); + ps.setLong(6, getExpiryTime().toEpochMilli()); + ps.setString(7, indexes.get(PRINCIPAL_NAME_INDEX_NAME)); + }); + Set attributeNames = getAttributeNames(); + if (!attributeNames.isEmpty()) { + insertSessionAttributes(JdbcSession.this, new ArrayList<>(attributeNames)); + } }); - } + } else { + List deltaActions = JdbcSession.this.changed ? new ArrayList<>(4) : new ArrayList<>(); + if (JdbcSession.this.changed) { + deltaActions.add(() -> { + Map indexes = JdbcIndexedSessionRepository.this.indexResolver + .resolveIndexesFor(JdbcSession.this); + JdbcIndexedSessionRepository.this.jdbcOperations + .update(JdbcIndexedSessionRepository.this.updateSessionQuery, (ps) -> { + ps.setString(1, getEncodeSessionId(getId())); + ps.setLong(2, getLastAccessedTime().toEpochMilli()); + ps.setInt(3, (int) getMaxInactiveInterval().getSeconds()); + ps.setLong(4, getExpiryTime().toEpochMilli()); + ps.setString(5, indexes.get(PRINCIPAL_NAME_INDEX_NAME)); + ps.setString(6, JdbcSession.this.primaryKey); + }); + }); + } - List addedAttributeNames = JdbcSession.this.delta.entrySet() - .stream() - .filter((entry) -> entry.getValue() == DeltaValue.ADDED) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); - if (!addedAttributeNames.isEmpty()) { - deltaActions.add(() -> insertSessionAttributes(JdbcSession.this, addedAttributeNames)); - } + List addedAttributeNames = JdbcSession.this.delta.entrySet() + .stream() + .filter((entry) -> entry.getValue() == DeltaValue.ADDED) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + if (!addedAttributeNames.isEmpty()) { + deltaActions.add(() -> insertSessionAttributes(JdbcSession.this, addedAttributeNames)); + } - List updatedAttributeNames = JdbcSession.this.delta.entrySet() - .stream() - .filter((entry) -> entry.getValue() == DeltaValue.UPDATED) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); - if (!updatedAttributeNames.isEmpty()) { - deltaActions.add(() -> updateSessionAttributes(JdbcSession.this, updatedAttributeNames)); - } + List updatedAttributeNames = JdbcSession.this.delta.entrySet() + .stream() + .filter((entry) -> entry.getValue() == DeltaValue.UPDATED) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + if (!updatedAttributeNames.isEmpty()) { + deltaActions.add(() -> updateSessionAttributes(JdbcSession.this, updatedAttributeNames)); + } - List removedAttributeNames = JdbcSession.this.delta.entrySet() - .stream() - .filter((entry) -> entry.getValue() == DeltaValue.REMOVED) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); - if (!removedAttributeNames.isEmpty()) { - deltaActions.add(() -> deleteSessionAttributes(JdbcSession.this, removedAttributeNames)); - } + List removedAttributeNames = JdbcSession.this.delta.entrySet() + .stream() + .filter((entry) -> entry.getValue() == DeltaValue.REMOVED) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + if (!removedAttributeNames.isEmpty()) { + deltaActions.add(() -> deleteSessionAttributes(JdbcSession.this, removedAttributeNames)); + } - if (!deltaActions.isEmpty()) { - JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> { - for (Runnable action : deltaActions) { - action.run(); - } - }); + if (!deltaActions.isEmpty()) { + JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> { + for (Runnable action : deltaActions) { + action.run(); + } + }); + } } + clearChangeFlags(); + } catch (DataIntegrityViolationException e) { + logger.error(e); + throw new DataIntegrityViolationException("The data exceeds the limit of length for column ?session_id?. Please adjust its maximum value and try again."); } - clearChangeFlags(); } - } private class SessionResultSetExtractor implements ResultSetExtractor> { From 733ed9cb696e8cc877eebb29a561b0d9b582c7c3 Mon Sep 17 00:00:00 2001 From: "qiangsheng.ye" Date: Tue, 16 Jun 2020 19:06:53 +0800 Subject: [PATCH 06/15] KE_14608 add save session exception --- .../web/http/SaveSessionException.java | 37 +++++++++++++++++++ .../web/http/SessionRepositoryFilter.java | 6 ++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 spring-session-core/src/main/java/org/springframework/session/web/http/SaveSessionException.java diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/SaveSessionException.java b/spring-session-core/src/main/java/org/springframework/session/web/http/SaveSessionException.java new file mode 100644 index 000000000..edc996518 --- /dev/null +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/SaveSessionException.java @@ -0,0 +1,37 @@ +/* + * Copyright 2014-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.session.web.http; + +public class SaveSessionException extends RuntimeException { + + public SaveSessionException() { + super(); + } + + public SaveSessionException(String s) { + super(s); + } + + public SaveSessionException(String message, Throwable cause) { + super(message, cause); + } + + public SaveSessionException(Throwable cause) { + super(cause); + } + +} diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java index 05044ff84..b6a6deabc 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java @@ -243,7 +243,11 @@ private void commitSession() { S session = wrappedSession.getSession(); String requestedSessionId = getRequestedSessionId(); clearRequestedSessionCache(); - SessionRepositoryFilter.this.sessionRepository.save(session); + try { + SessionRepositoryFilter.this.sessionRepository.save(session); + } catch (Exception e) { + throw new SaveSessionException("Failed to save session!", e); + } String sessionId = session.getId(); if (!isRequestedSessionIdValid() || !sessionId.equals(requestedSessionId)) { SessionRepositoryFilter.this.httpSessionIdResolver.setSessionId(this, this.response, sessionId); From 390ec4f92bcf6c62909e30f86599c364cd1b7723 Mon Sep 17 00:00:00 2001 From: "qiangsheng.ye" Date: Thu, 22 Apr 2021 09:57:28 +0800 Subject: [PATCH 07/15] KE-25654 save session when delay half timeout. --- .../session/web/http/SessionRepositoryFilter.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java index b6a6deabc..5a4466aa2 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java @@ -244,7 +244,11 @@ private void commitSession() { String requestedSessionId = getRequestedSessionId(); clearRequestedSessionCache(); try { - SessionRepositoryFilter.this.sessionRepository.save(session); + S sourceSession = SessionRepositoryFilter.this.sessionRepository.findById(session.getId()); + if ( null == sourceSession || (System.currentTimeMillis() - + sourceSession.getLastAccessedTime().toEpochMilli()) > session.getMaxInactiveInterval().toMillis() * 500 ) { + SessionRepositoryFilter.this.sessionRepository.save(session); + } } catch (Exception e) { throw new SaveSessionException("Failed to save session!", e); } From 99f2d6e8e9fd126e590bc88a2dbc14419746a42d Mon Sep 17 00:00:00 2001 From: xifeng yang Date: Mon, 21 Feb 2022 20:23:27 +0800 Subject: [PATCH 08/15] format code --- .../springframework/session/MapSession.java | 10 ++++---- .../http/SpringHttpSessionConfiguration.java | 1 + .../web/http/SaveSessionException.java | 24 +++++++++--------- .../web/http/SessionRepositoryFilter.java | 25 +++++++++++-------- .../jdbc/JdbcIndexedSessionRepository.java | 18 +++++++------ 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/spring-session-core/src/main/java/org/springframework/session/MapSession.java b/spring-session-core/src/main/java/org/springframework/session/MapSession.java index bb3167bdc..6ca98b9c1 100644 --- a/spring-session-core/src/main/java/org/springframework/session/MapSession.java +++ b/spring-session-core/src/main/java/org/springframework/session/MapSession.java @@ -16,9 +16,6 @@ package org.springframework.session; -import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration; -import org.springframework.util.DigestUtils; - import java.io.Serializable; import java.security.SecureRandom; import java.time.Duration; @@ -29,6 +26,9 @@ import java.util.Set; import java.util.UUID; +import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration; +import org.springframework.util.DigestUtils; + /** *

* A {@link Session} implementation that is backed by a {@link java.util.Map}. The @@ -246,7 +246,7 @@ public int hashCode() { } private static String generateId() { - if(SpringHttpSessionConfiguration.secureRandomCreateEnabled){ + if (SpringHttpSessionConfiguration.secureRandomCreateEnabled) { byte[] salt1 = new byte[36]; byte[] salt2 = new byte[36]; SecureRandom secureRandom = new SecureRandom(); @@ -255,7 +255,7 @@ private static String generateId() { secureRandom.nextBytes(salt2); return DigestUtils.md5DigestAsHex(salt1) + DigestUtils.md5DigestAsHex(salt2); } - else{ + else { return UUID.randomUUID().toString(); } } diff --git a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java index 5880b27ba..016800cef 100644 --- a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java +++ b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java @@ -126,6 +126,7 @@ public void setSecureRandomCreateEnabled(boolean enabled) { } public static boolean jdbcEncodeEnable; + @Value("${kylin.web.session.jdbc-encode-enabled:false}") public void setJdbcEncodeEnable(boolean enabled) { jdbcEncodeEnable = enabled; diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/SaveSessionException.java b/spring-session-core/src/main/java/org/springframework/session/web/http/SaveSessionException.java index edc996518..81ee615a7 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/SaveSessionException.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/SaveSessionException.java @@ -18,20 +18,20 @@ public class SaveSessionException extends RuntimeException { - public SaveSessionException() { - super(); - } + public SaveSessionException() { + super(); + } - public SaveSessionException(String s) { - super(s); - } + public SaveSessionException(String s) { + super(s); + } - public SaveSessionException(String message, Throwable cause) { - super(message, cause); - } + public SaveSessionException(String message, Throwable cause) { + super(message, cause); + } - public SaveSessionException(Throwable cause) { - super(cause); - } + public SaveSessionException(Throwable cause) { + super(cause); + } } diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java index 5a4466aa2..5d4ff10a1 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java @@ -115,8 +115,8 @@ public void setSkipCommitSessionHeaderName(String skipCommitSessionHeaderName) { private int sessionTimeout = -1; public void setSessionTimeout(int sessionTimeout) { - this.sessionTimeout = sessionTimeout; - } + this.sessionTimeout = sessionTimeout; + } /** * Creates a new instance. @@ -236,7 +236,7 @@ private void commitSession() { } } else { - if (Boolean.valueOf(this.getHeader(skipCommitSessionHeaderName))) { + if (Boolean.valueOf(this.getHeader(SessionRepositoryFilter.this.skipCommitSessionHeaderName))) { return; } @@ -245,12 +245,14 @@ private void commitSession() { clearRequestedSessionCache(); try { S sourceSession = SessionRepositoryFilter.this.sessionRepository.findById(session.getId()); - if ( null == sourceSession || (System.currentTimeMillis() - - sourceSession.getLastAccessedTime().toEpochMilli()) > session.getMaxInactiveInterval().toMillis() * 500 ) { + if (null == sourceSession || (System.currentTimeMillis() + - sourceSession.getLastAccessedTime().toEpochMilli()) > session.getMaxInactiveInterval() + .toMillis() * 500) { SessionRepositoryFilter.this.sessionRepository.save(session); } - } catch (Exception e) { - throw new SaveSessionException("Failed to save session!", e); + } + catch (Exception ex) { + throw new SaveSessionException("Failed to save session!", ex); } String sessionId = session.getId(); if (!isRequestedSessionIdValid() || !sessionId.equals(requestedSessionId)) { @@ -342,11 +344,12 @@ public HttpSessionWrapper getSession(boolean create) { new RuntimeException("For debugging purposes only (not an error)")); } S session = SessionRepositoryFilter.this.sessionRepository.createSession(); - if (sessionTimeout > 60) { - session.setMaxInactiveInterval(Duration.ofSeconds(sessionTimeout)); - } else if (sessionTimeout > 0) { + if (SessionRepositoryFilter.this.sessionTimeout > 60) { + session.setMaxInactiveInterval(Duration.ofSeconds(SessionRepositoryFilter.this.sessionTimeout)); + } + else if (SessionRepositoryFilter.this.sessionTimeout > 0) { session.setMaxInactiveInterval(Duration.ofSeconds(60)); - } + } session.setLastAccessedTime(Instant.now()); currentSession = new HttpSessionWrapper(session, getServletContext()); setCurrentSession(currentSession); diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java index 521761dfd..0d33e3f28 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java @@ -887,11 +887,11 @@ private void flushIfRequired() { } } - private String getEncodeSessionId(final String sessionId){ - if(SpringHttpSessionConfiguration.jdbcEncodeEnable){ + private String getEncodeSessionId(final String sessionId) { + if (SpringHttpSessionConfiguration.jdbcEncodeEnable) { return new String(Base64.getEncoder().encode(sessionId.getBytes())); } - else{ + else { return sessionId; } } @@ -917,7 +917,8 @@ private void save() { insertSessionAttributes(JdbcSession.this, new ArrayList<>(attributeNames)); } }); - } else { + } + else { List deltaActions = JdbcSession.this.changed ? new ArrayList<>(4) : new ArrayList<>(); if (JdbcSession.this.changed) { deltaActions.add(() -> { @@ -971,7 +972,8 @@ private void save() { } } clearChangeFlags(); - } catch (DataIntegrityViolationException e) { + } + catch (DataIntegrityViolationException e) { logger.error(e); throw new DataIntegrityViolationException("The data exceeds the limit of length for column ?session_id?. Please adjust its maximum value and try again."); } @@ -1011,11 +1013,11 @@ private JdbcSession getLast(List sessions) { return sessions.get(sessions.size() - 1); } - private String getDecodeSessionId(final String sessionId){ - if(SpringHttpSessionConfiguration.jdbcEncodeEnable){ + private String getDecodeSessionId(final String sessionId) { + if (SpringHttpSessionConfiguration.jdbcEncodeEnable) { return new String(Base64.getDecoder().decode(sessionId.getBytes())); } - else{ + else { return sessionId; } } From a66c232cd6594f83607f9f40b88536c6cde5d3e5 Mon Sep 17 00:00:00 2001 From: xifeng yang Date: Tue, 22 Feb 2022 15:16:24 +0800 Subject: [PATCH 09/15] fix kylin.web.session.jdbc-encode-enabled --- .../springframework/session/MapSession.java | 12 +++++++-- .../jdbc/JdbcIndexedSessionRepository.java | 26 +++---------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/spring-session-core/src/main/java/org/springframework/session/MapSession.java b/spring-session-core/src/main/java/org/springframework/session/MapSession.java index 6ca98b9c1..cfb348698 100644 --- a/spring-session-core/src/main/java/org/springframework/session/MapSession.java +++ b/spring-session-core/src/main/java/org/springframework/session/MapSession.java @@ -20,6 +20,7 @@ import java.security.SecureRandom; import java.time.Duration; import java.time.Instant; +import java.util.Base64; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -246,6 +247,7 @@ public int hashCode() { } private static String generateId() { + String id; if (SpringHttpSessionConfiguration.secureRandomCreateEnabled) { byte[] salt1 = new byte[36]; byte[] salt2 = new byte[36]; @@ -253,11 +255,17 @@ private static String generateId() { secureRandom.setSeed(System.currentTimeMillis()); secureRandom.nextBytes(salt1); secureRandom.nextBytes(salt2); - return DigestUtils.md5DigestAsHex(salt1) + DigestUtils.md5DigestAsHex(salt2); + id = DigestUtils.md5DigestAsHex(salt1) + DigestUtils.md5DigestAsHex(salt2); } else { - return UUID.randomUUID().toString(); + id = UUID.randomUUID().toString(); } + + if (SpringHttpSessionConfiguration.jdbcEncodeEnable) { + return new String(Base64.getEncoder().encode(id.getBytes())); + } + + return id; } /** diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java index 0d33e3f28..1cd25680a 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java @@ -22,7 +22,6 @@ import java.time.Duration; import java.time.Instant; import java.util.ArrayList; -import java.util.Base64; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -65,7 +64,6 @@ import org.springframework.session.Session; import org.springframework.session.SessionIdGenerator; import org.springframework.session.UuidSessionIdGenerator; -import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration; import org.springframework.transaction.support.TransactionOperations; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -887,15 +885,6 @@ private void flushIfRequired() { } } - private String getEncodeSessionId(final String sessionId) { - if (SpringHttpSessionConfiguration.jdbcEncodeEnable) { - return new String(Base64.getEncoder().encode(sessionId.getBytes())); - } - else { - return sessionId; - } - } - private void save() { try { if (this.isNew) { @@ -905,7 +894,7 @@ private void save() { JdbcIndexedSessionRepository.this.jdbcOperations .update(JdbcIndexedSessionRepository.this.createSessionQuery, (ps) -> { ps.setString(1, JdbcSession.this.primaryKey); - ps.setString(2, getEncodeSessionId(getId())); + ps.setString(2, getId()); ps.setLong(3, getCreationTime().toEpochMilli()); ps.setLong(4, getLastAccessedTime().toEpochMilli()); ps.setInt(5, (int) getMaxInactiveInterval().getSeconds()); @@ -926,7 +915,7 @@ private void save() { .resolveIndexesFor(JdbcSession.this); JdbcIndexedSessionRepository.this.jdbcOperations .update(JdbcIndexedSessionRepository.this.updateSessionQuery, (ps) -> { - ps.setString(1, getEncodeSessionId(getId())); + ps.setString(1, getId()); ps.setLong(2, getLastAccessedTime().toEpochMilli()); ps.setInt(3, (int) getMaxInactiveInterval().getSeconds()); ps.setLong(4, getExpiryTime().toEpochMilli()); @@ -986,7 +975,7 @@ private class SessionResultSetExtractor implements ResultSetExtractor extractData(ResultSet rs) throws SQLException, DataAccessException { List sessions = new ArrayList<>(); while (rs.next()) { - String id = getDecodeSessionId(rs.getString("SESSION_ID")); + String id = rs.getString("SESSION_ID"); JdbcSession session; if (sessions.size() > 0 && getLast(sessions).getId().equals(id)) { session = getLast(sessions); @@ -1013,15 +1002,6 @@ private JdbcSession getLast(List sessions) { return sessions.get(sessions.size() - 1); } - private String getDecodeSessionId(final String sessionId) { - if (SpringHttpSessionConfiguration.jdbcEncodeEnable) { - return new String(Base64.getDecoder().decode(sessionId.getBytes())); - } - else { - return sessionId; - } - } - } } From a349b35f46153eb419ebeb1a01b1a0c3a9a2cb6b Mon Sep 17 00:00:00 2001 From: xifeng yang Date: Mon, 21 Feb 2022 20:16:08 +0800 Subject: [PATCH 10/15] add plugin maven-publish, upgrade version to 2.6.1-kylin-r1 --- build.gradle | 19 +++++++++++++++++++ gradle.properties | 2 +- .../spring-session-core.gradle | 16 ---------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 782fcd722..3ec96c70c 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ buildscript { plugins { id "com.github.ben-manes.versions" + id 'maven-publish' } apply plugin: 'io.spring.convention.root' @@ -66,3 +67,21 @@ springRelease { apiDocUrl = "https://docs.spring.io/spring-session/reference/{version}/api/java/index.html" replaceSnapshotVersionInReferenceDocUrl = true } + + +configure(subprojects) {project -> { + apply plugin: 'maven-publish' + + publishing { + repositories { + maven { + url = release_url + name = 'kyligence' + credentials { + username 'admin' + password 'Kyligence@2016' + } + } + } + } +}} diff --git a/gradle.properties b/gradle.properties index 4036c52c6..ef41d4599 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.parallel=true -version=3.5.6 +version=3.5.6-kylin-r1 group_id=org.springframework.session artifact_id=spring-session-core diff --git a/spring-session-core/spring-session-core.gradle b/spring-session-core/spring-session-core.gradle index 257f39107..4e7f9b7c8 100644 --- a/spring-session-core/spring-session-core.gradle +++ b/spring-session-core/spring-session-core.gradle @@ -31,19 +31,3 @@ dependencies { testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine" testRuntimeOnly "org.junit.platform:junit-platform-launcher" } - - -apply plugin: 'maven' - -uploadArchives { - repositories { - mavenDeployer { - repository(url: release_url) { - authentication(userName: "admin", password: "Kyligence@2016") - } - pom.version = version - pom.artifactId = artifact_id - pom.groupId = group_id - } - } -} From e5475688f4bc655345eeb1f3e7069473374c0d5d Mon Sep 17 00:00:00 2001 From: xifeng yang Date: Tue, 8 Mar 2022 17:38:51 +0800 Subject: [PATCH 11/15] KE-35014 fix refresh session last expire time --- .../session/web/http/SessionRepositoryFilter.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java index 5d4ff10a1..ab5eeffe7 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java @@ -245,11 +245,17 @@ private void commitSession() { clearRequestedSessionCache(); try { S sourceSession = SessionRepositoryFilter.this.sessionRepository.findById(session.getId()); - if (null == sourceSession || (System.currentTimeMillis() - - sourceSession.getLastAccessedTime().toEpochMilli()) > session.getMaxInactiveInterval() - .toMillis() * 500) { + + if (null == sourceSession) { SessionRepositoryFilter.this.sessionRepository.save(session); } + else { + long halfExpireMillis = sourceSession.getLastAccessedTime().toEpochMilli() + + session.getMaxInactiveInterval().toMillis() / 2; + if (System.currentTimeMillis() > halfExpireMillis) { + SessionRepositoryFilter.this.sessionRepository.save(session); + } + } } catch (Exception ex) { throw new SaveSessionException("Failed to save session!", ex); From fcc736e69b2178caf45ce41ba2f4b22b528c1e22 Mon Sep 17 00:00:00 2001 From: "binbin.zheng" Date: Fri, 29 Jul 2022 10:15:26 +0800 Subject: [PATCH 12/15] KE-37642 support session_attributes's foreign key constraint is removed --- .../jdbc/JdbcIndexedSessionRepository.java | 54 +++++++++++++++++-- .../JdbcIndexedSessionRepositoryTests.java | 30 +++++++++-- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java index 1cd25680a..c55cf0123 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java @@ -207,6 +207,25 @@ public class JdbcIndexedSessionRepository implements WHERE EXPIRY_TIME < ? """; + // @formatter:off + private static final String DELETE_SESSION_ATTRIBUTE_BY_SESSION_ID_QUERY = "" + + "DELETE FROM %TABLE_NAME%_ATTRIBUTES " + + "WHERE SESSION_PRIMARY_ID in (" + + " SELECT PRIMARY_ID FROM %TABLE_NAME%" + + " WHERE SESSION_ID = ? " + + " AND MAX_INACTIVE_INTERVAL >= 0" + + ")"; + // @formatter:on + + // @formatter:off + private static final String DELETE_SESSION_ATTRIBUTE_BY_EXPIRY_TIME_QUERY = "" + + "DELETE FROM %TABLE_NAME%_ATTRIBUTES " + + "WHERE SESSION_PRIMARY_ID in (" + + " SELECT PRIMARY_ID FROM %TABLE_NAME%" + + " WHERE EXPIRY_TIME < ?" + + ")"; + // @formatter:on + private static final Log logger = LogFactory.getLog(JdbcIndexedSessionRepository.class); private final JdbcOperations jdbcOperations; @@ -240,6 +259,10 @@ public class JdbcIndexedSessionRepository implements private Duration defaultMaxInactiveInterval = Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS); + private String deleteSessionAttributeBySessionIdQuery; + + private String deleteSessionAttributeByExpiryTimeQuery; + private IndexResolver indexResolver = new DelegatingIndexResolver<>(new PrincipalNameIndexResolver<>()); private ConversionService conversionService = createDefaultConversionService(); @@ -383,6 +406,16 @@ public void setDeleteSessionsByExpiryTimeQuery(String deleteSessionsByExpiryTime this.deleteSessionsByExpiryTimeQuery = getQuery(deleteSessionsByExpiryTimeQuery); } + public void setDeleteSessionAttributeBySessionIdQuery(String deleteSessionAttributeBySessionIdQuery) { + Assert.hasText(deleteSessionAttributeBySessionIdQuery, "Query must not be empty"); + this.deleteSessionAttributeBySessionIdQuery = getQuery(deleteSessionAttributeBySessionIdQuery); + } + + public void setDeleteSessionAttributeByExpiryTimeQuery(String deleteSessionAttributeByExpiryTimeQuery) { + Assert.hasText(deleteSessionAttributeByExpiryTimeQuery, "Query must not be empty"); + this.deleteSessionAttributeByExpiryTimeQuery = getQuery(deleteSessionAttributeByExpiryTimeQuery); + } + /** * Set the maximum inactive interval in seconds between requests before newly created * sessions will be invalidated. A negative time indicates that the session will never @@ -502,8 +535,12 @@ public JdbcSession findById(final String id) { @Override public void deleteById(final String id) { - this.transactionOperations.executeWithoutResult((status) -> JdbcIndexedSessionRepository.this.jdbcOperations - .update(JdbcIndexedSessionRepository.this.deleteSessionQuery, id)); + this.transactionOperations.executeWithoutResult((status) -> { + JdbcIndexedSessionRepository.this.jdbcOperations + .update(JdbcIndexedSessionRepository.this.deleteSessionAttributeBySessionIdQuery, id); + JdbcIndexedSessionRepository.this.jdbcOperations + .update(JdbcIndexedSessionRepository.this.deleteSessionQuery, id); + }); } @Override @@ -645,9 +682,13 @@ public int getBatchSize() { public void cleanUpExpiredSessions() { Integer deletedCount = this.transactionOperations - .execute((status) -> JdbcIndexedSessionRepository.this.jdbcOperations - .update(JdbcIndexedSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis())); - + .execute((status) -> { + long currentTimeMillis = System.currentTimeMillis(); + JdbcIndexedSessionRepository.this.jdbcOperations.update( + JdbcIndexedSessionRepository.this.deleteSessionAttributeByExpiryTimeQuery, currentTimeMillis); + return JdbcIndexedSessionRepository.this.jdbcOperations + .update(JdbcIndexedSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis()); + }); if (logger.isDebugEnabled()) { logger.debug("Cleaned up " + deletedCount + " expired sessions"); } @@ -674,6 +715,9 @@ private void prepareQueries() { this.deleteSessionQuery = getQuery(DELETE_SESSION_QUERY); this.listSessionsByPrincipalNameQuery = getQuery(LIST_SESSIONS_BY_PRINCIPAL_NAME_QUERY); this.deleteSessionsByExpiryTimeQuery = getQuery(DELETE_SESSIONS_BY_EXPIRY_TIME_QUERY); + this.deleteSessionAttributeBySessionIdQuery = getQuery(DELETE_SESSION_ATTRIBUTE_BY_SESSION_ID_QUERY); + this.deleteSessionAttributeByExpiryTimeQuery = getQuery(DELETE_SESSION_ATTRIBUTE_BY_EXPIRY_TIME_QUERY); + } private LobHandler getLobHandler() { diff --git a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java index 341b5e350..b9db06b0d 100644 --- a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java +++ b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java @@ -239,6 +239,30 @@ void setDeleteSessionsByLastAccessTimeQueryEmpty() { .withMessage("Query must not be empty"); } + @Test + void setDeleteSessionAttributeBySessionIdQueryNull() { + assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeBySessionIdQuery(null)) + .withMessage("Query must not be empty"); + } + + @Test + void setDeleteSessionAttributeBySessionIdQueryEmpty() { + assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeBySessionIdQuery(" ")) + .withMessage("Query must not be empty"); + } + + @Test + void setDeleteSessionAttributeByExpiryTimeQueryNull() { + assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeByExpiryTimeQuery(null)) + .withMessage("Query must not be empty"); + } + + @Test + void setDeleteSessionAttributeByExpiryTimeQueryEmpty() { + assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeByExpiryTimeQuery(" ")) + .withMessage("Query must not be empty"); + } + @Test void setLobHandlerNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setLobHandler(null)) @@ -573,7 +597,7 @@ void getSessionExpired() { assertThat(session).isNull(); verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class), isA(ResultSetExtractor.class)); - verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), eq(expired.getId())); + verify(this.jdbcOperations, times(2)).update(startsWith("DELETE"), eq(expired.getId())); } @Test @@ -600,7 +624,7 @@ void delete() { this.repository.deleteById(sessionId); - verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), eq(sessionId)); + verify(this.jdbcOperations, times(2)).update(startsWith("DELETE"), eq(sessionId)); } @Test @@ -658,7 +682,7 @@ void findByIndexNameAndIndexValuePrincipalIndexNameFound() { void cleanupExpiredSessions() { this.repository.cleanUpExpiredSessions(); - verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), anyLong()); + verify(this.jdbcOperations, times(2)).update(startsWith("DELETE"), anyLong()); } @Test // gh-1120 From 9b44c8e33e6e228b38094c34596be33c4dced788 Mon Sep 17 00:00:00 2001 From: "binbin.zheng" Date: Tue, 2 Aug 2022 18:31:14 +0800 Subject: [PATCH 13/15] modify repo address and code format --- build.gradle | 4 ++-- gradle.properties | 2 +- .../jdbc/JdbcIndexedSessionRepository.java | 16 ++++++++-------- .../jdbc/JdbcIndexedSessionRepositoryTests.java | 12 ++++++++---- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 3ec96c70c..6a6b526f6 100644 --- a/build.gradle +++ b/build.gradle @@ -78,8 +78,8 @@ configure(subprojects) {project -> { url = release_url name = 'kyligence' credentials { - username 'admin' - password 'Kyligence@2016' + username 'kyligence' + password 'Kyligence@2022' } } } diff --git a/gradle.properties b/gradle.properties index ef41d4599..ce0504de8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,4 @@ version=3.5.6-kylin-r1 group_id=org.springframework.session artifact_id=spring-session-core -release_url=https://repository.kyligence.io/repository/maven-releases/ +release_url=https://repo-ofs.kyligence.com/repository/maven-releases/ diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java index c55cf0123..59e50cda3 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java @@ -681,14 +681,14 @@ public int getBatchSize() { } public void cleanUpExpiredSessions() { - Integer deletedCount = this.transactionOperations - .execute((status) -> { - long currentTimeMillis = System.currentTimeMillis(); - JdbcIndexedSessionRepository.this.jdbcOperations.update( - JdbcIndexedSessionRepository.this.deleteSessionAttributeByExpiryTimeQuery, currentTimeMillis); - return JdbcIndexedSessionRepository.this.jdbcOperations - .update(JdbcIndexedSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis()); - }); + Integer deletedCount = this.transactionOperations.execute((status) -> { + long currentTimeMillis = System.currentTimeMillis(); + JdbcIndexedSessionRepository.this.jdbcOperations.update( + JdbcIndexedSessionRepository.this.deleteSessionAttributeByExpiryTimeQuery, currentTimeMillis); + return JdbcIndexedSessionRepository.this.jdbcOperations + .update(JdbcIndexedSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis()); + }); + if (logger.isDebugEnabled()) { logger.debug("Cleaned up " + deletedCount + " expired sessions"); } diff --git a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java index b9db06b0d..27e34b6e0 100644 --- a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java +++ b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java @@ -241,25 +241,29 @@ void setDeleteSessionsByLastAccessTimeQueryEmpty() { @Test void setDeleteSessionAttributeBySessionIdQueryNull() { - assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeBySessionIdQuery(null)) + assertThatIllegalArgumentException() + .isThrownBy(() -> this.repository.setDeleteSessionAttributeBySessionIdQuery(null)) .withMessage("Query must not be empty"); } @Test void setDeleteSessionAttributeBySessionIdQueryEmpty() { - assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeBySessionIdQuery(" ")) + assertThatIllegalArgumentException() + .isThrownBy(() -> this.repository.setDeleteSessionAttributeBySessionIdQuery(" ")) .withMessage("Query must not be empty"); } @Test void setDeleteSessionAttributeByExpiryTimeQueryNull() { - assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeByExpiryTimeQuery(null)) + assertThatIllegalArgumentException() + .isThrownBy(() -> this.repository.setDeleteSessionAttributeByExpiryTimeQuery(null)) .withMessage("Query must not be empty"); } @Test void setDeleteSessionAttributeByExpiryTimeQueryEmpty() { - assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeByExpiryTimeQuery(" ")) + assertThatIllegalArgumentException() + .isThrownBy(() -> this.repository.setDeleteSessionAttributeByExpiryTimeQuery(" ")) .withMessage("Query must not be empty"); } From 387cfa8e2606726cf8e1aa7bdea2ff6b9d7f39d4 Mon Sep 17 00:00:00 2001 From: "binbin.zheng" Date: Fri, 25 Nov 2022 18:41:03 +0800 Subject: [PATCH 14/15] KE-40314 remove username and password --- build.gradle | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 6a6b526f6..f89588b9f 100644 --- a/build.gradle +++ b/build.gradle @@ -77,10 +77,12 @@ configure(subprojects) {project -> { maven { url = release_url name = 'kyligence' - credentials { - username 'kyligence' - password 'Kyligence@2022' - } + if (project.hasProperty('kyligenceRepoUsername')) { + credentials { + username "$kyligenceRepoUsername" + password "$kyligenceRepoPassword" + } + } } } } From 4e4e4ad311e0b9a96f446623b9e699ff2e276be0 Mon Sep 17 00:00:00 2001 From: Xuecheng Shan Date: Mon, 11 May 2026 17:03:46 +0800 Subject: [PATCH 15/15] KE45061 set version for kylin --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ce0504de8..e890893f2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.parallel=true -version=3.5.6-kylin-r1 +version=3.5.6-kylin-r1-SNAPSHOT group_id=org.springframework.session artifact_id=spring-session-core