mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-05-29 21:32:01 +00:00
rename anonymus to anonymous
This commit is contained in:
parent
fa8df329df
commit
1fb4a40edf
@ -66,7 +66,7 @@ sourceSets {
|
|||||||
exclude "stirling/software/SPDF/model/User.java"
|
exclude "stirling/software/SPDF/model/User.java"
|
||||||
exclude "stirling/software/SPDF/repository/**"
|
exclude "stirling/software/SPDF/repository/**"
|
||||||
} else {
|
} else {
|
||||||
exclude "stirling/software/SPDF/config/anonymus/**"
|
exclude "stirling/software/SPDF/config/anonymous/**"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (System.getenv("STIRLING_PDF_DESKTOP_UI") == "false") {
|
if (System.getenv("STIRLING_PDF_DESKTOP_UI") == "false") {
|
||||||
@ -534,6 +534,7 @@ dependencies {
|
|||||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||||
|
|
||||||
testRuntimeOnly 'org.mockito:mockito-inline:5.2.0'
|
testRuntimeOnly 'org.mockito:mockito-inline:5.2.0'
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
@ -33,10 +33,7 @@ public class EndpointInterceptor implements HandlerInterceptor {
|
|||||||
public boolean preHandle(
|
public boolean preHandle(
|
||||||
HttpServletRequest request, HttpServletResponse response, Object handler)
|
HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
HttpSession session = request.getSession(false);
|
HttpSession session = request.getSession(true);
|
||||||
if (session == null) {
|
|
||||||
session = request.getSession(true);
|
|
||||||
}
|
|
||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
|
|
||||||
boolean isApiRequest = requestURI.contains("/api/v1");
|
boolean isApiRequest = requestURI.contains("/api/v1");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config.anonymus.session;
|
package stirling.software.SPDF.config.anonymous.session;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ import stirling.software.SPDF.config.interfaces.SessionsModelInterface;
|
|||||||
@ToString(exclude = "session") // exclude session from toString to avoid verbose output or sensitive
|
@ToString(exclude = "session") // exclude session from toString to avoid verbose output or sensitive
|
||||||
// data
|
// data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class AnonymusSessionInfo implements SessionsModelInterface {
|
public class AnonymousSessionInfo implements SessionsModelInterface {
|
||||||
private static final String principalName = "anonymousUser";
|
private static final String principalName = "anonymousUser";
|
||||||
private HttpSession session;
|
private HttpSession session;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config.anonymus.session;
|
package stirling.software.SPDF.config.anonymous.session;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@ -22,7 +22,7 @@ import stirling.software.SPDF.config.interfaces.SessionsModelInterface;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AnonymusSessionListener implements HttpSessionListener, SessionsInterface {
|
public class AnonymousSessionListener implements HttpSessionListener, SessionsInterface {
|
||||||
|
|
||||||
@Value("${server.servlet.session.timeout:30m}")
|
@Value("${server.servlet.session.timeout:30m}")
|
||||||
private Duration defaultMaxInactiveInterval;
|
private Duration defaultMaxInactiveInterval;
|
||||||
@ -49,11 +49,11 @@ public class AnonymusSessionListener implements HttpSessionListener, SessionsInt
|
|||||||
if (allNonExpiredSessions >= getMaxUserSessions()) {
|
if (allNonExpiredSessions >= getMaxUserSessions()) {
|
||||||
sessions.put(
|
sessions.put(
|
||||||
session.getId(),
|
session.getId(),
|
||||||
new AnonymusSessionInfo(session, creationTime, creationTime, true));
|
new AnonymousSessionInfo(session, creationTime, creationTime, true));
|
||||||
} else {
|
} else {
|
||||||
sessions.put(
|
sessions.put(
|
||||||
session.getId(),
|
session.getId(),
|
||||||
new AnonymusSessionInfo(session, creationTime, creationTime, false));
|
new AnonymousSessionInfo(session, creationTime, creationTime, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public class AnonymusSessionListener implements HttpSessionListener, SessionsInt
|
|||||||
if (session == null) {
|
if (session == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AnonymusSessionInfo sessionsInfo = (AnonymusSessionInfo) sessions.get(session.getId());
|
AnonymousSessionInfo sessionsInfo = (AnonymousSessionInfo) sessions.get(session.getId());
|
||||||
if (sessionsInfo == null) {
|
if (sessionsInfo == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ public class AnonymusSessionListener implements HttpSessionListener, SessionsInt
|
|||||||
// Mark a single session as expired
|
// Mark a single session as expired
|
||||||
public void expireSession(String sessionId) {
|
public void expireSession(String sessionId) {
|
||||||
if (sessions.containsKey(sessionId)) {
|
if (sessions.containsKey(sessionId)) {
|
||||||
AnonymusSessionInfo sessionInfo = (AnonymusSessionInfo) sessions.get(sessionId);
|
AnonymousSessionInfo sessionInfo = (AnonymousSessionInfo) sessions.get(sessionId);
|
||||||
sessionInfo.setExpired(true);
|
sessionInfo.setExpired(true);
|
||||||
try {
|
try {
|
||||||
sessionInfo.getSession().invalidate();
|
sessionInfo.getSession().invalidate();
|
||||||
@ -103,7 +103,7 @@ public class AnonymusSessionListener implements HttpSessionListener, SessionsInt
|
|||||||
.findFirst()
|
.findFirst()
|
||||||
.ifPresent(
|
.ifPresent(
|
||||||
session -> {
|
session -> {
|
||||||
AnonymusSessionInfo sessionInfo = (AnonymusSessionInfo) session;
|
AnonymousSessionInfo sessionInfo = (AnonymousSessionInfo) session;
|
||||||
sessionInfo.setExpired(true);
|
sessionInfo.setExpired(true);
|
||||||
try {
|
try {
|
||||||
log.info(
|
log.info(
|
||||||
@ -122,7 +122,7 @@ public class AnonymusSessionListener implements HttpSessionListener, SessionsInt
|
|||||||
sessions.values()
|
sessions.values()
|
||||||
.forEach(
|
.forEach(
|
||||||
sessionInfo -> {
|
sessionInfo -> {
|
||||||
AnonymusSessionInfo info = (AnonymusSessionInfo) sessionInfo;
|
AnonymousSessionInfo info = (AnonymousSessionInfo) sessionInfo;
|
||||||
info.setExpired(true);
|
info.setExpired(true);
|
||||||
HttpSession session = info.getSession();
|
HttpSession session = info.getSession();
|
||||||
try {
|
try {
|
||||||
@ -138,12 +138,12 @@ public class AnonymusSessionListener implements HttpSessionListener, SessionsInt
|
|||||||
sessions.values().stream()
|
sessions.values().stream()
|
||||||
.filter(
|
.filter(
|
||||||
sessionInfo -> {
|
sessionInfo -> {
|
||||||
AnonymusSessionInfo info = (AnonymusSessionInfo) sessionInfo;
|
AnonymousSessionInfo info = (AnonymousSessionInfo) sessionInfo;
|
||||||
return info.getPrincipalName().equals(username);
|
return info.getPrincipalName().equals(username);
|
||||||
})
|
})
|
||||||
.forEach(
|
.forEach(
|
||||||
sessionInfo -> {
|
sessionInfo -> {
|
||||||
AnonymusSessionInfo info = (AnonymusSessionInfo) sessionInfo;
|
AnonymousSessionInfo info = (AnonymousSessionInfo) sessionInfo;
|
||||||
info.setExpired(true);
|
info.setExpired(true);
|
||||||
HttpSession session = info.getSession();
|
HttpSession session = info.getSession();
|
||||||
try {
|
try {
|
||||||
@ -157,7 +157,7 @@ public class AnonymusSessionListener implements HttpSessionListener, SessionsInt
|
|||||||
@Override
|
@Override
|
||||||
public void updateSessionLastRequest(String sessionId) {
|
public void updateSessionLastRequest(String sessionId) {
|
||||||
if (sessions.containsKey(sessionId)) {
|
if (sessions.containsKey(sessionId)) {
|
||||||
AnonymusSessionInfo sessionInfo = (AnonymusSessionInfo) sessions.get(sessionId);
|
AnonymousSessionInfo sessionInfo = (AnonymousSessionInfo) sessions.get(sessionId);
|
||||||
sessionInfo.setLastRequest(new Date());
|
sessionInfo.setLastRequest(new Date());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,8 +183,8 @@ public class AnonymusSessionListener implements HttpSessionListener, SessionsInt
|
|||||||
@Override
|
@Override
|
||||||
public void registerSession(HttpSession session) {
|
public void registerSession(HttpSession session) {
|
||||||
if (!sessions.containsKey(session.getId())) {
|
if (!sessions.containsKey(session.getId())) {
|
||||||
AnonymusSessionInfo sessionInfo =
|
AnonymousSessionInfo sessionInfo =
|
||||||
new AnonymusSessionInfo(session, new Date(), new Date(), false);
|
new AnonymousSessionInfo(session, new Date(), new Date(), false);
|
||||||
sessions.put(session.getId(), sessionInfo);
|
sessions.put(session.getId(), sessionInfo);
|
||||||
log.debug("Session {} registered", session.getId());
|
log.debug("Session {} registered", session.getId());
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ public class AnonymusSessionListener implements HttpSessionListener, SessionsInt
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeSession(HttpSession session) {
|
public void removeSession(HttpSession session) {
|
||||||
AnonymusSessionInfo sessionsInfo = (AnonymusSessionInfo) sessions.get(session.getId());
|
AnonymousSessionInfo sessionsInfo = (AnonymousSessionInfo) sessions.get(session.getId());
|
||||||
if (sessionsInfo != null) {
|
if (sessionsInfo != null) {
|
||||||
sessionsInfo.setExpired(true);
|
sessionsInfo.setExpired(true);
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config.anonymus.session;
|
package stirling.software.SPDF.config.anonymous.session;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@ -14,9 +14,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class AnonymusSessionService {
|
public class AnonymousSessionService {
|
||||||
|
|
||||||
@Autowired private AnonymusSessionListener sessionRegistry;
|
@Autowired private AnonymousSessionListener sessionRegistry;
|
||||||
|
|
||||||
@Value("${server.servlet.session.timeout:30m}")
|
@Value("${server.servlet.session.timeout:30m}")
|
||||||
private Duration defaultMaxInactiveInterval;
|
private Duration defaultMaxInactiveInterval;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config.anonymus.session;
|
package stirling.software.SPDF.config.anonymous.session;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -17,21 +17,14 @@ import stirling.software.SPDF.config.interfaces.SessionsModelInterface;
|
|||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AnonymusSessionStatusController {
|
public class AnonymousSessionStatusController {
|
||||||
|
|
||||||
@Autowired private AnonymusSessionListener sessionRegistry;
|
@Autowired private AnonymousSessionListener sessionRegistry;
|
||||||
|
|
||||||
@GetMapping("/userSession")
|
@GetMapping("/userSession")
|
||||||
public String getUserSessions(HttpServletRequest request, Model model) {
|
public String getUserSessions(HttpServletRequest request, Model model) {
|
||||||
HttpSession session = request.getSession(false);
|
HttpSession session = request.getSession(false);
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
|
|
||||||
boolean isSessionValid =
|
|
||||||
sessionRegistry.getAllNonExpiredSessions().stream()
|
|
||||||
.allMatch(
|
|
||||||
sessionEntity ->
|
|
||||||
sessionEntity.getSessionId().equals(session.getId()));
|
|
||||||
|
|
||||||
// Get all sessions for the user
|
// Get all sessions for the user
|
||||||
List<SessionsModelInterface> sessionList =
|
List<SessionsModelInterface> sessionList =
|
||||||
sessionRegistry.getAllNonExpiredSessions().stream()
|
sessionRegistry.getAllNonExpiredSessions().stream()
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config.anonymus.session;
|
package stirling.software.SPDF.config.security.session;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -17,10 +17,7 @@ import jakarta.servlet.http.HttpSession;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.config.interfaces.SessionsInterface;
|
|
||||||
import stirling.software.SPDF.config.security.UserUtils;
|
import stirling.software.SPDF.config.security.UserUtils;
|
||||||
import stirling.software.SPDF.config.security.session.CustomHttpSessionListener;
|
|
||||||
import stirling.software.SPDF.config.security.session.SessionPersistentRegistry;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -30,7 +27,6 @@ public class SessionStatusController {
|
|||||||
private boolean loginEnabled;
|
private boolean loginEnabled;
|
||||||
|
|
||||||
@Autowired private SessionPersistentRegistry sessionPersistentRegistry;
|
@Autowired private SessionPersistentRegistry sessionPersistentRegistry;
|
||||||
@Autowired private SessionsInterface sessionInterface;
|
|
||||||
|
|
||||||
@Autowired private CustomHttpSessionListener customHttpSessionListener;
|
@Autowired private CustomHttpSessionListener customHttpSessionListener;
|
||||||
|
|
||||||
|
@ -294,7 +294,7 @@ session.refreshPage=Refresh Page
|
|||||||
userSession.title=User Sessions
|
userSession.title=User Sessions
|
||||||
userSession.header=User Sessions
|
userSession.header=User Sessions
|
||||||
userSession.maxUserSession=If the maximum number of sessions for this user is reached, you can end other logins here to continue on this device.
|
userSession.maxUserSession=If the maximum number of sessions for this user is reached, you can end other logins here to continue on this device.
|
||||||
userSession.lastRequest=last Request
|
userSession.lastRequest=Last Request
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# HOME-PAGE #
|
# HOME-PAGE #
|
||||||
|
Loading…
x
Reference in New Issue
Block a user