List of usage examples for org.joda.time DateTime plusMinutes
public DateTime plusMinutes(int minutes)
From source file:org.openiam.idm.srvc.auth.sso.SAML1TokenModule.java
License:Open Source License
public SSOToken createToken(Map tokenParam) { String expectedID = "ident"; String tokenIssuer = (String) tokenParam.get("TOKEN_ISSUER"); String tokenLife = (String) tokenParam.get("TOKEN_LIFE"); int idleTime = Integer.parseInt(tokenLife.trim()); DateTime expectedIssueInstant = new DateTime(System.currentTimeMillis()); DateTime notAfterTime = new DateTime(System.currentTimeMillis()); notAfterTime = notAfterTime.plusMinutes(idleTime); final String userId = (String) tokenParam.get("USER_ID"); final String principal = (String) tokenParam.get("PRINCIPAL"); int expectedMinorVersion = 1; qname = Request.DEFAULT_ELEMENT_NAME; XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory(); // Get the assertion builder based on the assertion element name SAMLObjectBuilder<Assertion> builder = (SAMLObjectBuilder<Assertion>) builderFactory .getBuilder(Assertion.DEFAULT_ELEMENT_NAME); if (builder == null) { System.out.println("Unable to retrieve builder for object QName = " + qname); }//from www .ja va 2 s .c o m // Create the assertion Assertion assertion = builder.buildObject(); assertion.setIssuer(tokenIssuer); assertion.setVersion(SAMLVersion.VERSION_10); assertion.setID(UUIDGen.getUUID()); assertion.setIssueInstant(expectedIssueInstant); // conditions Conditions conditions = buildConditions(expectedIssueInstant, notAfterTime); assertion.setConditions(conditions); // authentication statement List<AuthenticationStatement> authStatements = assertion.getAuthenticationStatements(); authStatements.add(buildAuthenticateStatement(expectedIssueInstant, userId, tokenIssuer)); MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); // Get the Subject marshaller Marshaller marshaller = marshallerFactory.getMarshaller(assertion); // Marshall the Subject try { Element generatedDOM = marshaller.marshall(assertion, parser.newDocument()); SSOToken ssoTkn = new SSOToken(); ssoTkn.setToken(XMLHelper.nodeToString(generatedDOM)); ssoTkn.setExpirationTime(notAfterTime.toDate()); ssoTkn.setUserId(userId); ssoTkn.setPrincipal(principal); return ssoTkn; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.openiam.idm.srvc.auth.sso.SAML2TokenModule.java
License:Open Source License
public SSOToken createToken(Map tokenParam) { String expectedID = "ident"; DateTime expectedIssueInstant = new DateTime(System.currentTimeMillis()); DateTime notAfterTime = new DateTime(System.currentTimeMillis()); String tokenIssuer = (String) tokenParam.get("TOKEN_ISSUER"); String tokenLife = (String) tokenParam.get("TOKEN_LIFE"); int idleTime = Integer.parseInt(tokenLife.trim()); notAfterTime = notAfterTime.plusMinutes(idleTime); String userId = (String) tokenParam.get("USER_ID"); String principal = (String) tokenParam.get("PRINCIPAL"); int expectedMinorVersion = 1; qname = Request.DEFAULT_ELEMENT_NAME; XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory(); // Get the assertion builder based on the assertion element name SAMLObjectBuilder<Assertion> builder = (SAMLObjectBuilder<Assertion>) builderFactory .getBuilder(Assertion.DEFAULT_ELEMENT_NAME); if (builder == null) { System.out.println("Unable to retrieve builder for object QName = " + qname); }//from w ww . j a v a 2s. c o m // issuer builder IssuerBuilder ib = new IssuerBuilder(); Issuer issuer = ib.buildObject(); issuer.setValue(tokenIssuer); // Create the assertion Assertion assertion = builder.buildObject(); assertion.setVersion(SAMLVersion.VERSION_20); assertion.setIssuer(issuer); assertion.setID(UUIDGen.getUUID()); assertion.setIssueInstant(expectedIssueInstant); assertion.setSubject(this.buildSubject(userId, principal, tokenIssuer)); assertion.getAuthnStatements().add(buildAuthenticateStatement(expectedIssueInstant, userId)); assertion.setConditions(this.buildConditions(expectedIssueInstant, notAfterTime)); MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); // Get the Subject marshaller Marshaller marshaller = marshallerFactory.getMarshaller(assertion); // Marshall the Subject try { Element generatedDOM = marshaller.marshall(assertion, parser.newDocument()); SSOToken ssoTkn = new SSOToken(); String saml = XMLHelper.nodeToString(generatedDOM); int index = saml.indexOf(">"); String str = saml.substring(index + 1); ssoTkn.setToken(str); ssoTkn.setExpirationTime(notAfterTime.toDate()); ssoTkn.setPrincipal(principal); ssoTkn.setUserId(userId); return ssoTkn; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.opensaml.soap.wssecurity.impl.WSSecurityObjectsTestCase.java
License:Open Source License
@Test public void testTimestamp() throws Exception { Timestamp timestamp = buildXMLObject(Timestamp.ELEMENT_NAME); Created created = buildXMLObject(Created.ELEMENT_NAME); DateTime now = new DateTime(); created.setDateTime(now);// ww w. j a v a 2 s .c om timestamp.setCreated(created); Expires expires = buildXMLObject(Expires.ELEMENT_NAME); expires.setDateTime(now.plusMinutes(10)); timestamp.setExpires(expires); timestamp.setWSUId("Timestamp-" + System.currentTimeMillis()); marshallAndUnmarshall(timestamp); }
From source file:org.opensaml.ws.wssecurity.WSSecurityObjectsTestCase.java
License:Apache License
public void testTimestamp() throws Exception { Timestamp timestamp = buildXMLObject(Timestamp.ELEMENT_NAME); Created created = buildXMLObject(Created.ELEMENT_NAME); DateTime now = new DateTime(); created.setDateTime(now);// w w w . j a v a 2s.c om timestamp.setCreated(created); Expires expires = buildXMLObject(Expires.ELEMENT_NAME); expires.setDateTime(now.plusMinutes(10)); timestamp.setExpires(expires); timestamp.setWSUId("Timestamp-" + System.currentTimeMillis()); marshallAndUnmarshall(timestamp); }
From source file:org.oxymores.chronix.core.State.java
License:Apache License
public void run(Place p, MessageProducer pjProducer, Session session, String calendarOccurrenceID, boolean updateCalendarPointer, boolean outOfPlan, boolean outOfChainLaunch, UUID level0Id, UUID level1Id, UUID level2Id, UUID level3Id, CalendarPointer cpToUpdate, Date virtualTime, EnvironmentValue... params) {/*from w ww.ja v a2 s . c o m*/ DateTime now = DateTime.now(); PipelineJob pj = new PipelineJob(); // Common fields pj.setLevel0IdU(level0Id); pj.setLevel1IdU(level1Id); pj.setLevel2IdU(level2Id); pj.setLevel3IdU(level3Id); pj.setMarkedForRunAt(now.toDate()); pj.setPlace(p); pj.setState(this); pj.setStatus("ENTERING_QUEUE"); pj.setApplication(this.application); pj.setOutsideChain(outOfChainLaunch); pj.setIgnoreCalendarUpdating(!updateCalendarPointer); pj.setOutOfPlan(outOfPlan); pj.setVirtualTime(virtualTime); // Warning and kill if (this.warnAfterMn != null) { pj.setWarnNotEndedAt(now.plusMinutes(this.warnAfterMn).toDate()); } else { pj.setWarnNotEndedAt(now.plusDays(1).toDate()); } if (this.killAfterMn != null) { pj.setKillAt(now.plusMinutes(this.killAfterMn).toDate()); } // Environment variables from the State itself for (EnvironmentParameter ep : this.envParams) { pj.addValue(ep.key, ep.value); } // Environment variables passed from other jobs through the event (or // manually set) for (EnvironmentValue ep : params) { if (ep.getKey().startsWith("CHR_")) { // Don't propagate auto variables continue; } pj.addValue(ep.getKey(), ep.getValue()); } // Environment variables auto pj.addValue("CHR_STATEID", this.id.toString()); pj.addValue("CHR_CHAINID", this.chain.id.toString()); pj.addValue("CHR_LAUNCHID", pj.getId()); pj.addValue("CHR_JOBNAME", this.represents.name); pj.addValue("CHR_PLACEID", p.id.toString()); pj.addValue("CHR_PLACENAME", p.name); pj.addValue("CHR_PLACEGROUPID", this.runsOn.id.toString()); pj.addValue("CHR_PLACEGROUPNAME", this.runsOn.name); // Calendar update if (this.usesCalendar()) { pj.setCalendarOccurrenceID(calendarOccurrenceID); pj.setCalendar(calendar); log.debug("Since this state will run, calendar update!"); cpToUpdate.setRunning(true); if (updateCalendarPointer) { cpToUpdate.setLastStartedOccurrenceId(cpToUpdate.getNextRunOccurrenceId()); } pj.addValue(Constants.ENV_AUTO_CHR_CALENDAR, this.calendar.name); pj.addValue(Constants.ENV_AUTO_CHR_CHR_CALENDARID, this.calendar.id.toString()); pj.addValue(Constants.ENV_AUTO_CHR_CHR_CALENDARDATE, cpToUpdate.getNextRunOccurrenceId()); } else { pj.addValue(Constants.ENV_AUTO_CHR_CALENDAR, "NONE"); pj.addValue(Constants.ENV_AUTO_CHR_CHR_CALENDARID, "NONE"); pj.addValue(Constants.ENV_AUTO_CHR_CHR_CALENDARDATE, "NONE"); } // Send it (commit is done by main engine later) String qName = String.format(Constants.Q_PJ, p.getNode().getBrokerName()); try { SenderHelpers.sendPipelineJobToRunner(pj, p.getNode().getHost(), pjProducer, session, false); } catch (JMSException e1) { log.error( "Could not enqueue a state for launch. Scheduler will still go on, but this may affect its operations.", e1); } // Done log.debug(String.format("State (%s - chain %s) was enqueued for launch on place %s (queue %s)", this.represents.getName(), this.chain.getName(), p.name, qName)); }
From source file:org.sakaiproject.rubrics.logic.impl.RubricsServiceImpl.java
License:Educational Community License
public String generateJsonWebToken(String tool) { String token = null;/*from ww w . j av a 2 s. c om*/ String userId = sessionManager.getCurrentSessionUserId(); try { String siteId = toolManager.getCurrentPlacement().getContext(); DateTime now = DateTime.now(); JWTCreator.Builder jwtBuilder = JWT.create(); jwtBuilder.withIssuer(JWT_ISSUER).withAudience(JWT_AUDIENCE).withSubject(userId) .withClaim(JWT_CUSTOM_CLAIM_TOOL_ID, tool) .withClaim(JWT_CUSTOM_CLAIM_SESSION_ID, sessionManager.getCurrentSession().getId()) .withIssuedAt(now.toDate()); int sessionTimeoutInSeconds = sessionManager.getCurrentSession().getMaxInactiveInterval(); if (sessionTimeoutInSeconds > 0) { jwtBuilder.withExpiresAt(now.plusSeconds(sessionTimeoutInSeconds).toDate()); } else { // if Sakai is configured for sessions to never timeout (negative value), we will set 30 minutes for // tokens - the rubrics service will check Sakai session validity if it receives an expired token. jwtBuilder.withExpiresAt(now.plusMinutes(30).toDate()); } if (securityService.isSuperUser()) { jwtBuilder.withArrayClaim(JWT_CUSTOM_CLAIM_ROLES, new String[] { RBCS_PERMISSIONS_EDITOR, RBCS_PERMISSIONS_ASSOCIATOR, RBCS_PERMISSIONS_EVALUATOR, RBCS_PERMISSIONS_EVALUEE, RBCS_PERMISSIONS_SUPERUSER }); } else { List<String> roles = new ArrayList<>(); if (authzGroupService.isAllowed(userId, RBCS_PERMISSIONS_EDITOR, "/site/" + siteId)) { roles.add(RBCS_PERMISSIONS_EDITOR); } if (authzGroupService.isAllowed(userId, RBCS_PERMISSIONS_ASSOCIATOR, "/site/" + siteId)) { roles.add(RBCS_PERMISSIONS_ASSOCIATOR); } if (authzGroupService.isAllowed(userId, RBCS_PERMISSIONS_EVALUATOR, "/site/" + siteId)) { roles.add(RBCS_PERMISSIONS_EVALUATOR); } if (authzGroupService.isAllowed(userId, RBCS_PERMISSIONS_EVALUEE, "/site/" + siteId)) { roles.add(RBCS_PERMISSIONS_EVALUEE); } jwtBuilder.withArrayClaim(JWT_CUSTOM_CLAIM_ROLES, roles.toArray(new String[] {})); } jwtBuilder.withClaim(JWT_CUSTOM_CLAIM_CONTEXT_ID, siteId); jwtBuilder.withClaim(JWT_CUSTOM_CLAIM_CONTEXT_TYPE, SITE_CONTEXT_TYPE); token = jwtBuilder.sign(Algorithm .HMAC256(serverConfigurationService.getString(RUBRICS_TOKEN_SIGNING_SHARED_SECRET_PROPERTY))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(String.format( "An error occurred while generating a JSON Web Token to " + "authorize communication with the Rubrics service. Please verify the %s property is " + "defined in the sakai.properties file.", RUBRICS_TOKEN_SIGNING_SHARED_SECRET_PROPERTY), e); } return token; }
From source file:org.sakaiproject.rubrics.logic.RubricsServiceImpl.java
License:Educational Community License
public String generateJsonWebToken(String tool, String siteId) { String token = null;/*from w w w.j ava2 s . c o m*/ String userId = sessionManager.getCurrentSessionUserId(); try { DateTime now = DateTime.now(); JWTCreator.Builder jwtBuilder = JWT.create(); jwtBuilder.withIssuer(JWT_ISSUER).withAudience(JWT_AUDIENCE).withSubject(userId) .withClaim(JWT_CUSTOM_CLAIM_TOOL_ID, tool) .withClaim(JWT_CUSTOM_CLAIM_SESSION_ID, sessionManager.getCurrentSession().getId()) .withIssuedAt(now.toDate()); int sessionTimeoutInSeconds = sessionManager.getCurrentSession().getMaxInactiveInterval(); if (sessionTimeoutInSeconds > 0) { jwtBuilder.withExpiresAt(now.plusSeconds(sessionTimeoutInSeconds).toDate()); } else { // if Sakai is configured for sessions to never timeout (negative value), we will set 30 minutes for // tokens - the rubrics service will check Sakai session validity if it receives an expired token. jwtBuilder.withExpiresAt(now.plusMinutes(30).toDate()); } if (securityService.isSuperUser()) { jwtBuilder.withArrayClaim(JWT_CUSTOM_CLAIM_ROLES, new String[] { RBCS_PERMISSIONS_EDITOR, RBCS_PERMISSIONS_ASSOCIATOR, RBCS_PERMISSIONS_EVALUATOR, RBCS_PERMISSIONS_EVALUEE, RBCS_PERMISSIONS_SUPERUSER }); } else { List<String> roles = new ArrayList<>(); if (authzGroupService.isAllowed(userId, RBCS_PERMISSIONS_EDITOR, "/site/" + siteId)) { roles.add(RBCS_PERMISSIONS_EDITOR); } if (authzGroupService.isAllowed(userId, RBCS_PERMISSIONS_ASSOCIATOR, "/site/" + siteId)) { roles.add(RBCS_PERMISSIONS_ASSOCIATOR); } if (authzGroupService.isAllowed(userId, RBCS_PERMISSIONS_EVALUATOR, "/site/" + siteId)) { roles.add(RBCS_PERMISSIONS_EVALUATOR); } if (authzGroupService.isAllowed(userId, RBCS_PERMISSIONS_EVALUEE, "/site/" + siteId)) { roles.add(RBCS_PERMISSIONS_EVALUEE); } jwtBuilder.withArrayClaim(JWT_CUSTOM_CLAIM_ROLES, roles.toArray(new String[] {})); } jwtBuilder.withClaim(JWT_CUSTOM_CLAIM_CONTEXT_ID, siteId); jwtBuilder.withClaim(JWT_CUSTOM_CLAIM_CONTEXT_TYPE, SITE_CONTEXT_TYPE); token = jwtBuilder.sign(Algorithm .HMAC256(serverConfigurationService.getString(RUBRICS_TOKEN_SIGNING_SHARED_SECRET_PROPERTY))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(String.format( "An error occurred while generating a JSON Web Token to " + "authorize communication with the Rubrics service. Please verify the %s property is " + "defined in the sakai.properties file.", RUBRICS_TOKEN_SIGNING_SHARED_SECRET_PROPERTY), e); } return token; }
From source file:org.slc.sli.sandbox.idp.saml.SamlResponseComposer.java
License:Apache License
private String createUnsignedResponse(String destination, String issuer, String requestId, String userId, Map<String, String> attributes, List<String> roles) { String template;/* ww w . j av a 2s.c o m*/ try { template = IOUtils.toString(this.getClass().getResourceAsStream("/samlResponseTemplate.xml")); } catch (IOException e) { throw new SamlProcessException(e); } template = template.replace("__RESPONSE_ID__", UUID.randomUUID().toString()); template = template.replace("__ASSERTION_ID__", UUID.randomUUID().toString()); template = template.replace("__REQUEST_ID__", requestId); template = template.replace("__ISSUE_INSTANT__", new DateTime().withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.dateTimeNoMillis())); template = template.replace("__DESTINATION__", destination); template = template.replace("__ISSUER__", issuer); template = template.replace("__TRANSIENT_ID__", UUID.randomUUID().toString()); //must be at least a 128-bit random string DateTime notOnOrAfter = new DateTime(); notOnOrAfter = notOnOrAfter.plusMinutes(10); template = template.replace("__NOT_ON_OR_AFTER__", notOnOrAfter.withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.dateTimeNoMillis())); StringBuilder buf = new StringBuilder(); addAttribute(buf, "userId", userId); if (attributes != null) { for (Map.Entry<String, String> attr : attributes.entrySet()) { if (attr.getKey() != null && attr.getValue() != null) { addAttribute(buf, attr.getKey(), attr.getValue()); } } } if (roles != null && !roles.isEmpty()) { buf.append(ATTRIBUTE_NAME_BEGIN_TEMPLATE.replace("__NAME__", "roles")); for (String role : roles) { buf.append(ATTRIBUTE_VALUE_TEMPLATE.replace("__VALUE__", role)); } buf.append(ATTRIBUTE_NAME_END_TEMPLATE); } template = template.replace("__ATTRIBUTES__", buf.toString()); return template; }
From source file:org.smallmind.javafx.extras.instrument.TimeAxis.java
License:Open Source License
@Override protected List<Long> calculateTickValues(double length, Object range) { LinkedList<Long> ticks = new LinkedList<Long>(); DateTime origin = new DateTime(((EndPoints<Long>) range).getLow()).withMillisOfSecond(0); DateTime bound = new DateTime(((EndPoints<Long>) range).getHigh()); int majorInterval; if ((majorInterval = (origin.getSecondOfMinute() / 15) + 1) < 4) { origin = origin.withSecondOfMinute(majorInterval * 15); } else {/* ww w . ja va 2s . c om*/ origin = origin.plusMinutes(1).withSecondOfMinute(0); } while (origin.isBefore(bound)) { ticks.add(origin.getMillis()); origin = origin.plusSeconds(15); } return ticks; }
From source file:org.smallmind.javafx.extras.instrument.TimeAxis.java
License:Open Source License
@Override protected List<Long> calculateMinorTickMarks() { LinkedList<Long> ticks = new LinkedList<Long>(); Object range = getRange();/*from w w w.j a va 2s .c o m*/ DateTime origin = new DateTime(((EndPoints<Long>) range).getLow()).withMillisOfSecond(0); DateTime bound = new DateTime(((EndPoints<Long>) range).getHigh()); int minorInterval; if ((minorInterval = (origin.getSecondOfMinute() / 5) + 1) < 12) { origin = origin.withSecondOfMinute(minorInterval * 5); } else { origin = origin.plusMinutes(1).withSecondOfMinute(0); } while (origin.isBefore(bound)) { if ((origin.getSecondOfMinute() % 15) != 0) { ticks.add(origin.getMillis()); } origin = origin.plusSeconds(5); } return ticks; }