List of usage examples for org.joda.time DateTime plus
public DateTime plus(ReadablePeriod period)
From source file:com.vmware.identity.samlservice.impl.LogoutStateValidator.java
License:Open Source License
/** * Validate LogoutResponse/*from w w w.j a v a 2 s .c o m*/ * * @param vr * @param accessor * @param response * @return */ private com.vmware.identity.samlservice.SamlValidator.ValidationResult validateLogoutResponse( com.vmware.identity.samlservice.SamlValidator.ValidationResult vr, IdmAccessor accessor, LogoutResponse response, SessionManager sm) { Validate.notNull(response.getIssuer()); // Validate single logout service first, if that is valid, we can send // SAML replies try { @SuppressWarnings("unused") String acsUrl = accessor.getSloForRelyingParty(response.getIssuer().getValue(), OasisNames.HTTP_REDIRECT); } catch (IllegalStateException e) { // set validation result to 400 log.debug("Caught illegal state exception while Validating " + e.toString() + ", returning 400"); vr = new ValidationResult(HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), null); } // Validate ID if (vr == null && response.getID() == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Request ID is missing"); } // Validate version if (vr == null) { SAMLVersion version = response.getVersion(); if ((version.getMajorVersion() > Shared.REQUIRED_SAML_VERSION.getMajorVersion()) || version.getMajorVersion() == Shared.REQUIRED_SAML_VERSION.getMajorVersion() && version.getMinorVersion() > Shared.REQUIRED_SAML_VERSION.getMinorVersion()) { // version too high vr = new ValidationResult(OasisNames.VERSION_MISMATCH, OasisNames.REQUEST_VERSION_TOO_HIGH); log.debug("Validation FAILED - Version is too high"); } else if ((version.getMajorVersion() < Shared.REQUIRED_SAML_VERSION.getMajorVersion()) || version.getMajorVersion() == Shared.REQUIRED_SAML_VERSION.getMajorVersion() && version.getMinorVersion() < Shared.REQUIRED_SAML_VERSION.getMinorVersion()) { // version too low vr = new ValidationResult(OasisNames.VERSION_MISMATCH, OasisNames.REQUEST_VERSION_TOO_LOW); log.debug("Validation FAILED - Version is too low"); } } // Validate IssueInstant if (vr == null) { DateTime dtPlus = response.getIssueInstant(); DateTime dtMinus = response.getIssueInstant(); DateTime instant = new DateTime(); long clockTolerance = accessor.getClockTolerance(); if (dtPlus == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Issue Instant is missing"); } else { dtPlus = dtPlus.plus(clockTolerance); dtMinus = dtMinus.minus(clockTolerance); // dtPlus must be after now and dtMinus must be before now // in order to satisfy clock tolerance if (dtPlus.isBefore(instant) || dtMinus.isAfter(instant)) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Issue Instant outside of clock tolerance"); log.debug("clockTolerance {} ", clockTolerance); log.debug("now {}", instant); log.debug("dtPlus {}", dtPlus.toString()); log.debug("dtMinus {}", dtMinus.toString()); } } } // Destination URL skipped, this is already done by OpenSAML when // parsing // validate inResponseTo (which is the corresponding SLO request ID that // this response is targetting at) if (vr == null) { String inResponseTo = response.getInResponseTo(); if (inResponseTo == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - inResponseTo is missing"); } else { // try to find a session by LogoutRequest id that we have Session session = sm.getByLogoutRequestId(inResponseTo); if (session == null) { // No session found using the SLO request ID. This could // happen due to // fail-over (node switch). So here we ignore rather than // throw error at browser log.info( "Unable to identify a session the SLO response is referring to. This could be caused by site-affinity switch."); } } } // check response status code if (vr == null) { Status status = null; StatusCode statusCode = null; if (vr == null) { // check LogoutResponse status code here status = response.getStatus(); if (status == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - unable to find status code"); } } if (vr == null) { statusCode = status.getStatusCode(); if (statusCode == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - unable to find status code"); } } if (vr == null) { String code = statusCode.getValue(); if (!OasisNames.SUCCESS.equals(code)) { vr = new ValidationResult(OasisNames.SUCCESS, OasisNames.PARTIAL_LOGOUT); log.debug("Validation FAILED - partially logged out session"); } } } // validation done if (vr == null) { vr = new ValidationResult(); // success } return vr; }
From source file:com.vmware.identity.samlservice.impl.LogoutStateValidator.java
License:Open Source License
/** * Validate LogoutRequest// ww w . j a va2 s . c om * * @param vr * @param accessor * @param request * @return */ private ValidationResult validateLogoutRequest(ValidationResult vr, IdmAccessor accessor, LogoutRequest request) { Validate.notNull(request.getIssuer()); // Validate single logout service first, if that is valid, we can send // SAML replies try { @SuppressWarnings("unused") String acsUrl = accessor.getSloForRelyingParty(request.getIssuer().getValue(), OasisNames.HTTP_REDIRECT); } catch (IllegalStateException e) { // set validation result to 400 log.debug("Caught illegal state exception while Validating " + e.toString() + ", returning 400"); vr = new ValidationResult(HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), null); } // Validate ID if (vr == null && request.getID() == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Request ID is missing"); } // Validate version if (vr == null) { SAMLVersion version = request.getVersion(); if ((version.getMajorVersion() > Shared.REQUIRED_SAML_VERSION.getMajorVersion()) || version.getMajorVersion() == Shared.REQUIRED_SAML_VERSION.getMajorVersion() && version.getMinorVersion() > Shared.REQUIRED_SAML_VERSION.getMinorVersion()) { // version too high vr = new ValidationResult(OasisNames.VERSION_MISMATCH, OasisNames.REQUEST_VERSION_TOO_HIGH); log.debug("Validation FAILED - Version is too high"); } else if ((version.getMajorVersion() < Shared.REQUIRED_SAML_VERSION.getMajorVersion()) || version.getMajorVersion() == Shared.REQUIRED_SAML_VERSION.getMajorVersion() && version.getMinorVersion() < Shared.REQUIRED_SAML_VERSION.getMinorVersion()) { // version too low vr = new ValidationResult(OasisNames.VERSION_MISMATCH, OasisNames.REQUEST_VERSION_TOO_LOW); log.debug("Validation FAILED - Version is too low"); } } // Validate IssueInstant if (vr == null) { DateTime dtPlus = request.getIssueInstant(); DateTime dtMinus = request.getIssueInstant(); DateTime instant = new DateTime(); long clockTolerance = accessor.getClockTolerance(); if (dtPlus == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Issue Instant is missing"); } else { dtPlus = dtPlus.plus(clockTolerance); dtMinus = dtMinus.minus(clockTolerance); // dtPlus must be after now and dtMinus must be before now // in order to satisfy clock tolerance if (dtPlus.isBefore(instant) || dtMinus.isAfter(instant)) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Issue Instant outside of clock tolerance"); log.debug("clockTolerance {}", clockTolerance); log.debug("now {}", instant); log.debug("dtPlus {}", dtPlus.toString()); log.debug("dtMinus {}", dtMinus.toString()); } } } // Destination URL skipped, this is already done by OpenSAML when // parsing // Validate NotOnOrAfter if (vr == null) { DateTime notOnOrAfter = request.getNotOnOrAfter(); if (notOnOrAfter != null) { DateTime instant = new DateTime(); if (!instant.isBefore(notOnOrAfter)) { vr = new ValidationResult(OasisNames.REQUESTER, OasisNames.REQUEST_DENIED); log.debug("Validation FAILED - NotOnOrAfter condition violated"); log.debug("now {}", instant); log.debug("notOnOrAfter {}", notOnOrAfter.toString()); } } } // validate NameID if (vr == null) { NameID nameID = request.getNameID(); if (nameID == null || nameID.getFormat() == null || nameID.getValue() == null) { log.debug("Validation FAILED for NameID: node, format or value missing"); vr = new ValidationResult(OasisNames.REQUESTER); } } // validate session index if (vr == null) { List<SessionIndex> sessionList = request.getSessionIndexes(); if (sessionList == null || sessionList.size() == 0) { log.debug("Validation FAILED for session indices: at least one session index is required"); vr = new ValidationResult(OasisNames.REQUESTER); } } // validation done if (vr == null) { vr = new ValidationResult(); // success } return vr; }
From source file:com.wealdtech.utils.WealdInterval.java
License:Open Source License
public WealdInterval(final DateTime start, final Duration duration) { this.start = start; this.end = start.plus(duration); }
From source file:com.wealdtech.utils.WealdInterval.java
License:Open Source License
public WealdInterval(final DateTime start, final Period period) { this.start = start; this.end = start.plus(period); }
From source file:com.xpn.xwiki.stats.impl.xwiki.XWikiStatsReader.java
License:Open Source License
/** * Shows how the statistics for the specified action have evolved over the specified period of time. * //from www .j a v a 2 s . c o m * @param action the action for which to retrieve statistics. * @param scope the set of documents to consider. * @param period the period of time, including its start date but excluding its end date. * @param step the step used for sampling the period. * @param context the XWiki context. * @return a map of (date, actionCount) pairs. */ public Map<DateTime, Integer> getActionStatistics(String action, Scope scope, Period period, Duration step, XWikiContext context) { DateTime stepStart = new DateTime(period.getStart()); DateTime periodEnd = new DateTime(period.getEnd()); org.joda.time.Period stepDuration = new org.joda.time.Period(step.getYears(), step.getMonths(), step.getWeeks(), step.getDays(), 0, 0, 0, 0); Map<DateTime, Integer> activity = new HashMap<DateTime, Integer>(); while (stepStart.compareTo(periodEnd) < 0) { DateTime stepEnd = stepStart.plus(stepDuration); if (stepEnd.compareTo(periodEnd) > 0) { stepEnd = periodEnd; } List<DocumentStats> stats = getDocumentStatistics(action, scope, new Period(stepStart.getMillis(), stepEnd.getMillis()), RangeFactory.FIRST, context); int actionCount = 0; if (stats.size() > 0) { actionCount = stats.get(0).getPageViews(); } activity.put(stepStart, new Integer(actionCount)); stepStart = stepEnd; } return activity; }
From source file:com.yahoo.bard.webservice.data.time.TimeGrain.java
License:Apache License
/** * Round the DateTime to the "front edge" (ie. the most recent time) of the time bucket the DateTime falls in. * * @param dateTime DateTime to round//w w w . ja v a 2 s. co m * * @return the rounded DateTime */ @JsonIgnore default DateTime roundCeiling(DateTime dateTime) { DateTime floor = roundFloor(dateTime); return floor.equals(dateTime) ? floor : floor.plus(getPeriod()); }
From source file:com.yahoo.bard.webservice.util.DateTimeUtils.java
License:Apache License
/** * Adds timeGrain to a given dateTime./*from w w w. j av a 2s . co m*/ * * @param dateTime dateTime to which timeGrain is to be added * @param timeGrain timeGrain to be added * * @return new dateTime i.e. old dateTime + timeGrain */ public static DateTime addTimeGrain(DateTime dateTime, TimeGrain timeGrain) { return dateTime.plus(timeGrain.getPeriod()); }
From source file:com.yahoo.bard.webservice.web.NextMacroCalculation.java
License:Apache License
@Override public DateTime getDateTime(DateTime dateTime, TimeGrain timeGrain) { return timeGrain.roundFloor(dateTime.plus(timeGrain.getPeriod())); }
From source file:com.yandex.money.api.model.showcase.components.uicontrols.Date.java
License:Open Source License
private static DateTime parseWithPeriod(DateTime dateTime, Period period, boolean add) { return add ? dateTime.plus(period) : dateTime.minus(period); }
From source file:datafu.pig.date.TimeCount.java
License:Apache License
public Long call(DataBag bag) throws IOException { DateTime last_date = null; long sum = 0; for (Tuple t : bag) { DateTime date = new DateTime(t.get(0)); if (last_date == null) { last_date = date;//from w ww . ja v a2 s .com sum = 1; } else if (date.isAfter(last_date.plus(this.millis))) sum += 1; else if (date.isBefore(last_date)) throw new IOException("input time series is not sorted"); last_date = date; } return sum; }