/**
* Get a ConditionsBean object.
*/
public ConditionsBean getConditions(TokenProviderParameters providerParameters) {
ConditionsBean conditions = new ConditionsBean();
if (lifetime > 0) {
Lifetime tokenLifetime = providerParameters.getTokenRequirements().getLifetime();
if (acceptClientLifetime && tokenLifetime != null) {
try {
XmlSchemaDateFormat fmt = new XmlSchemaDateFormat();
Date creationTime = fmt.parse(tokenLifetime.getCreated());
Date expirationTime = fmt.parse(tokenLifetime.getExpires());
long requestedLifetime = expirationTime.getTime() - creationTime.getTime();
if (requestedLifetime > (getMaxLifetime() * 1000L)) {
StringBuilder sb = new StringBuilder();
sb.append("Requested lifetime [").append(requestedLifetime / 1000L);
sb.append(" sec] exceed configured maximum lifetime [").append(getMaxLifetime());
sb.append(" sec]");
LOG.warning(sb.toString());
if (isFailLifetimeExceedance()) {
throw new STSException("Requested lifetime exceeds maximum lifetime",
STSException.INVALID_TIME);
} else {
expirationTime.setTime(creationTime.getTime() + (getMaxLifetime() * 1000L));
}
}
DateTime creationDateTime = new DateTime(creationTime.getTime());
DateTime expirationDateTime = new DateTime(expirationTime.getTime());
conditions.setNotAfter(expirationDateTime);
conditions.setNotBefore(creationDateTime);
} catch (ParseException e) {
LOG.warning("Failed to parse life time element: " + e.getMessage());
conditions.setTokenPeriodMinutes((int)(lifetime / 60L));
}
} else {
conditions.setTokenPeriodMinutes((int)(lifetime / 60L));
}
} else {
conditions.setTokenPeriodMinutes(5);
}
conditions.setAudienceURI(providerParameters.getAppliesToAddress());
return conditions;
}