List of usage examples for org.joda.time DateTime plusSeconds
public DateTime plusSeconds(int seconds)
From source file:com.enonic.cms.server.service.portal.mvc.controller.AbstractSiteController.java
License:Open Source License
protected void enableHttpCacheHeaders(HttpServletResponse response, SitePath sitePath, DateTime now, Integer siteCacheSettingsMaxAge, boolean anonymousAccess) { int maxAge;// w w w . j a va2 s .com boolean cacheForever = hasTimestampParameter(sitePath); if (cacheForever) { maxAge = HttpCacheControlSettings.CACHE_FOREVER_SECONDS; } else { maxAge = siteCacheSettingsMaxAge; } final DateTime expirationTime = now.plusSeconds(maxAge); final HttpCacheControlSettings cacheControlSettings = new HttpCacheControlSettings(); cacheControlSettings.maxAgeSecondsToLive = (long) maxAge; cacheControlSettings.publicAccess = anonymousAccess; HttpServletUtil.setExpiresHeader(response, expirationTime.toDate()); HttpServletUtil.setCacheControl(response, cacheControlSettings); }
From source file:com.enonic.cms.server.service.portal.mvc.controller.AttachmentController.java
License:Open Source License
private void enableHttpHeadersCache(HttpServletResponse response, SitePath sitePath, DateTime now, Integer siteCacheSettingsMaxAge, boolean publicAccess) { int maxAge;/*from ww w . ja v a2s . c o m*/ boolean cacheForever = hasTimestampParameter(sitePath); if (cacheForever) { maxAge = HttpCacheControlSettings.CACHE_FOREVER_SECONDS; } else { maxAge = siteCacheSettingsMaxAge; } final DateTime expirationTime = now.plusSeconds(maxAge); final HttpCacheControlSettings cacheControlSettings = new HttpCacheControlSettings(); cacheControlSettings.maxAgeSecondsToLive = (long) maxAge; cacheControlSettings.publicAccess = publicAccess; HttpServletUtil.setExpiresHeader(response, expirationTime.toDate()); HttpServletUtil.setCacheControl(response, cacheControlSettings); }
From source file:com.enonic.cms.web.portal.handler.WebHandlerBase.java
License:Open Source License
protected final void enableHttpCacheHeaders(HttpServletResponse response, SitePath sitePath, DateTime now, Integer siteCacheSettingsMaxAge, boolean anonymousAccess) { int maxAge;// w w w. ja v a 2 s. c o m boolean cacheForever = hasTimestampParameter(sitePath); if (cacheForever) { maxAge = HttpCacheControlSettings.CACHE_FOREVER_SECONDS; } else { maxAge = siteCacheSettingsMaxAge; } final DateTime expirationTime = now.plusSeconds(maxAge); final HttpCacheControlSettings cacheControlSettings = new HttpCacheControlSettings(); cacheControlSettings.maxAgeSecondsToLive = (long) maxAge; cacheControlSettings.publicAccess = anonymousAccess; HttpServletUtil.setExpiresHeader(response, expirationTime.toDate()); HttpServletUtil.setCacheControl(response, cacheControlSettings); }
From source file:com.eucalyptus.objectstorage.pipeline.auth.S3V4Authentication.java
License:Open Source License
static void validateExpiresFromParams(Map<String, String> parameters, Date date) throws AccessDeniedException { String expires = parameters.get(AWS_EXPIRES_PARAM); if (expires == null) throw new AccessDeniedException(null, "X-Amz-Expires parameter must be specified."); Long expireTime;//from w w w.j ava 2 s . co m try { expireTime = Long.parseLong(expires); } catch (NumberFormatException e) { throw new AccessDeniedException(null, "Invalid X-Amz-Expires parameter."); } if (expireTime < 1 || expireTime > 604800) throw new AccessDeniedException(null, "Invalid Expires parameter."); DateTime currentTime = DateTime.now(); DateTime dt = new DateTime(date); if (currentTime.isBefore(dt.minusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT))) throw new AccessDeniedException(null, "Cannot process request. X-Amz-Date is not yet valid."); if (currentTime.isAfter(dt.plusSeconds(expireTime.intValue() + StackConfiguration.CLOCK_SKEW_SEC))) throw new AccessDeniedException(null, "Cannot process request. Expired."); }
From source file:com.example.geomesa.accumulo.AccumuloQuickStart.java
License:Open Source License
static FeatureCollection createNewFeatures(SimpleFeatureType simpleFeatureType, int numNewFeatures) { DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); String id;/*from ww w .ja v a 2 s . c om*/ Object[] NO_VALUES = {}; String[] PEOPLE_NAMES = { "Addams", "Bierce", "Clemens" }; Long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L; Random random = new Random(5771); DateTime MIN_DATE = new DateTime(2014, 1, 1, 0, 0, 0, DateTimeZone.forID("UTC")); Double MIN_X = -78.0; Double MIN_Y = -39.0; Double DX = 2.0; Double DY = 2.0; for (int i = 0; i < numNewFeatures; i++) { // create the new (unique) identifier and empty feature shell id = "Observation." + Integer.toString(i); SimpleFeature simpleFeature = SimpleFeatureBuilder.build(simpleFeatureType, NO_VALUES, id); // be sure to tell GeoTools explicitly that you want to use the ID you provided simpleFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE); // populate the new feature's attributes // string value simpleFeature.setAttribute("Who", PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // long value simpleFeature.setAttribute("What", i); // location: construct a random point within a 2-degree-per-side square double x = MIN_X + random.nextDouble() * DX; double y = MIN_Y + random.nextDouble() * DY; Geometry geometry = WKTUtils.read("POINT(" + x + " " + y + ")"); // date-time: construct a random instant within a year simpleFeature.setAttribute("Where", geometry); DateTime dateTime = MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)); simpleFeature.setAttribute("When", dateTime.toDate()); // another string value // "Why"; left empty, showing that not all attributes need values // accumulate this new feature in the collection featureCollection.add(simpleFeature); } return featureCollection; }
From source file:com.example.geomesa.accumulo.FeatureLevelVisibility.java
License:Open Source License
static FeatureCollection createNewFeatures(SimpleFeatureType simpleFeatureType, int numNewFeatures) { DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); String id;/* w w w .java2 s. c o m*/ Object[] NO_VALUES = {}; String[] PEOPLE_NAMES = { "Addams", "Bierce", "Clemens" }; Long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L; Random random = new Random(5771); DateTime MIN_DATE = new DateTime(2014, 1, 1, 0, 0, 0, DateTimeZone.forID("UTC")); Double MIN_X = -78.0; Double MIN_Y = -39.0; Double DX = 2.0; Double DY = 2.0; for (int i = 0; i < numNewFeatures; i++) { // create the new (unique) identifier and empty feature shell id = "Observation." + Integer.toString(i); SimpleFeature simpleFeature = SimpleFeatureBuilder.build(simpleFeatureType, NO_VALUES, id); // be sure to tell GeoTools explicitly that you want to use the ID you provided simpleFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE); // populate the new feature's attributes // string value simpleFeature.setAttribute("Who", PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // long value simpleFeature.setAttribute("What", i); // location: construct a random point within a 2-degree-per-side square double x = MIN_X + random.nextDouble() * DX; double y = MIN_Y + random.nextDouble() * DY; Geometry geometry = WKTUtils.read("POINT(" + x + " " + y + ")"); // date-time: construct a random instant within a year simpleFeature.setAttribute("Where", geometry); DateTime dateTime = MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)); simpleFeature.setAttribute("When", dateTime.toDate()); // another string value // "Why"; left empty, showing that not all attributes need values // set visibility on each feature, and attribute for display if (i % 2 == 0) { simpleFeature.setAttribute("Visibility", "admin"); SecurityUtils.setFeatureVisibility(simpleFeature, "admin"); } else { simpleFeature.setAttribute("Visibility", "user|admin"); SecurityUtils.setFeatureVisibility(simpleFeature, "user|admin"); } // accumulate this new feature in the collection featureCollection.add(simpleFeature); } return featureCollection; }
From source file:com.example.geomesa.hbase.HBaseQuickStart.java
License:Apache License
static FeatureCollection createNewFeatures(SimpleFeatureType simpleFeatureType, int numNewFeatures) { DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); String id;/*from w ww . jav a 2 s . c o m*/ Object[] NO_VALUES = {}; String[] PEOPLE_NAMES = { "Addams", "Bierce", "Clemens" }; Long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L; Random random = new Random(5771); DateTime MIN_DATE = new DateTime(2014, 1, 1, 0, 0, 0, DateTimeZone.forID("UTC")); Double MIN_X = -79.5; Double MIN_Y = 37.0; Double DX = 2.0; Double DY = 2.0; for (int i = 0; i < numNewFeatures; i++) { // create the new (unique) identifier and empty feature shell id = "Observation." + Integer.toString(i); SimpleFeature simpleFeature = SimpleFeatureBuilder.build(simpleFeatureType, NO_VALUES, id); // be sure to tell GeoTools explicitly that you want to use the ID you provided simpleFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE); // populate the new feature's attributes // Who: string value simpleFeature.setAttribute("Who", PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // What: long value simpleFeature.setAttribute("What", i); // Where: location: construct a random point within a 2-degree-per-side square double x = MIN_X + random.nextDouble() * DX; double y = MIN_Y + random.nextDouble() * DY; Geometry geometry = WKTUtils$.MODULE$.read("POINT(" + x + " " + y + ")"); simpleFeature.setAttribute("Where", geometry); // When: date-time: construct a random instant within a year DateTime dateTime = MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)); simpleFeature.setAttribute("When", dateTime.toDate()); // Why: another string value // left empty, showing that not all attributes need values // accumulate this new feature in the collection featureCollection.add(simpleFeature); } return featureCollection; }
From source file:com.example.geomesa.kafka.KafkaQuickStart.java
License:Open Source License
public static void addSimpleFeatures(SimpleFeatureType sft, FeatureStore producerFS) throws InterruptedException, IOException { final int MIN_X = -180; final int MAX_X = 180; final int MIN_Y = -90; final int MAX_Y = 90; final int DX = 2; final int DY = 1; final String[] PEOPLE_NAMES = { "James", "John", "Peter", "Hannah", "Claire", "Gabriel" }; final long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L; final Random random = new Random(); final DateTime MIN_DATE = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeZone.forID("UTC")); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(sft); DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); // creates and updates two SimpleFeatures. // the first time this for loop runs the two SimpleFeatures are created. // in the subsequent iterations of the for loop, the two SimpleFeatures are updated. int numFeatures = (MAX_X - MIN_X) / DX; for (int i = 1; i <= numFeatures; i++) { builder.add(PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // name builder.add((int) Math.round(random.nextDouble() * 110)); // age builder.add(MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toDate()); // dtg builder.add(WKTUtils$.MODULE$.read("POINT(" + (MIN_X + DX * i) + " " + (MIN_Y + DY * i) + ")")); // geom SimpleFeature feature1 = builder.buildFeature("1"); builder.add(PEOPLE_NAMES[(i + 1) % PEOPLE_NAMES.length]); // name builder.add((int) Math.round(random.nextDouble() * 110)); // age builder.add(MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toDate()); // dtg builder.add(WKTUtils$.MODULE$.read("POINT(" + (MIN_X + DX * i) + " " + (MAX_Y - DY * i) + ")")); // geom SimpleFeature feature2 = builder.buildFeature("2"); // write the SimpleFeatures to Kafka featureCollection.add(feature1); featureCollection.add(feature2); producerFS.addFeatures(featureCollection); featureCollection.clear();//from ww w . j av a 2 s . c o m // wait 100 ms in between updating SimpleFeatures to simulate a stream of data Thread.sleep(100); } }
From source file:com.example.geomesa.kafka08.KafkaQuickStart.java
License:Open Source License
public static void addSimpleFeatures(SimpleFeatureType sft, FeatureStore producerFS, String visibility) throws InterruptedException, IOException { final int MIN_X = -180; final int MAX_X = 180; final int MIN_Y = -90; final int MAX_Y = 90; final int DX = 2; final int DY = 1; final String[] PEOPLE_NAMES = { "James", "John", "Peter", "Hannah", "Claire", "Gabriel" }; final long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L; final Random random = new Random(); final DateTime MIN_DATE = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeZone.forID("UTC")); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(sft); DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); // creates and updates two SimpleFeatures. // the first time this for loop runs the two SimpleFeatures are created. // in the subsequent iterations of the for loop, the two SimpleFeatures are updated. int numFeatures = (MAX_X - MIN_X) / DX; for (int i = 1; i <= numFeatures; i++) { builder.add(PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // name builder.add((int) Math.round(random.nextDouble() * 110)); // age builder.add(MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toDate()); // dtg builder.add(WKTUtils$.MODULE$.read("POINT(" + (MIN_X + DX * i) + " " + (MIN_Y + DY * i) + ")")); // geom SimpleFeature feature1 = builder.buildFeature("1"); builder.add(PEOPLE_NAMES[(i + 1) % PEOPLE_NAMES.length]); // name builder.add((int) Math.round(random.nextDouble() * 110)); // age builder.add(MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toDate()); // dtg builder.add(WKTUtils$.MODULE$.read("POINT(" + (MIN_X + DX * i) + " " + (MAX_Y - DY * i) + ")")); // geom SimpleFeature feature2 = builder.buildFeature("2"); if (visibility != null) { feature1.getUserData().put("geomesa.feature.visibility", visibility); feature2.getUserData().put("geomesa.feature.visibility", visibility); }//www. ja v a2s. com // write the SimpleFeatures to Kafka featureCollection.add(feature1); featureCollection.add(feature2); producerFS.addFeatures(featureCollection); featureCollection.clear(); // wait 100 ms in between updating SimpleFeatures to simulate a stream of data Thread.sleep(100); } }
From source file:com.lastpass.saml.SAMLClient.java
License:Apache License
private void validate(Response response) throws ValidationException { // response signature must match IdP's key, if present Signature sig = response.getSignature(); if (sig != null) sigValidator.validate(sig);/*ww w .jav a2 s. co m*/ // response must be successful if (response.getStatus() == null || response.getStatus().getStatusCode() == null || !(StatusCode.SUCCESS_URI.equals(response.getStatus().getStatusCode().getValue()))) { throw new ValidationException("Response has an unsuccessful status code"); } // response destination must match ACS if (!spConfig.getAcs().equals(response.getDestination())) throw new ValidationException("Response is destined for a different endpoint"); DateTime now = DateTime.now(); // issue instant must be within a day DateTime issueInstant = response.getIssueInstant(); if (issueInstant != null) { if (issueInstant.isBefore(now.minusDays(1).minusSeconds(slack))) throw new ValidationException("Response IssueInstant is in the past"); if (issueInstant.isAfter(now.plusDays(1).plusSeconds(slack))) throw new ValidationException("Response IssueInstant is in the future"); } List<Assertion> assertions; try { assertions = parseAllAssertions(response); } catch (SAMLException ex) { throw new ValidationException("no assertions found."); } for (Assertion assertion : assertions) { // Assertion must be signed correctly if (!assertion.isSigned()) throw new ValidationException("Assertion must be signed"); sig = assertion.getSignature(); sigValidator.validate(sig); // Assertion must contain an authnstatement // with an unexpired session if (assertion.getAuthnStatements().isEmpty()) { throw new ValidationException("Assertion should contain an AuthnStatement"); } for (AuthnStatement as : assertion.getAuthnStatements()) { DateTime sessionTime = as.getSessionNotOnOrAfter(); if (sessionTime != null) { DateTime exp = sessionTime.plusSeconds(slack); if (exp != null && (now.isEqual(exp) || now.isAfter(exp))) throw new ValidationException("AuthnStatement has expired"); } } if (assertion.getConditions() == null) { throw new ValidationException("Assertion should contain conditions"); } // Assertion IssueInstant must be within a day DateTime instant = assertion.getIssueInstant(); if (instant != null) { if (instant.isBefore(now.minusDays(1).minusSeconds(slack))) throw new ValidationException("Response IssueInstant is in the past"); if (instant.isAfter(now.plusDays(1).plusSeconds(slack))) throw new ValidationException("Response IssueInstant is in the future"); } // Conditions must be met by current time Conditions conditions = assertion.getConditions(); DateTime notBefore = conditions.getNotBefore(); DateTime notOnOrAfter = conditions.getNotOnOrAfter(); if (notBefore == null || notOnOrAfter == null) throw new ValidationException("Assertion conditions must have limits"); notBefore = notBefore.minusSeconds(slack); notOnOrAfter = notOnOrAfter.plusSeconds(slack); if (now.isBefore(notBefore)) throw new ValidationException("Assertion conditions is in the future"); if (now.isEqual(notOnOrAfter) || now.isAfter(notOnOrAfter)) throw new ValidationException("Assertion conditions is in the past"); // If subjectConfirmationData is included, it must // have a recipient that matches ACS, with a valid // NotOnOrAfter Subject subject = assertion.getSubject(); if (subject != null && !subject.getSubjectConfirmations().isEmpty()) { boolean foundRecipient = false; for (SubjectConfirmation sc : subject.getSubjectConfirmations()) { if (sc.getSubjectConfirmationData() == null) continue; SubjectConfirmationData scd = sc.getSubjectConfirmationData(); if (scd.getNotOnOrAfter() != null) { DateTime chkdate = scd.getNotOnOrAfter().plusSeconds(slack); if (now.isEqual(chkdate) || now.isAfter(chkdate)) { throw new ValidationException("SubjectConfirmationData is in the past"); } } if (spConfig.getAcs().equals(scd.getRecipient())) foundRecipient = true; } if (!foundRecipient) throw new ValidationException("No SubjectConfirmationData found for ACS"); } // audience must include intended SP issuer if (conditions.getAudienceRestrictions().isEmpty()) throw new ValidationException("Assertion conditions must have audience restrictions"); // only one audience restriction supported: we can only // check against the single SP. if (conditions.getAudienceRestrictions().size() > 1) throw new ValidationException("Assertion contains multiple audience restrictions"); AudienceRestriction ar = conditions.getAudienceRestrictions().get(0); // at least one of the audiences must match our SP boolean foundSP = false; for (Audience a : ar.getAudiences()) { if (spConfig.getEntityId().equals(a.getAudienceURI())) foundSP = true; } if (!foundSP) throw new ValidationException("Assertion audience does not include issuer"); } }