mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-02 18:45:21 +00:00
Fixing logout
This commit is contained in:
parent
9d162abc8c
commit
177861ce09
@ -304,8 +304,8 @@ public class ApplicationProperties {
|
|||||||
private boolean enableKeystore = true;
|
private boolean enableKeystore = true;
|
||||||
private boolean enableKeyRotation = false;
|
private boolean enableKeyRotation = false;
|
||||||
private boolean enableKeyCleanup = true;
|
private boolean enableKeyCleanup = true;
|
||||||
private int keyRetentionDays;
|
private int keyRetentionDays = 7;
|
||||||
private int cleanupBatchSize;
|
private int cleanupBatchSize = 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,10 +61,10 @@ security:
|
|||||||
spCert: classpath:certificate.crt # Your signing certificate. Generated from your keypair
|
spCert: classpath:certificate.crt # Your signing certificate. Generated from your keypair
|
||||||
jwt:
|
jwt:
|
||||||
enableKeyStore: true # Set to 'true' to enable JWT key store
|
enableKeyStore: true # Set to 'true' to enable JWT key store
|
||||||
enableKeyRotation: true # Set to 'true' to enable JWT key rotation
|
enableKeyRotation: false # Set to 'true' to enable JWT key rotation
|
||||||
enableKeyCleanup: true # Set to 'true' to enable JWT key cleanup
|
enableKeyCleanup: true # Set to 'true' to enable JWT key cleanup
|
||||||
keyRetentionDays: 7 # Number of days to retain old keys
|
keyRetentionDays: 7 # Number of days to retain old keys. The default is 7 days.
|
||||||
cleanupBatchSize: 100 # Number of keys to clean up in each batch
|
cleanupBatchSize: 100 # Number of keys to clean up in each batch. The default is 100.
|
||||||
|
|
||||||
premium:
|
premium:
|
||||||
key: 00000000-0000-0000-0000-000000000000
|
key: 00000000-0000-0000-0000-000000000000
|
||||||
|
@ -62,11 +62,15 @@ window.JWTManager = {
|
|||||||
fetch('/logout', {
|
fetch('/logout', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
}).then(() => {
|
}).then(response => {
|
||||||
window.location.href = '/login';
|
if (response.redirected) {
|
||||||
|
window.location.href = response.url;
|
||||||
|
} else {
|
||||||
|
window.location.href = '/login?logout=true';
|
||||||
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// Even if logout fails, redirect to login
|
// If logout fails, let server handle it
|
||||||
window.location.href = '/login';
|
window.location.href = '/logout';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -47,11 +47,14 @@
|
|||||||
console.log('User is not authenticated or token expired');
|
console.log('User is not authenticated or token expired');
|
||||||
// Only redirect to login if we're not already on login/register pages
|
// Only redirect to login if we're not already on login/register pages
|
||||||
const currentPath = window.location.pathname;
|
const currentPath = window.location.pathname;
|
||||||
|
const currentSearch = window.location.search;
|
||||||
|
// Don't redirect if we're on logout page or already being logged out
|
||||||
if (!currentPath.includes('/login') &&
|
if (!currentPath.includes('/login') &&
|
||||||
!currentPath.includes('/register') &&
|
!currentPath.includes('/register') &&
|
||||||
!currentPath.includes('/oauth') &&
|
!currentPath.includes('/oauth') &&
|
||||||
!currentPath.includes('/saml') &&
|
!currentPath.includes('/saml') &&
|
||||||
!currentPath.includes('/error')) {
|
!currentPath.includes('/error') &&
|
||||||
|
!currentSearch.includes('logout=true')) {
|
||||||
// Redirect to login after a short delay to allow other scripts to load
|
// Redirect to login after a short delay to allow other scripts to load
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = '/login';
|
window.location.href = '/login';
|
||||||
|
@ -77,8 +77,11 @@ public class AccountWebController {
|
|||||||
|
|
||||||
@GetMapping("/login")
|
@GetMapping("/login")
|
||||||
public String login(HttpServletRequest request, Model model, Authentication authentication) {
|
public String login(HttpServletRequest request, Model model, Authentication authentication) {
|
||||||
// If the user is already authenticated, redirect them to the home page.
|
// If the user is already authenticated and it's not a logout scenario, redirect them to the
|
||||||
if (authentication != null && authentication.isAuthenticated()) {
|
// home page.
|
||||||
|
if (authentication != null
|
||||||
|
&& authentication.isAuthenticated()
|
||||||
|
&& request.getParameter("logout") == null) {
|
||||||
return "redirect:/";
|
return "redirect:/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,13 +65,6 @@ public class UserAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
|
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
log.info(
|
|
||||||
"UserAuthenticationFilter - Authentication from SecurityContext: {}",
|
|
||||||
authentication != null
|
|
||||||
? authentication.getClass().getSimpleName()
|
|
||||||
+ " for "
|
|
||||||
+ authentication.getName()
|
|
||||||
: "null");
|
|
||||||
|
|
||||||
// Check for session expiration (unsure if needed)
|
// Check for session expiration (unsure if needed)
|
||||||
// if (authentication != null && authentication.isAuthenticated()) {
|
// if (authentication != null && authentication.isAuthenticated()) {
|
||||||
@ -117,7 +110,7 @@ public class UserAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
String method = request.getMethod();
|
String method = request.getMethod();
|
||||||
String contextPath = request.getContextPath();
|
String contextPath = request.getContextPath();
|
||||||
|
|
||||||
if ("GET".equalsIgnoreCase(method) && !(contextPath + "/login").equals(requestURI)) {
|
if ("GET".equalsIgnoreCase(method) && !requestURI.startsWith(contextPath + "/login")) {
|
||||||
response.sendRedirect(contextPath + "/login"); // redirect to the login page
|
response.sendRedirect(contextPath + "/login"); // redirect to the login page
|
||||||
} else {
|
} else {
|
||||||
response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
||||||
|
@ -2,7 +2,8 @@ package stirling.software.proprietary.security.model;
|
|||||||
|
|
||||||
public enum AuthenticationType {
|
public enum AuthenticationType {
|
||||||
WEB,
|
WEB,
|
||||||
@Deprecated(since = "1.0.2") SSO,
|
@Deprecated(since = "1.0.2")
|
||||||
|
SSO,
|
||||||
OAUTH2,
|
OAUTH2,
|
||||||
SAML2
|
SAML2
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
@ -25,6 +26,7 @@ import stirling.software.proprietary.security.model.JwtSigningKey;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
@ConditionalOnBooleanProperty("v2")
|
||||||
public class JwtKeyCleanupService {
|
public class JwtKeyCleanupService {
|
||||||
|
|
||||||
private final JwtSigningKeyRepository signingKeyRepository;
|
private final JwtSigningKeyRepository signingKeyRepository;
|
||||||
|
@ -41,7 +41,7 @@ public class JwtService implements JwtServiceInterface {
|
|||||||
private static final String AUTHORIZATION_HEADER = "Authorization";
|
private static final String AUTHORIZATION_HEADER = "Authorization";
|
||||||
private static final String BEARER_PREFIX = "Bearer ";
|
private static final String BEARER_PREFIX = "Bearer ";
|
||||||
private static final String ISSUER = "Stirling PDF";
|
private static final String ISSUER = "Stirling PDF";
|
||||||
private static final long EXPIRATION = 300000; // 5 minutes in milliseconds
|
private static final long EXPIRATION = 3600000;
|
||||||
|
|
||||||
private final JwtKeystoreServiceInterface keystoreService;
|
private final JwtKeystoreServiceInterface keystoreService;
|
||||||
private final boolean v2Enabled;
|
private final boolean v2Enabled;
|
||||||
@ -127,7 +127,6 @@ public class JwtService implements JwtServiceInterface {
|
|||||||
|
|
||||||
private Claims extractAllClaims(String token) {
|
private Claims extractAllClaims(String token) {
|
||||||
try {
|
try {
|
||||||
// Extract key ID from token header if present
|
|
||||||
String keyId = extractKeyId(token);
|
String keyId = extractKeyId(token);
|
||||||
KeyPair keyPair;
|
KeyPair keyPair;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user