Skip to content

Commit

Permalink
Bug #13604: a dedicated OneShotSessionInfo has been implemented into …
Browse files Browse the repository at this point in the history
…the aim to not create an HTTP session in a such case of access.
  • Loading branch information
SilverYoCha committed Jun 28, 2023
1 parent 28e873b commit 9e81e28
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2000 - 2022 Silverpeas
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* As a special exception to the terms and conditions of version 3.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* Open Source Software ("FLOSS") applications as described in Silverpeas's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* "https://www.silverpeas.org/legal/floss_exception.html"
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.silverpeas.core.web.session;

import org.silverpeas.core.admin.user.model.User;
import org.silverpeas.core.security.session.SessionInfo;

import java.util.UUID;

/**
* A Silverpeas user session built dedicated for one shot requests.
* <p>
* No HTTP session is created into this context.
* </p>
* <p>
* The session identifier is built on object instantiation. It is composed of
* '{@literal oneshot-}' prefix and an UUID.
* </p>
*/
public class OneShotSessionInfo extends SessionInfo {

/**
* Constructs a new {@link SessionInfo} object from the data.
* @param ip the remote user host address IP.
* @param ud the detail about the connected user.
*/
OneShotSessionInfo(String ip, User ud) {
super("oneshot-" + UUID.randomUUID(), ud);
setIPAddress(ip);
setAsOneShot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public void execute(JobExecutionContext context) {

@Override
public SessionInfo openSession(User user, HttpServletRequest request) {
SessionInfo si = createUserSessionInfo(user, request);
SessionInfo si = createUserSessionInfo(user, request, false);
try {
registerSession(si);
} catch (Exception ex) {
Expand All @@ -523,9 +523,7 @@ public SessionInfo openSession(User user, HttpServletRequest request) {

@Override
public SessionInfo openOneShotSession(final User user, final HttpServletRequest request) {
SessionInfo sessionInfo = createUserSessionInfo(user, request);
sessionInfo.setAsOneShot();
return sessionInfo;
return createUserSessionInfo(user, request, true);
}

@Override
Expand Down Expand Up @@ -554,7 +552,8 @@ private void registerSession(SessionInfo sessionInfo) {
}

@Nonnull
private SessionInfo createUserSessionInfo(final User user, final HttpServletRequest request) {
private SessionInfo createUserSessionInfo(final User user, final HttpServletRequest request,
final boolean isOneShot) {
if (user.isAnonymous()) {
throw new IllegalArgumentException("Connection with anonymous access is invoked here!");
}
Expand All @@ -573,6 +572,9 @@ private SessionInfo createUserSessionInfo(final User user, final HttpServletRequ
anIP = requestRemoteHost;
}

if (isOneShot) {
return new OneShotSessionInfo(anIP, user);
}
HttpSession session = request.getSession();
return new HTTPSessionInfo(session, anIP, user);
}
Expand Down

0 comments on commit 9e81e28

Please sign in to comment.