List of usage examples for org.joda.time DateTime minusSeconds
public DateTime minusSeconds(int seconds)
From source file:org.efaps.esjp.accounting.report.TrialBalanceDS_Base.java
License:Apache License
@Override public void init(final JasperReport _jasperReport, final Parameter _parameter, final JRDataSource _parentSource, final Map<String, Object> _jrParameters) throws EFapsException { super.init(_jasperReport, _parameter, _parentSource, _jrParameters); final Map<Instance, DataBean> mapping = new HashMap<>(); final List<Instance> instances = new ArrayList<>(); final DateTime dateFrom = new DateTime( _parameter.getParameterValue(CIFormAccounting.Accounting_PReportTrialBalanceForm.dateFrom.name)); final DateTime dateTo = new DateTime( _parameter.getParameterValue(CIFormAccounting.Accounting_PReportTrialBalanceForm.dateTo.name)); final boolean includeInit = Boolean.parseBoolean( _parameter.getParameterValue(CIFormAccounting.Accounting_PReportTrialBalanceForm.includeInit.name)); int level = 2; final String levelStr = _parameter .getParameterValue(CIFormAccounting.Accounting_PReportTrialBalanceForm.level.name); if (levelStr != null && !levelStr.isEmpty()) { level = Integer.parseInt(levelStr); }/*from w ww . j a v a2 s .c om*/ _jrParameters.put("IncludeInit", includeInit); _jrParameters.put("DateFrom", dateFrom); _jrParameters.put("DateTo", dateTo); final String[] oids = (String[]) Context.getThreadContext().getSessionAttribute("selectedOIDs"); for (final String oid : oids) { final Instance instancetmp = Instance.get(oid); if (instancetmp.isValid()) { instances.addAll(getAccountInst(_parameter, instancetmp, false)); } } final QueryBuilder attrQueryBldr = new QueryBuilder(CIAccounting.TransactionAbstract); attrQueryBldr.addWhereAttrLessValue(CIAccounting.TransactionAbstract.Date, dateTo.plusDays(1)); if (!includeInit) { attrQueryBldr.addWhereAttrGreaterValue(CIAccounting.TransactionAbstract.Date, dateFrom.minusSeconds(1)); } final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.TransactionPositionAbstract); queryBldr.addWhereAttrInQuery(CIAccounting.TransactionPositionAbstract.TransactionLink, attrQueryBldr.getAttributeQuery(CIAccounting.TransactionAbstract.ID)); queryBldr.addWhereAttrEqValue(CIAccounting.TransactionPositionAbstract.AccountLink, instances.toArray()); final MultiPrintQuery multi = queryBldr.getPrint(); final SelectBuilder selTrans = SelectBuilder.get() .linkto(CIAccounting.TransactionPositionAbstract.TransactionLink); final SelectBuilder selTransDate = new SelectBuilder(selTrans) .attribute(CIAccounting.TransactionAbstract.Date); final SelectBuilder selAcc = SelectBuilder.get() .linkto(CIAccounting.TransactionPositionAbstract.AccountLink); final SelectBuilder selAccInst = new SelectBuilder(selAcc).instance(); final SelectBuilder selAccName = new SelectBuilder(selAcc).attribute(CIAccounting.AccountAbstract.Name); final SelectBuilder selAccDescr = new SelectBuilder(selAcc) .attribute(CIAccounting.AccountAbstract.Description); multi.addSelect(selTransDate, selAccInst, selAccName, selAccDescr); multi.addAttribute(CIAccounting.TransactionPositionAbstract.Amount); multi.execute(); while (multi.next()) { final DateTime date = multi.<DateTime>getSelect(selTransDate); final BigDecimal amount = multi .<BigDecimal>getAttribute(CIAccounting.TransactionPositionAbstract.Amount); final Instance accInst = multi.getSelect(selAccInst); DataBean bean; if (mapping.containsKey(accInst)) { bean = mapping.get(accInst); } else { bean = new DataBean(); mapping.put(accInst, bean); bean.setAccName(multi.<String>getSelect(selAccName)); bean.setAccDescr(multi.<String>getSelect(selAccDescr)); } if (multi.getCurrentInstance().getType().isKindOf(CIAccounting.TransactionPositionDebit.getType())) { if (includeInit && date.isBefore(dateFrom.plusSeconds(1))) { bean.addInitDebit(amount); } else { bean.addDebit(amount); } } else { if (includeInit && date.isBefore(dateFrom.plusSeconds(1))) { bean.addInitCredit(amount); } else { bean.addCredit(amount); } } } final List<DataBean> values; if (level > 0) { values = new ArrayList<>(); final Map<Instance, Leveler> accMap = new HashMap<>(); for (final Entry<Instance, DataBean> entry : mapping.entrySet()) { final Leveler accInfo = getLeveler(_parameter).setInstance(entry.getKey()).setLevel(level); if (accMap.containsKey(accInfo.getInstance())) { accMap.get(accInfo.getInstance()).addBean(entry.getValue()); } else { accInfo.addBean(entry.getValue()); accMap.put(accInfo.getInstance(), accInfo); } } for (final Leveler leveler : accMap.values()) { values.add(leveler.getDataBean()); } } else { values = new ArrayList<>(mapping.values()); } final ComparatorChain<DataBean> chain = new ComparatorChain<>(); chain.addComparator(new Comparator<DataBean>() { @Override public int compare(final DataBean _arg0, final DataBean _arg1) { return _arg0.getAccName().compareTo(_arg1.getAccName()); } }); Collections.sort(values, chain); setData(values); }
From source file:org.jaggeryjs.modules.sso.common.util.Util.java
License:Open Source License
/** * Validates the 'Not Before' and 'Not On Or After' conditions of the SAML Assertion * * @param resp SAML Response/*from ww w.ja v a2 s . co m*/ */ public static boolean validateAssertionValidityPeriod(Response resp, Properties prop) { Assertion assertion; assertion = retrieveAssertion(resp); if (assertion == null) { log.error("SAML Assertion not found in the Response"); return false; } DateTime validFrom = assertion.getConditions().getNotBefore(); DateTime validTill = assertion.getConditions().getNotOnOrAfter(); int timeStampSkewInSeconds = getTimeStampSkewInSeconds(prop); if (validFrom != null && validFrom.minusSeconds(timeStampSkewInSeconds).isAfterNow()) { log.error("Failed to meet SAML Assertion Condition 'Not Before'"); return false; } if (validTill != null && validTill.plusSeconds(timeStampSkewInSeconds).isBeforeNow()) { log.error("Failed to meet SAML Assertion Condition 'Not On Or After'"); return false; } if (validFrom != null && validTill != null && validFrom.isAfter(validTill)) { log.error( "SAML Assertion Condition 'Not Before' must be less than the " + "value of 'Not On Or After'"); return false; } return true; }
From source file:org.jasig.portal.portlet.container.services.PortletCookieServiceImpl.java
License:Apache License
/** * //from w w w. ja va2 s . c o m * (non-Javadoc) * @see org.jasig.portal.portlet.container.services.IPortletCookieService#updatePortalCookie(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override public void updatePortalCookie(HttpServletRequest request, HttpServletResponse response) { //Get the portal cookie object final IPortalCookie portalCookie = this.getOrCreatePortalCookie(request); //Create the browser cookie final Cookie cookie = this.convertToCookie(portalCookie, this.portalCookieAlwaysSecure || request.isSecure()); //Update the expiration date of the portal cookie stored in the DB if the update interval has passed final DateTime expires = portalCookie.getExpires(); if (DateTime.now().minusMillis(this.maxAgeUpdateInterval).isAfter(expires.minusSeconds(this.maxAge))) { this.portletCookieDao.updatePortalCookieExpiration(portalCookie, cookie.getMaxAge()); // Update expiration dates of portlet cookies stored in session removeExpiredPortletCookies(request); } //Update the cookie in the users browser response.addCookie(cookie); }
From source file:org.kuali.kpme.core.util.TKUtils.java
License:Educational Community License
public static Timestamp subtractOneSecondFromTimestamp(Timestamp originalTimestamp) { DateTime dt = new DateTime(originalTimestamp); dt = dt.minusSeconds(1); return new Timestamp(dt.getMillis()); }
From source file:org.wildfly.metrics.server.Server.java
License:Apache License
public static void main(String[] args) throws Exception { final Server server = new Server(); Undertow http = Undertow.builder().addHttpListener(4444, "localhost") .setHandler(path().addPrefixPath("/api/put", exchange -> { Map<String, Deque<String>> params = exchange.getQueryParameters(); server.writeMetric(params.get("metric").getFirst(), Long.valueOf(params.get("value").getFirst())); })//from w ww .j ava 2 s. c o m .addPrefixPath("/api/get", exchange -> { Map<String, Deque<String>> params = exchange.getQueryParameters(); List<Long[]> values = server.readSlice(params.get("metric").getFirst(), () -> { return new long[] { 0, System.currentTimeMillis() }; }); payload(exchange, params, values); }) .addPrefixPath("/api/get15s", exchange -> { Map<String, Deque<String>> params = exchange.getQueryParameters(); List<Long[]> values = server.readSlice(params.get("metric").getFirst(), () -> { DateTime dt = new DateTime(); DateTime offset = dt.minusSeconds(15); return new long[] { offset.getMillis(), System.currentTimeMillis() }; }); payload(exchange, params, values); }) .addPrefixPath("/api/get30s", exchange -> { Map<String, Deque<String>> params = exchange.getQueryParameters(); List<Long[]> values = server.readSlice(params.get("metric").getFirst(), () -> { DateTime dt = new DateTime(); DateTime offset = dt.minusSeconds(30); return new long[] { offset.getMillis(), System.currentTimeMillis() }; }); payload(exchange, params, values); }) .addPrefixPath("/api/get1m", exchange -> { Map<String, Deque<String>> params = exchange.getQueryParameters(); List<Long[]> values = server.readSlice(params.get("metric").getFirst(), () -> { DateTime dt = new DateTime(); DateTime offset = dt.minusMinutes(1); return new long[] { offset.getMillis(), System.currentTimeMillis() }; }); payload(exchange, params, values); }) .addPrefixPath("/api/get1h", exchange -> { Map<String, Deque<String>> params = exchange.getQueryParameters(); List<Long[]> values = server.readSlice(params.get("metric").getFirst(), () -> { DateTime dt = new DateTime(); DateTime offset = dt.minusHours(1); return new long[] { offset.getMillis(), System.currentTimeMillis() }; }); payload(exchange, params, values); }) .addPrefixPath("/", exchange -> { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); exchange.getResponseSender().send("Metric Server"); })) .build(); server.start(); http.start(); System.out.println("Press enter to exit ..."); System.in.read(); http.stop(); server.stop(); }
From source file:org.wso2.carbon.appmgt.gateway.handlers.security.saml2.IDPMessage.java
License:Open Source License
/** * Validates the 'Not Before' and 'Not On Or After' conditions of the SAML Assertion. * *///from w ww. ja va 2s . c om public boolean validateAssertionValidityPeriod() { boolean validateAssertionExpiry = SSOConfiguratorUtil.isValidateAssertionValidityPeriod(); if (validateAssertionExpiry) { Assertion assertion = null; Response response = (Response) samlResponse; List<Assertion> assertions = response.getAssertions(); if (CollectionUtils.isEmpty(assertions)) { if (log.isDebugEnabled()) { log.debug("SAML Response does not have assertions."); } return false; } assertion = assertions.get(0); DateTime validFrom = assertion.getConditions().getNotBefore(); DateTime validTill = assertion.getConditions().getNotOnOrAfter(); //skew time in seconds String timeStampSkewInConfig = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService() .getAPIManagerConfiguration() .getFirstProperty(AppMConstants.SSO_CONFIGURATION_RESPONSE_VALIDITY_TIME_STAMP_SKEW); if (timeStampSkewInConfig != null) { timeStampSkewInSeconds = Integer.parseInt(timeStampSkewInConfig); } if (validFrom != null && validFrom.minusSeconds(timeStampSkewInSeconds).isAfterNow()) { log.error("Failed to meet SAML Assertion Condition 'Not Before'"); return false; } if (validTill != null && validTill.plusSeconds(timeStampSkewInSeconds).isBeforeNow()) { log.error("Failed to meet SAML Assertion Condition 'Not On Or After'"); return false; } if (validFrom != null && validTill != null && validFrom.isAfter(validTill)) { log.error("SAML Assertion Condition 'Not Before' must be less than the value of 'Not On Or After'"); return false; } } return true; }
From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java
License:Open Source License
/** * Validates the 'Not Before' and 'Not On Or After' conditions of the SAML Assertion * * @param assertion SAML Assertion element * @throws ScriptException/* w w w . j a v a 2s .com*/ */ private boolean validateAssertionValidityPeriod(Assertion assertion, int timeStampSkewInSeconds) throws ScriptException { DateTime validFrom = assertion.getConditions().getNotBefore(); DateTime validTill = assertion.getConditions().getNotOnOrAfter(); if (validFrom != null && validFrom.minusSeconds(timeStampSkewInSeconds).isAfterNow()) { log.error("Failed to meet SAML Assertion Condition 'Not Before'"); return false; } if (validTill != null && validTill.plusSeconds(timeStampSkewInSeconds).isBeforeNow()) { log.error("Failed to meet SAML Assertion Condition 'Not On Or After'"); return false; } if (validFrom != null && validTill != null && validFrom.isAfter(validTill)) { log.error( "SAML Assertion Condition 'Not Before' must be less than the " + "value of 'Not On Or After'"); return false; } return true; }
From source file:org.wso2.carbon.identity.application.authenticator.passive.sts.manager.PassiveSTSManager.java
License:Open Source License
/** * Validates the 'Not Before' and 'Not On Or After' conditions of the SAML Assertion * * @param xmlObject parsed SAML entity/*from www . java2 s . co m*/ * @throws PassiveSTSException */ private void validateAssertionValidityPeriod(AuthenticationContext context, XMLObject xmlObject) throws PassiveSTSException { if (log.isDebugEnabled()) { log.debug("Validating SAML Assertion's 'Not Before' and 'Not On Or After' conditions."); } DateTime validFrom = null; DateTime validTill = null; if (xmlObject instanceof org.opensaml.saml1.core.Assertion) { org.opensaml.saml1.core.Assertion saml1Assertion = (org.opensaml.saml1.core.Assertion) xmlObject; if (saml1Assertion.getConditions() != null) { validFrom = saml1Assertion.getConditions().getNotBefore(); validTill = saml1Assertion.getConditions().getNotOnOrAfter(); } } else if (xmlObject instanceof org.opensaml.saml2.core.Assertion) { org.opensaml.saml2.core.Assertion saml2Assertion = (org.opensaml.saml2.core.Assertion) xmlObject; if (saml2Assertion.getConditions() != null) { validFrom = saml2Assertion.getConditions().getNotBefore(); validTill = saml2Assertion.getConditions().getNotOnOrAfter(); } } else { throw new PassiveSTSException( "Unknown Security Token. Can process only SAML 1.0 and SAML 2.0 Assertions"); } int clockSkewInSeconds = IdentityUtil.getClockSkewInSeconds(); if (validFrom != null && validFrom.minusSeconds(clockSkewInSeconds).isAfterNow()) { throw new PassiveSTSException("Failed to meet SAML Assertion Condition 'Not Before'"); } if (validTill != null && validTill.plusSeconds(clockSkewInSeconds).isBeforeNow()) { throw new PassiveSTSException("Failed to meet SAML Assertion Condition 'Not On Or After'"); } if (validFrom != null && validTill != null && validFrom.isAfter(validTill)) { throw new PassiveSTSException( "SAML Assertion Condition 'Not Before' must be less than the value of 'Not On Or After'"); } }
From source file:org.wso2.carbon.identity.authenticator.saml2.sso.SAML2SSOAuthenticator.java
License:Open Source License
/** * Validates the 'Not Before' and 'Not On Or After' conditions of the SAML Assertion * * @param xmlObject SAML Assertion element * @throws SAML2SSOAuthenticatorException *///from www. j a va 2 s . co m private void validateAssertionValidityPeriod(XMLObject xmlObject) throws SAML2SSOAuthenticatorException { Assertion assertion; if (xmlObject instanceof Response) { assertion = getAssertionFromResponse((Response) xmlObject); } else if (xmlObject instanceof Assertion) { assertion = (Assertion) xmlObject; } else { throw new SAML2SSOAuthenticatorException( "Only Response and Assertion objects are validated in this authenticator"); } if (assertion == null) { throw new SAML2SSOAuthenticatorException("Cannot find a SAML Assertion"); } if (assertion.getConditions() != null) { DateTime validFrom = assertion.getConditions().getNotBefore(); DateTime validTill = assertion.getConditions().getNotOnOrAfter(); int timeStampSkewInSeconds = getTimeStampSkewInSeconds(); if (validFrom != null && validFrom.minusSeconds(timeStampSkewInSeconds).isAfterNow()) { throw new SAML2SSOAuthenticatorException("Failed to meet SAML Assertion Condition 'Not Before'"); } if (validTill != null && validTill.plusSeconds(timeStampSkewInSeconds).isBeforeNow()) { throw new SAML2SSOAuthenticatorException( "Failed to meet SAML Assertion Condition 'Not On Or After'"); } if (validFrom != null && validTill != null && validFrom.isAfter(validTill)) { throw new SAML2SSOAuthenticatorException( "SAML Assertion Condition 'Not Before' must be less than the " + "value of 'Not On Or After'"); } } }
From source file:org.wso2.carbon.identity.sso.saml.validators.SPInitSSOAuthnRequestValidator.java
License:Open Source License
/** * Validating issueInstant time// w w w . ja va 2 s .c o m * @return */ private String validateRequestIssueInstant() { DateTime validFrom = authnReq.getIssueInstant(); if (validFrom == null) { return "IssueInstant time is not valid."; } DateTime validTill = validFrom.plusSeconds(SAMLSSOUtil.getSAMLAuthenticationRequestValidityPeriod()); int timeStampSkewInSeconds = IdentityUtil.getClockSkewInSeconds(); if (validFrom.minusSeconds(timeStampSkewInSeconds).isAfterNow()) { return "The request IssueInstant time is 'Not Before'"; } if (validTill != null && validTill.plusSeconds(timeStampSkewInSeconds).isBeforeNow()) { return "The request IssueInstant time is 'Not On Or After'"; } if (validTill != null && validFrom.isAfter(validTill)) { return "The request IssueInstant time is 'Not On Or After'"; } return null; }