[Minor] only save permissions if required
This commit is contained in:
parent
33105cdf14
commit
b2604f7ab5
|
@ -93,12 +93,12 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
||||||
}
|
}
|
||||||
|
|
||||||
checkSessionsForTimeout();
|
checkSessionsForTimeout();
|
||||||
logger.info("Restored " + certificates.size() + " sessions of which "
|
logger.info("Restored " + certificates.size() + " sessions of which " + (certificates.size()
|
||||||
+ (certificates.size() - this.certificateMap.size()) + " had timed out and were removed.");
|
- this.certificateMap.size()) + " had timed out and were removed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sessionHandler = getScheduledExecutor().scheduleWithFixedDelay(this::handleSessions, 5, 1,
|
this.sessionHandler = getScheduledExecutor()
|
||||||
TimeUnit.MINUTES);
|
.scheduleWithFixedDelay(this::handleSessions, 5, 1, TimeUnit.MINUTES);
|
||||||
|
|
||||||
super.start();
|
super.start();
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,8 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
||||||
|
|
||||||
Certificate removedCert = this.certificateMap.remove(certificate.getAuthToken());
|
Certificate removedCert = this.certificateMap.remove(certificate.getAuthToken());
|
||||||
if (removedCert == null)
|
if (removedCert == null)
|
||||||
logger.error(MessageFormat.format("No session was registered with token {0}", certificate.getAuthToken())); //$NON-NLS-1$
|
logger.error(MessageFormat
|
||||||
|
.format("No session was registered with token {0}", certificate.getAuthToken())); //$NON-NLS-1$
|
||||||
|
|
||||||
this.privilegeHandler.invalidateSession(certificate);
|
this.privilegeHandler.invalidateSession(certificate);
|
||||||
}
|
}
|
||||||
|
@ -201,7 +202,8 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
||||||
|
|
||||||
Certificate removedCert = this.certificateMap.remove(certificate.getAuthToken());
|
Certificate removedCert = this.certificateMap.remove(certificate.getAuthToken());
|
||||||
if (removedCert == null)
|
if (removedCert == null)
|
||||||
logger.error(MessageFormat.format("No session was registered with token {0}", certificate.getAuthToken())); //$NON-NLS-1$
|
logger.error(MessageFormat
|
||||||
|
.format("No session was registered with token {0}", certificate.getAuthToken())); //$NON-NLS-1$
|
||||||
|
|
||||||
this.privilegeHandler.sessionTimeout(certificate);
|
this.privilegeHandler.sessionTimeout(certificate);
|
||||||
}
|
}
|
||||||
|
@ -214,21 +216,26 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSessions() {
|
private void handleSessions() {
|
||||||
checkSessionsForTimeout();
|
|
||||||
persistSessions();
|
boolean changed = checkSessionsForTimeout();
|
||||||
|
|
||||||
|
// save sessions every few minutes
|
||||||
|
if (!changed)
|
||||||
|
persistSessions();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void persistSessions() {
|
private void persistSessions() {
|
||||||
runAsAgent(ctx -> this.privilegeHandler.getPrivilegeHandler().persistSessions(ctx.getCertificate()));
|
runAsAgent(ctx -> this.privilegeHandler.getPrivilegeHandler().persistSessions(ctx.getCertificate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSessionsForTimeout() {
|
private boolean checkSessionsForTimeout() {
|
||||||
Map<String, Certificate> map = getCertificateMap();
|
|
||||||
Map<String, Certificate> certificateMap;
|
Map<String, Certificate> certificateMap;
|
||||||
synchronized (map) {
|
synchronized (this.certificateMap) {
|
||||||
certificateMap = new HashMap<>(map);
|
certificateMap = new HashMap<>(this.certificateMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean changed = false;
|
||||||
|
|
||||||
LocalDateTime timeOutTime = LocalDateTime.now().minus(sessionTtl, ChronoUnit.MILLIS);
|
LocalDateTime timeOutTime = LocalDateTime.now().minus(sessionTtl, ChronoUnit.MILLIS);
|
||||||
ZoneId systemDefault = ZoneId.systemDefault();
|
ZoneId systemDefault = ZoneId.systemDefault();
|
||||||
|
|
||||||
|
@ -238,8 +245,12 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
||||||
String msg = "Session {0} for user {1} has expired, invalidating session..."; //$NON-NLS-1$
|
String msg = "Session {0} for user {1} has expired, invalidating session..."; //$NON-NLS-1$
|
||||||
logger.info(MessageFormat.format(msg, certificate.getSessionId(), certificate.getUsername()));
|
logger.info(MessageFormat.format(msg, certificate.getSessionId(), certificate.getUsername()));
|
||||||
sessionTimeout(certificate);
|
sessionTimeout(certificate);
|
||||||
|
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,27 +15,18 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.utils.helper;
|
package li.strolch.utils.helper;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import javax.xml.parsers.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import javax.xml.parsers.SAXParser;
|
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
|
||||||
import javax.xml.transform.OutputKeys;
|
import javax.xml.transform.OutputKeys;
|
||||||
import javax.xml.transform.Source;
|
import javax.xml.transform.Source;
|
||||||
import javax.xml.transform.Transformer;
|
import javax.xml.transform.Transformer;
|
||||||
import javax.xml.transform.TransformerFactory;
|
import javax.xml.transform.TransformerFactory;
|
||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import li.strolch.utils.exceptions.XmlException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.w3c.dom.DOMException;
|
import org.w3c.dom.DOMException;
|
||||||
|
@ -44,8 +35,6 @@ import org.w3c.dom.Element;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
import li.strolch.utils.exceptions.XmlException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for performing XML based tasks
|
* Helper class for performing XML based tasks
|
||||||
*
|
*
|
||||||
|
@ -226,7 +215,6 @@ public class XmlHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lineSep.equals("\n")) { //$NON-NLS-1$
|
if (!lineSep.equals("\n")) { //$NON-NLS-1$
|
||||||
XmlHelper.logger.info("Overriding line separator to \\n"); //$NON-NLS-1$
|
|
||||||
System.setProperty(PROP_LINE_SEPARATOR, UNIX_LINE_SEP);
|
System.setProperty(PROP_LINE_SEPARATOR, UNIX_LINE_SEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue