Search in sources :

Example 1 with AttributedDateTime

use of org.apache.cxf.ws.security.sts.provider.model.utility.AttributedDateTime in project cxf by apache.

the class AbstractOperation method createLifetime.

/**
 * Create a LifetimeType object given a created + expires Dates
 */
protected static LifetimeType createLifetime(Instant tokenCreated, Instant tokenExpires) {
    AttributedDateTime created = QNameConstants.UTIL_FACTORY.createAttributedDateTime();
    AttributedDateTime expires = QNameConstants.UTIL_FACTORY.createAttributedDateTime();
    Instant now = Instant.now();
    Instant creationTime = tokenCreated;
    if (tokenCreated == null) {
        creationTime = now;
    }
    Instant expirationTime = tokenExpires;
    if (tokenExpires == null) {
        long lifeTimeOfToken = 300L;
        expirationTime = now.plusSeconds(lifeTimeOfToken);
    }
    created.setValue(creationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true)));
    expires.setValue(expirationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true)));
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Token lifetime creation: " + created.getValue());
        LOG.fine("Token lifetime expiration: " + expires.getValue());
    }
    LifetimeType lifetimeType = QNameConstants.WS_TRUST_FACTORY.createLifetimeType();
    lifetimeType.setCreated(created);
    lifetimeType.setExpires(expires);
    return lifetimeType;
}
Also used : Instant(java.time.Instant) LifetimeType(org.apache.cxf.ws.security.sts.provider.model.LifetimeType) AttributedDateTime(org.apache.cxf.ws.security.sts.provider.model.utility.AttributedDateTime)

Example 2 with AttributedDateTime

use of org.apache.cxf.ws.security.sts.provider.model.utility.AttributedDateTime in project cxf by apache.

the class IssueUnitTest method createLifetime.

/**
 * Create a LifetimeType object given a lifetime in seconds
 */
private LifetimeType createLifetime(long lifetime) {
    AttributedDateTime created = QNameConstants.UTIL_FACTORY.createAttributedDateTime();
    AttributedDateTime expires = QNameConstants.UTIL_FACTORY.createAttributedDateTime();
    if (lifetime <= 0) {
        lifetime = 300L;
    }
    Instant creationTime = Instant.now();
    Instant expirationTime = creationTime.plusSeconds(lifetime);
    created.setValue(creationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true)));
    expires.setValue(expirationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true)));
    LifetimeType lifetimeType = QNameConstants.WS_TRUST_FACTORY.createLifetimeType();
    lifetimeType.setCreated(created);
    lifetimeType.setExpires(expires);
    return lifetimeType;
}
Also used : Instant(java.time.Instant) LifetimeType(org.apache.cxf.ws.security.sts.provider.model.LifetimeType) AttributedDateTime(org.apache.cxf.ws.security.sts.provider.model.utility.AttributedDateTime)

Aggregations

Instant (java.time.Instant)2 LifetimeType (org.apache.cxf.ws.security.sts.provider.model.LifetimeType)2 AttributedDateTime (org.apache.cxf.ws.security.sts.provider.model.utility.AttributedDateTime)2