[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();
|
||||
logger.info("Restored " + certificates.size() + " sessions of which "
|
||||
+ (certificates.size() - this.certificateMap.size()) + " had timed out and were removed.");
|
||||
logger.info("Restored " + certificates.size() + " sessions of which " + (certificates.size()
|
||||
- this.certificateMap.size()) + " had timed out and were removed.");
|
||||
}
|
||||
|
||||
this.sessionHandler = getScheduledExecutor().scheduleWithFixedDelay(this::handleSessions, 5, 1,
|
||||
TimeUnit.MINUTES);
|
||||
this.sessionHandler = getScheduledExecutor()
|
||||
.scheduleWithFixedDelay(this::handleSessions, 5, 1, TimeUnit.MINUTES);
|
||||
|
||||
super.start();
|
||||
}
|
||||
|
@ -173,7 +173,8 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
|||
|
||||
Certificate removedCert = this.certificateMap.remove(certificate.getAuthToken());
|
||||
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);
|
||||
}
|
||||
|
@ -201,7 +202,8 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
|||
|
||||
Certificate removedCert = this.certificateMap.remove(certificate.getAuthToken());
|
||||
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);
|
||||
}
|
||||
|
@ -214,21 +216,26 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
|||
}
|
||||
|
||||
private void handleSessions() {
|
||||
checkSessionsForTimeout();
|
||||
persistSessions();
|
||||
|
||||
boolean changed = checkSessionsForTimeout();
|
||||
|
||||
// save sessions every few minutes
|
||||
if (!changed)
|
||||
persistSessions();
|
||||
}
|
||||
|
||||
private void persistSessions() {
|
||||
runAsAgent(ctx -> this.privilegeHandler.getPrivilegeHandler().persistSessions(ctx.getCertificate()));
|
||||
}
|
||||
|
||||
private void checkSessionsForTimeout() {
|
||||
Map<String, Certificate> map = getCertificateMap();
|
||||
private boolean checkSessionsForTimeout() {
|
||||
Map<String, Certificate> certificateMap;
|
||||
synchronized (map) {
|
||||
certificateMap = new HashMap<>(map);
|
||||
synchronized (this.certificateMap) {
|
||||
certificateMap = new HashMap<>(this.certificateMap);
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
LocalDateTime timeOutTime = LocalDateTime.now().minus(sessionTtl, ChronoUnit.MILLIS);
|
||||
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$
|
||||
logger.info(MessageFormat.format(msg, certificate.getSessionId(), certificate.getUsername()));
|
||||
sessionTimeout(certificate);
|
||||
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,27 +15,18 @@
|
|||
*/
|
||||
package li.strolch.utils.helper;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
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.parsers.*;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
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.LoggerFactory;
|
||||
import org.w3c.dom.DOMException;
|
||||
|
@ -44,8 +35,6 @@ import org.w3c.dom.Element;
|
|||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import li.strolch.utils.exceptions.XmlException;
|
||||
|
||||
/**
|
||||
* Helper class for performing XML based tasks
|
||||
*
|
||||
|
@ -226,7 +215,6 @@ public class XmlHelper {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue