List of usage examples for java.util SimpleTimeZone SimpleTimeZone
public SimpleTimeZone(int rawOffset, String ID)
From source file:xc.mst.oai.Facade.java
private String getHeader(Record record) { StringBuilder header = new StringBuilder(); header.append("<header>\n"); // Inject service to get OAI identifier record.setService(service);/*w ww . ja va 2s . com*/ header.append("\t<identifier>").append(record.getOaiIdentifier()).append("</identifier>\n"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC")); header.append("\t<datestamp>").append(sdf.format(record.getUpdatedAt())).append("</datestamp>\n"); // Get each set from the list of set IDs this record belongs to. If the set is // not null, add its setSpec to the header. SortedSet<String> setSpecs = new TreeSet<String>(); for (Set s : record.getSets()) if (s != null) setSpecs.add(s.getSetSpec()); for (String setSpec : setSpecs) { header.append("\t<setSpec>").append(setSpec).append("</setSpec>\n"); } header.append("</header>"); return header.toString(); }
From source file:org.dasein.cloud.aws.AWSCloud.java
public String getV4HeaderDate(Date date) { SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'"); Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); fmt.setCalendar(cal);/* w ww. j av a2s .c o m*/ if (date == null) { return fmt.format(new Date()); } else { return fmt.format(date); } }
From source file:com.qut.middleware.esoe.sso.impl.SSOProcessorImpl.java
private Response createSuccessfulAuthnResponseObject(SSOProcessorData data, String sessionIndex, String charset, boolean signed) throws SSOException { Principal principal = data.getPrincipal(); if (principal == null) { throw new SSOException("SSO response being generated for null principal. Unable to continue."); }/*from w w w . j a v a2 s .c o m*/ String remoteAddress = data.getRemoteAddress(); this.logger.debug("[SSO for {}] Creating successful Authn response.", remoteAddress); AuthnStatement authnStatement = new AuthnStatement(); SubjectLocality subjectLocality = new SubjectLocality(); AuthnContext authnContext = new AuthnContext(); Subject subject = new Subject(); NameIDType issuer = new NameIDType(); NameIDType nameID = new NameIDType(); Signature signature = new Signature(); Conditions conditions = new Conditions(); Assertion assertion = new Assertion(); Status status = new Status(); StatusCode statusCode = new StatusCode(); Response response = new Response(); /* Generate subject locality */ subjectLocality.setDNSName(data.getHttpRequest().getServerName()); /* * Generate AuthnContext, SAML spec requires previous session to be set if user not directly authenticated * during this transaction */ TimeZone utc = new SimpleTimeZone(0, ConfigurationConstants.timeZone); GregorianCalendar cal = new GregorianCalendar(utc); long thisTime = cal.getTimeInMillis(); if (thisTime - principal.getAuthnTimestamp() > this.allowedTimeSkew) authnContext.setAuthnContextClassRef(AuthenticationContextConstants.previousSession); else authnContext.setAuthnContextClassRef(principal.getAuthenticationContextClass()); /* Generate successful authentication response for consumption by SPEP */ authnStatement.setAuthnInstant(CalendarUtils.generateXMLCalendar(0)); authnStatement.setSessionIndex(sessionIndex); /* Add our allowed time skew to the current time */ // TODO check that this is still accurate authnStatement .setSessionNotOnOrAfter(CalendarUtils.generateXMLCalendar(principal.getSessionNotOnOrAfter())); authnStatement.setSubjectLocality(subjectLocality); authnStatement.setAuthnContext(authnContext); /* Generate Issuer to attach to assertion and response */ issuer.setValue(this.esoeIdentifier); issuer.setFormat(NameIDFormatConstants.entity); /* populate subject to attach to assertion */ boolean setNameID = false; /** * If we're dealing with google insert mail identifier specially now and in special format until they correct * their problems */ if (data.getAuthnRequest().getIssuer().getValue().contains("google")) { /* Figure out what value we should try and get from the principals attributes - google wants email */ String attribName = this.identifierAttributeMapping.get(NameIDFormatConstants.emailAddress); if (attribName != null) { IdentityAttribute identityAttribute = principal.getAttributes().get(attribName); if (identityAttribute != null) { List<Object> attribValues = identityAttribute.getValues(); if (attribValues != null && attribValues.size() > 0) { String completeEmailAddress = (String) attribValues.get(0); int indAt = completeEmailAddress.indexOf('@'); nameID.setValue(completeEmailAddress.substring(0, indAt)); nameID.setFormat(NameIDFormatConstants.emailAddress); setNameID = true; } } } } else { if (data.getValidIdentifiers() != null) { this.logger.debug( "Got valid identifiers from Metadata or request, attempting to find appropriate value"); for (String identifier : data.getValidIdentifiers()) { if (NameIDFormatConstants.trans.equals(identifier)) { this.logger.info("Sending AuthnStatement with transient identifier"); nameID.setValue(principal.getSAMLAuthnIdentifier()); nameID.setFormat(NameIDFormatConstants.trans); setNameID = true; break; } /* Figure out what value we should try and get from the principals attributes */ String attribName = this.identifierAttributeMapping.get(identifier); if (attribName != null) { IdentityAttribute identityAttribute = principal.getAttributes().get(attribName); if (identityAttribute != null) { List<Object> attribValues = identityAttribute.getValues(); if (attribValues != null && attribValues.size() > 0) { this.logger.info("Sending AuthnStatement with identifier of type " + identifier); /* Use the first value if there are multiples */ nameID.setValue((String) attribValues.get(0)); nameID.setFormat(identifier); setNameID = true; break; } } } } } } /* We couldn't figure out an identifier to response with, so send transient identifier */ if (!setNameID) { nameID.setValue(principal.getSAMLAuthnIdentifier()); nameID.setFormat(NameIDFormatConstants.trans); } subject.setNameID(nameID); /* subject MUST contain a SubjectConfirmation */ SubjectConfirmation confirmation = new SubjectConfirmation(); confirmation.setMethod(ConfirmationMethodConstants.bearer); SubjectConfirmationDataType confirmationData = new SubjectConfirmationDataType(); confirmationData.setRecipient(data.getResponseEndpoint()); confirmationData.setInResponseTo(data.getAuthnRequest().getID()); confirmationData.setNotOnOrAfter(CalendarUtils.generateXMLCalendar(principal.getSessionNotOnOrAfter())); confirmation.setSubjectConfirmationData(confirmationData); subject.getSubjectConfirmationNonID().add(confirmation); /* Set conditions on the response. Restrict audience to the SPEP recieving this Response. */ conditions.setNotOnOrAfter(CalendarUtils.generateXMLCalendar(this.allowedTimeSkew)); List<ConditionAbstractType> audienceRestrictions = conditions .getConditionsAndOneTimeUsesAndAudienceRestrictions(); AudienceRestriction restrict = new AudienceRestriction(); restrict.getAudiences().add(data.getIssuerID()); audienceRestrictions.add(restrict); /* set assertion values */ assertion.setConditions(conditions); assertion.setVersion(VersionConstants.saml20); assertion.setID(this.identifierGenerator.generateSAMLID()); assertion.setIssueInstant(CalendarUtils.generateXMLCalendar(0)); assertion.setIssuer(issuer); assertion.setSignature(signature); assertion.setSubject(subject); assertion.getAuthnStatementsAndAuthzDecisionStatementsAndAttributeStatements().add(authnStatement); /* Generate successful status, only top level code supplied */ statusCode.setValue(StatusCodeConstants.success); status.setStatusCode(statusCode); /* Generate our response */ response.setID(this.identifierGenerator.generateSAMLID()); response.setInResponseTo(data.getAuthnRequest().getID()); response.setVersion(VersionConstants.saml20); response.setIssueInstant(CalendarUtils.generateXMLCalendar(0)); response.setDestination(data.getResponseEndpoint()); response.setConsent(ConsentIdentifierConstants.prior); response.setIssuer(issuer); response.setSignature(new Signature()); response.setStatus(status); response.getEncryptedAssertionsAndAssertions().add(assertion); return response; }
From source file:com.sunrun.crportal.util.CRPortalUtil.java
public static TimeZone getPacificTimeZone() { TimeZone tz = new SimpleTimeZone(-28800000, "America/Los_Angeles"); return tz;/*from www. ja v a2 s . c om*/ }