if (conditionsBuilder == null) {
conditionsBuilder = (SAMLObjectBuilder<Conditions>)
builderFactory.getBuilder(Conditions.DEFAULT_ELEMENT_NAME);
}
Conditions conditions = conditionsBuilder.buildObject();
if (conditionsBean == null) {
DateTime newNotBefore = new DateTime();
conditions.setNotBefore(newNotBefore);
conditions.setNotOnOrAfter(newNotBefore.plusMinutes(5));
return conditions;
}
long tokenPeriodSeconds = conditionsBean.getTokenPeriodSeconds();
DateTime notBefore = conditionsBean.getNotBefore();
DateTime notAfter = conditionsBean.getNotAfter();
if (notBefore != null && notAfter != null) {
if (notBefore.isAfter(notAfter)) {
throw new IllegalStateException(
"The value of notBefore may not be after the value of notAfter"
);
}
conditions.setNotBefore(notBefore);
conditions.setNotOnOrAfter(notAfter);
} else {
DateTime newNotBefore = new DateTime();
conditions.setNotBefore(newNotBefore);
if (tokenPeriodSeconds <= 0) {
tokenPeriodSeconds = 5L * 60L;
}
DateTime notOnOrAfter =
new DateTime(newNotBefore.getMillis() + tokenPeriodSeconds * 1000L);
conditions.setNotOnOrAfter(notOnOrAfter);
}
if (conditionsBean.getAudienceURI() != null) {
AudienceRestriction audienceRestriction =
createAudienceRestriction(conditionsBean.getAudienceURI());
conditions.getAudienceRestrictions().add(audienceRestriction);
}
if (conditionsBean.isOneTimeUse()) {
conditions.getConditions().add(createOneTimeUse());
}
if (conditionsBean.getProxyRestriction() != null) {
conditions.getConditions().add(createProxyRestriction(conditionsBean.getProxyRestriction()));
}
return conditions;
}