use of java.time.ZonedDateTime in project cas by apereo.
the class SamlProfileSamlConditionsBuilder method buildConditions.
private Conditions buildConditions(final AuthnRequest authnRequest, final Assertion assertion, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor) throws SamlException {
final ZonedDateTime currentDateTime = ZonedDateTime.now(ZoneOffset.UTC);
final Conditions conditions = newConditions(currentDateTime, currentDateTime.plusSeconds(casProperties.getAuthn().getSamlIdp().getResponse().getSkewAllowance()), adaptor.getEntityId());
return conditions;
}
use of java.time.ZonedDateTime in project camel by apache.
the class DateTimeConverter method marshal.
@Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) {
ZonedDateTime dateTime = (ZonedDateTime) o;
writer.setValue(DateTimeUtils.formatDateTime(dateTime));
}
use of java.time.ZonedDateTime in project cas by apereo.
the class TokenWebApplicationServiceResponseBuilder method generateToken.
/**
* Generate token string.
*
* @param service the service
* @param parameters the parameters
* @return the jwt
*/
protected String generateToken(final Service service, final Map<String, String> parameters) {
try {
final String ticketId = parameters.get(CasProtocolConstants.PARAMETER_TICKET);
final Cas30ServiceTicketValidator validator = new Cas30ServiceTicketValidator(casProperties.getServer().getPrefix());
final Assertion assertion = validator.validate(ticketId, service.getId());
final JWTClaimsSet.Builder claims = new JWTClaimsSet.Builder().audience(service.getId()).issuer(casProperties.getServer().getPrefix()).jwtID(ticketId).issueTime(assertion.getAuthenticationDate()).subject(assertion.getPrincipal().getName());
assertion.getAttributes().forEach(claims::claim);
assertion.getPrincipal().getAttributes().forEach(claims::claim);
if (assertion.getValidUntilDate() != null) {
claims.expirationTime(assertion.getValidUntilDate());
} else {
final ZonedDateTime dt = ZonedDateTime.now().plusSeconds(ticketGrantingTicketExpirationPolicy.getTimeToLive());
claims.expirationTime(DateTimeUtils.dateOf(dt));
}
final JWTClaimsSet claimsSet = claims.build();
final JSONObject object = claimsSet.toJSONObject();
return tokenCipherExecutor.encode(object.toJSONString());
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
use of java.time.ZonedDateTime in project hibernate-orm by hibernate.
the class LocalTimeJavaDescriptor method unwrap.
@Override
@SuppressWarnings("unchecked")
public <X> X unwrap(LocalTime value, Class<X> type, WrapperOptions options) {
if (value == null) {
return null;
}
if (LocalDate.class.isAssignableFrom(type)) {
return (X) value;
}
if (Time.class.isAssignableFrom(type)) {
return (X) Time.valueOf(value);
}
// Oracle documentation says to set the Date to January 1, 1970 when convert from
// a LocalTime to a Calendar. IMO the same should hold true for converting to all
// the legacy Date/Time types...
final ZonedDateTime zonedDateTime = value.atDate(LocalDate.of(1970, 1, 1)).atZone(ZoneId.systemDefault());
if (Calendar.class.isAssignableFrom(type)) {
return (X) GregorianCalendar.from(zonedDateTime);
}
final Instant instant = zonedDateTime.toInstant();
if (Timestamp.class.isAssignableFrom(type)) {
return (X) Timestamp.from(instant);
}
if (Date.class.equals(type)) {
return (X) Date.from(instant);
}
if (Long.class.isAssignableFrom(type)) {
return (X) Long.valueOf(instant.toEpochMilli());
}
throw unknownUnwrap(type);
}
use of java.time.ZonedDateTime in project hibernate-orm by hibernate.
the class OffsetTimeJavaDescriptor method unwrap.
@Override
@SuppressWarnings("unchecked")
public <X> X unwrap(OffsetTime offsetTime, Class<X> type, WrapperOptions options) {
if (offsetTime == null) {
return null;
}
if (OffsetTime.class.isAssignableFrom(type)) {
return (X) offsetTime;
}
if (java.sql.Time.class.isAssignableFrom(type)) {
return (X) java.sql.Time.valueOf(offsetTime.toLocalTime());
}
final ZonedDateTime zonedDateTime = offsetTime.atDate(LocalDate.of(1970, 1, 1)).toZonedDateTime();
if (Timestamp.class.isAssignableFrom(type)) {
return (X) Timestamp.valueOf(zonedDateTime.toLocalDateTime());
}
if (Calendar.class.isAssignableFrom(type)) {
return (X) GregorianCalendar.from(zonedDateTime);
}
final Instant instant = zonedDateTime.toInstant();
if (Long.class.isAssignableFrom(type)) {
return (X) Long.valueOf(instant.toEpochMilli());
}
if (java.util.Date.class.isAssignableFrom(type)) {
return (X) java.util.Date.from(instant);
}
throw unknownUnwrap(type);
}
Aggregations