List of usage examples for org.joda.time DateTime plusMillis
public DateTime plusMillis(int millis)
From source file:com.quinsoft.zeidon.domains.DateTimeDomain.java
License:Open Source License
/** * Adds milliseconds to the datetime value. *///from w w w .ja v a2 s .co m @Override public Object addToAttribute(Task task, AttributeInstance attributeInstance, AttributeDef attributeDef, Object currentValue, Object addValue) { DateTime date1 = (DateTime) convertExternalValue(task, attributeInstance, attributeDef, null, currentValue); if (date1 == null) throw new ZeidonException("Target attribute for add is NULL").prependAttributeDef(attributeDef); if (addValue == null) return date1; if (addValue instanceof Number) { int millis = ((Number) addValue).intValue(); return date1.plusMillis(millis); } throw new ZeidonException("Value type of %s not supported for add to DateDomain", addValue.getClass().getName()); }
From source file:com.tremolosecurity.provisioning.sharepoint.SharePointGroups.java
License:Apache License
private UserGroupSoap getConnection(URL url) throws Exception { UserGroup ss = new UserGroup(wsdl.toURI().toURL(), SERVICE); UserGroupSoap port = ss.getUserGroupSoap12(); BindingProvider provider = (BindingProvider) port; if (authType == AuthType.UnisonLastMile) { DateTime now = new DateTime(); DateTime future = now.plusMillis(this.skew); now = now.minusMillis(skew);// ww w .j av a 2 s . co m com.tremolosecurity.lastmile.LastMile lastmile = new com.tremolosecurity.lastmile.LastMile( url.getPath(), now, future, 0, "chainName"); lastmile.getAttributes().add(new Attribute("userPrincipalName", this.administratorUPN)); SecretKey sk = this.cfg.getSecretKey(this.keyAlias); Map<String, List<String>> headers = (Map<String, List<String>>) provider.getRequestContext() .get(MessageContext.HTTP_REQUEST_HEADERS); if (headers == null) { headers = new HashMap<String, List<String>>(); } headers.put(this.headerName, Collections.singletonList(lastmile.generateLastMileToken(sk))); provider.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers); } else if (authType == AuthType.NTLM) { NtlmAuthenticator authenticator = new NtlmAuthenticator(this.administratorUPN, this.administratorPassword); Authenticator.setDefault(authenticator); } provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString()); return port; }
From source file:com.tremolosecurity.provisioning.sharepoint.SharePointGroups.java
License:Apache License
private void touch(String upn) throws Exception { if (this.authType == AuthType.UnisonLastMile) { DateTime now = new DateTime(); DateTime future = now.plusMillis(this.skew); now = now.minusMillis(skew);/*w ww .j a v a 2s . c om*/ com.tremolosecurity.lastmile.LastMile lastmile = new com.tremolosecurity.lastmile.LastMile( "/Pages/Default.aspx", now, future, 0, "chainName"); lastmile.getAttributes().add(new Attribute("userPrincipalName", upn)); SecretKey sk = this.cfg.getSecretKey(this.keyAlias); DefaultHttpClient http = new DefaultHttpClient(); HttpGet get = new HttpGet(this.touchURL); get.addHeader(this.headerName, lastmile.generateLastMileToken(sk)); http.execute(get); } else { } }
From source file:com.tremolosecurity.proxy.auth.persistentCookie.PersistentCookieResult.java
License:Apache License
@Override public void createResultCookie(Cookie cookie, HttpServletRequest request, HttpServletResponse response) throws ServletException { UrlHolder holder = (UrlHolder) request.getAttribute(ProxyConstants.AUTOIDM_CFG); ConfigManager mgr = holder.getConfig(); HashSet<String> mechs = new HashSet<String>(); for (String mechName : mgr.getAuthMechs().keySet()) { MechanismType mech = mgr.getAuthMechs().get(mechName); if (mech.getClassName() .equalsIgnoreCase("com.tremolosecurity.proxy.auth.persistentCookie.PersistentCookie")) { mechs.add(mechName);//ww w .j a v a2s. c o m } } AuthController authCtl = (AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL); String chainName = authCtl.getAuthInfo().getAuthChain(); AuthChainType chain = mgr.getAuthChains().get(chainName); int millisToLive = 0; String keyAlias = ""; boolean useSSLSession = false; for (AuthMechType amt : chain.getAuthMech()) { if (mechs.contains(amt.getName())) { for (ParamType pt : amt.getParams().getParam()) { if (pt.getName().equalsIgnoreCase("millisToLive")) { millisToLive = Integer.parseInt(pt.getValue()); } if (pt.getName().equalsIgnoreCase("useSSLSessionID") && pt.getValue().equalsIgnoreCase("true")) { useSSLSession = true; } else if (pt.getName().equalsIgnoreCase("keyAlias")) { keyAlias = pt.getValue(); } } } } DateTime now = new DateTime(); DateTime expires = now.plusMillis(millisToLive); com.tremolosecurity.lastmile.LastMile lastmile = null; try { lastmile = new com.tremolosecurity.lastmile.LastMile("/", now, expires, 0, "NONE"); } catch (URISyntaxException e) { //not possible } lastmile.getAttributes().add(new Attribute("DN", authCtl.getAuthInfo().getUserDN())); lastmile.getAttributes().add(new Attribute("CLIENT_IP", request.getRemoteAddr())); if (useSSLSession) { Object sessionID = request.getAttribute("javax.servlet.request.ssl_session_id"); if (sessionID instanceof byte[]) { sessionID = new String(Base64.encodeBase64((byte[]) sessionID)); } lastmile.getAttributes().add(new Attribute("SSL_SESSION_ID", (String) sessionID)); } try { cookie.setValue(new StringBuilder().append('"') .append(lastmile.generateLastMileToken(mgr.getSecretKey(keyAlias))).append('"').toString()); } catch (Exception e) { throw new ServletException("Could not encrypt persistent cookie", e); } cookie.setMaxAge(millisToLive / 1000); }
From source file:com.tremolosecurity.unison.filter.CatchFirstLogin.java
License:Apache License
@Override public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception { HttpSession session = request.getSession(); if (session.getAttribute(key) == null) { AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)) .getAuthInfo();/* www. j a va2 s . c o m*/ Attribute attr = userData.getAttribs().get("userPrincipalName"); if (attr == null) { throw new Exception("User has not userPrincipalName attribute"); } DateTime now = new DateTime(); DateTime future = now.plusMillis(this.skew); now = now.minusMillis(skew); com.tremolosecurity.lastmile.LastMile lastmile = new com.tremolosecurity.lastmile.LastMile( "/Pages/Default.aspx", now, future, 0, "chainName"); lastmile.getAttributes().add(new Attribute("userPrincipalName", attr.getValues().get(0))); SecretKey sk = this.cfg.getSecretKey(this.keyAlias); DefaultHttpClient http = new DefaultHttpClient(); HttpGet get = new HttpGet(this.touchURL); get.addHeader(this.headerName, lastmile.generateLastMileToken(sk)); HttpResponse resp = http.execute(get); BufferedReader in = new BufferedReader(new InputStreamReader(resp.getEntity().getContent())); ByteArrayOutputStream baos = new ByteArrayOutputStream(); String line = null; while ((line = in.readLine()) != null) { baos.write(line.getBytes("UTF-8")); baos.write('\n'); } in.close(); String txt = new String(baos.toByteArray()); if (txt.contains("An unexpected error has occured")) { response.sendRedirect(this.redirectURI); chain.setLogout(true); chain.setNoProxy(true); return; } session.setAttribute(key, key); } chain.nextFilter(request, response, chain); }
From source file:com.tripadvisor.seekbar.ClockView.java
License:Apache License
public void setBounds(DateTime minTime, DateTime maxTime, boolean isMaxClock) { // NOTE: To show correct end time on clock, since the Interval.contains() checks for // millisInstant >= thisStart && millisInstant < thisEnd // however we want // millisInstant >= thisStart && millisInstant <= thisEnd maxTime = maxTime.plusMillis(1); mValidTimeInterval = new Interval(minTime, maxTime); maxTime = maxTime.minusMillis(1);//from ww w . j av a2 s. c o m mCircularClockSeekBar.reset(); if (isMaxClock) { mOriginalTime = maxTime; mCurrentValidTime = maxTime; int hourOfDay = maxTime.get(DateTimeFieldType.clockhourOfDay()) % 12; mCircularClockSeekBar.setProgress(hourOfDay * 10); setClockText(mOriginalTime); } else { mOriginalTime = minTime; mCurrentValidTime = minTime; int hourOfDay = minTime.get(DateTimeFieldType.clockhourOfDay()) % 12; mCircularClockSeekBar.setProgress(hourOfDay * 10); setClockText(mOriginalTime); } }
From source file:com.vaushell.superpipes.nodes.buffer.N_Buffer.java
License:Open Source License
private void pushMessage(final Message message) throws IOException { final DateTime now = new DateTime(); final Duration delta; if (getProperties().containsKey("wait-min") && getProperties().containsKey("wait-max")) { final int waitMin = getProperties().getConfigInteger("wait-min"); final int waitMax = getProperties().getConfigInteger("wait-max"); if (waitMin == waitMax) { delta = new Duration((long) waitMin); } else {/*w w w . ja v a 2 s . c o m*/ delta = new Duration((long) (rnd.nextInt(waitMax - waitMin) + waitMin)); } } else { delta = new Duration(0L); } final DateTime ID; if (messageIDs.isEmpty()) { ID = now.plus(delta); } else { final DateTime askedTime = now.plus(delta); final long lastID = messageIDs.last(); final DateTime lastTime = new DateTime(lastID); if (askedTime.isBefore(lastTime)) { ID = lastTime.plusMillis(1); } else { ID = askedTime; } } final Path p = messagesPath.resolve(Long.toString(ID.getMillis())); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] write message with ID=" + ID); } writeMessage(p, message); messageIDs.add(ID.getMillis()); }
From source file:demo.sts.provider.token.Saml1TokenProvider.java
License:Apache License
private org.opensaml.saml1.core.Assertion createAuthnAssertionSAML1(org.opensaml.saml1.core.Subject subject) { org.opensaml.saml1.core.AuthenticationStatement authnStatement = (new org.opensaml.saml1.core.impl.AuthenticationStatementBuilder()) .buildObject();/* w ww. ja v a 2s . co m*/ authnStatement.setSubject(subject); // authnStatement.setAuthenticationMethod(strAuthMethod); DateTime now = new DateTime(); authnStatement.setAuthenticationInstant(now); org.opensaml.saml1.core.Conditions conditions = (new org.opensaml.saml1.core.impl.ConditionsBuilder()) .buildObject(); conditions.setNotBefore(now.minusMillis(3600000)); conditions.setNotOnOrAfter(now.plusMillis(3600000)); String issuerURL = "http://www.sopera.de/SAML1"; org.opensaml.saml1.core.Assertion assertion = (new org.opensaml.saml1.core.impl.AssertionBuilder()) .buildObject(); try { SecureRandomIdentifierGenerator generator = new SecureRandomIdentifierGenerator(); assertion.setID(generator.generateIdentifier()); } catch (NoSuchAlgorithmException e) { LOG.log(Level.WARNING, e.getMessage(), e); } assertion.setIssuer(issuerURL); assertion.setIssueInstant(now); assertion.setVersion(SAMLVersion.VERSION_11); assertion.getAuthenticationStatements().add(authnStatement); // assertion.getAttributeStatements().add(attrStatement); assertion.setConditions(conditions); return assertion; }
From source file:demo.sts.provider.token.Saml2TokenProvider.java
License:Apache License
private Assertion createAssertion(Subject subject) { Assertion assertion = (new AssertionBuilder()).buildObject(); try {/*from w w w .ja v a 2 s . c o m*/ SecureRandomIdentifierGenerator generator = new SecureRandomIdentifierGenerator(); assertion.setID(generator.generateIdentifier()); } catch (NoSuchAlgorithmException e) { LOG.log(Level.WARNING, e.getMessage(), e); } DateTime now = new DateTime(); assertion.setIssueInstant(now); String issuerURL = "http://www.sopera.de/SAML2"; if (issuerURL != null) { Issuer issuer = (new IssuerBuilder()).buildObject(); issuer.setValue(issuerURL); assertion.setIssuer(issuer); } assertion.setSubject(subject); Conditions conditions = (new ConditionsBuilder()).buildObject(); conditions.setNotBefore(now.minusMillis(3600000)); conditions.setNotOnOrAfter(now.plusMillis(3600000)); assertion.setConditions(conditions); return assertion; }
From source file:es.usc.citius.servando.calendula.DailyAgendaRecyclerAdapter.java
License:Open Source License
boolean isAvailable(DateTime time) { DateTime now = DateTime.now();//from w w w.j a v a 2 s . c o m return time.isBefore(now) && time.plusMillis((int) window * 60 * 1000).isAfter(now); }