Search in sources :

Example 76 with ZonedDateTime

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;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Conditions(org.opensaml.saml.saml2.core.Conditions)

Example 77 with ZonedDateTime

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));
}
Also used : ZonedDateTime(java.time.ZonedDateTime)

Example 78 with ZonedDateTime

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);
    }
}
Also used : Cas30ServiceTicketValidator(org.jasig.cas.client.validation.Cas30ServiceTicketValidator) JSONObject(net.minidev.json.JSONObject) ZonedDateTime(java.time.ZonedDateTime) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) Assertion(org.jasig.cas.client.validation.Assertion)

Example 79 with ZonedDateTime

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);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant)

Example 80 with ZonedDateTime

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);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)1375 Test (org.junit.Test)570 Test (org.testng.annotations.Test)182 LocalDateTime (java.time.LocalDateTime)136 ZoneId (java.time.ZoneId)122 Instant (java.time.Instant)112 ArrayList (java.util.ArrayList)102 Test (org.junit.jupiter.api.Test)93 LocalDate (java.time.LocalDate)84 DateTimeFormatter (java.time.format.DateTimeFormatter)77 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)76 List (java.util.List)75 Date (java.util.Date)63 IOException (java.io.IOException)58 UUID (java.util.UUID)58 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)54 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)53 HashMap (java.util.HashMap)46 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)44 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)43