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;
}
int tokenPeriodMinutes = conditionsBean.getTokenPeriodMinutes();
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 (tokenPeriodMinutes <= 0) {
tokenPeriodMinutes = 5;
}
conditions.setNotOnOrAfter(newNotBefore.plusMinutes(tokenPeriodMinutes));
}
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;
}