diff options
author | Simon Rettberg | 2015-08-13 18:41:31 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-08-13 18:41:31 +0200 |
commit | 5609a2650fb4adbcd5015de44dd3093b2b79eda5 (patch) | |
tree | 3a8fcbd70d4867853c90b5ba4eca9f54a76bab78 /dozentenmodulserver | |
parent | [server] Validate lecture/imageversion dates, conditionally set isTemplate (diff) | |
download | tutor-module-5609a2650fb4adbcd5015de44dd3093b2b79eda5.tar.gz tutor-module-5609a2650fb4adbcd5015de44dd3093b2b79eda5.tar.xz tutor-module-5609a2650fb4adbcd5015de44dd3093b2b79eda5.zip |
[server] Don't mix seconds and milliseconds
Diffstat (limited to 'dozentenmodulserver')
4 files changed, 11 insertions, 9 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/RuntimeConfig.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/RuntimeConfig.java index ae9053a4..e73251fb 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/RuntimeConfig.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/RuntimeConfig.java @@ -22,12 +22,12 @@ public class RuntimeConfig { return satConfig.deepCopy(); } - public static long getMaxImageValidityMs() { - return satConfig.getMaxImageValidityDays() * 86400l * 1000l; + public static long getMaxImageValiditySeconds() { + return satConfig.getMaxImageValidityDays() * 86400l; } - public static long getMaxLectureValidityMs() { - return satConfig.getMaxLectureValidityDays() * 86400l * 1000l; + public static long getMaxLectureValiditySeconds() { + return satConfig.getMaxLectureValidityDays() * 86400l; } } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java index 2a9d5d6f..f1240c21 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java @@ -352,6 +352,8 @@ public class ServerHandler implements SatelliteServer.Iface { @Override public String createLecture(String userToken, LectureWrite lecture) throws TAuthorizationException, TInternalServerError, TInvalidDateParam { + if (lecture == null || lecture.defaultPermissions == null) + throw new TInternalServerError(); // TODO Own exception for this UserInfo user = SessionManager.getOrFail(userToken); User.canCreateLectureOrFail(user); Sanitizer.handleLectureDates(lecture); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Formatter.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Formatter.java index 0839ad24..bc64c8fe 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Formatter.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Formatter.java @@ -10,7 +10,7 @@ import org.openslx.bwlp.thrift.iface.UserInfo; public class Formatter { private static final DateTimeFormatter vmNameDateFormat = DateTimeFormat.forPattern("dd_HH-mm-ss"); - + /** * Generate a unique file name used for a virtual machine * image that is currently uploading. diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Sanitizer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Sanitizer.java index 5dd3b64e..52a32288 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Sanitizer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Sanitizer.java @@ -10,7 +10,7 @@ public class Sanitizer { /** * One day in milliseconds */ - private final static long ONE_DAY = 86400l * 1000l; + private final static long ONE_DAY = 86400l; /** * How far in the past can a date lie? Currently 180 days, no idea if anyone @@ -29,13 +29,13 @@ public class Sanitizer { public static void handleLectureDates(LectureWrite lecture) throws TInvalidDateParam { if (lecture.startTime > lecture.endTime) throw new TInvalidDateParam(DateParamError.NEGATIVE_RANGE, "Start date past end date"); - final long now = System.currentTimeMillis(); + final long now = System.currentTimeMillis() / 1000; long lowLimit = now - LOWER_CUTOFF; if (lecture.startTime < lowLimit) throw new TInvalidDateParam(DateParamError.TOO_LOW, "Start date lies in the past"); if (lecture.endTime < lowLimit) throw new TInvalidDateParam(DateParamError.TOO_LOW, "End date lies in the past"); - long highLimit = now + RuntimeConfig.getMaxLectureValidityMs(); + long highLimit = now + RuntimeConfig.getMaxLectureValiditySeconds(); if (lecture.startTime > highLimit) throw new TInvalidDateParam(DateParamError.TOO_HIGH, "Start date lies too far in the future"); // Bonus: If the end date is just a little bit off, silently correct it, since it might be clock @@ -55,7 +55,7 @@ public class Sanitizer { * @throws TInvalidDateParam If the date is invalid */ public static void handleImageExpiryDate(long unixTimestamp) throws TInvalidDateParam { - final long now = System.currentTimeMillis(); + final long now = System.currentTimeMillis() / 1000; long lowLimit = now - LOWER_CUTOFF; if (unixTimestamp < lowLimit) throw new TInvalidDateParam(DateParamError.TOO_LOW, "Expiry date lies in the past"); |