use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class AccCertTimedActionTriggerHandler method handle.
@Override
public <O extends ObjectType> void handle(PrismObject<O> object, TriggerType trigger, Task triggerScannerTask, OperationResult parentResult) {
if (!(object.asObjectable() instanceof AccessCertificationCampaignType)) {
throw new IllegalArgumentException("Unexpected object type: should be AccessCertificationCampaignType: " + object);
}
AccessCertificationCampaignType campaign = (AccessCertificationCampaignType) object.asObjectable();
OperationResult result = parentResult.createSubresult(AccCertTimedActionTriggerHandler.class.getName() + ".handle");
try {
Duration timeBeforeAction = ObjectTypeUtil.getExtensionItemRealValue(trigger.getExtension(), SchemaConstants.MODEL_EXTENSION_TIME_BEFORE_ACTION);
if (timeBeforeAction != null) {
AbstractWorkItemActionType action = ObjectTypeUtil.getExtensionItemRealValue(trigger.getExtension(), SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ACTION);
if (action == null) {
LOGGER.warn("Notification trigger without workItemAction; ignoring it: {}", trigger);
return;
}
executeNotifications(timeBeforeAction, action, campaign, triggerScannerTask, result);
} else {
WorkItemActionsType actions = ObjectTypeUtil.getExtensionItemRealValue(trigger.getExtension(), SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ACTIONS);
if (actions == null) {
LOGGER.warn("Trigger without workItemActions; ignoring it: {}", trigger);
return;
}
executeActions(actions, campaign, triggerScannerTask, result);
}
} catch (RuntimeException | ObjectNotFoundException | ObjectAlreadyExistsException | SchemaException | SecurityViolationException | ExpressionEvaluationException e) {
String message = "Exception while handling campaign trigger for " + campaign + ": " + e.getMessage();
result.recordFatalError(message, e);
throw new SystemException(message, e);
} finally {
result.computeStatusIfUnknown();
}
}
use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class ReportManagerImpl method cleanupReports.
@Override
public void cleanupReports(CleanupPolicyType cleanupPolicy, OperationResult parentResult) {
OperationResult result = parentResult.createSubresult(CLEANUP_REPORT_OUTPUTS);
if (cleanupPolicy.getMaxAge() == null) {
return;
}
Duration duration = cleanupPolicy.getMaxAge();
if (duration.getSign() > 0) {
duration = duration.negate();
}
Date deleteReportOutputsTo = new Date();
duration.addTo(deleteReportOutputsTo);
LOGGER.info("Starting cleanup for report outputs deleting up to {} (duration '{}').", new Object[] { deleteReportOutputsTo, duration });
XMLGregorianCalendar timeXml = XmlTypeConverter.createXMLGregorianCalendar(deleteReportOutputsTo.getTime());
List<PrismObject<ReportOutputType>> obsoleteReportOutputs = new ArrayList<PrismObject<ReportOutputType>>();
try {
ObjectQuery obsoleteReportOutputsQuery = QueryBuilder.queryFor(ReportOutputType.class, prismContext).item(ReportOutputType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP).le(timeXml).build();
obsoleteReportOutputs = modelService.searchObjects(ReportOutputType.class, obsoleteReportOutputsQuery, null, null, result);
} catch (Exception e) {
throw new SystemException("Couldn't get the list of obsolete report outputs: " + e.getMessage(), e);
}
LOGGER.debug("Found {} report output(s) to be cleaned up", obsoleteReportOutputs.size());
boolean interrupted = false;
int deleted = 0;
int problems = 0;
for (PrismObject<ReportOutputType> reportOutputPrism : obsoleteReportOutputs) {
ReportOutputType reportOutput = reportOutputPrism.asObjectable();
LOGGER.trace("Removing report output {} along with {} file.", reportOutput.getName().getOrig(), reportOutput.getFilePath());
boolean problem = false;
try {
deleteReportOutput(reportOutput, result);
} catch (Exception e) {
LoggingUtils.logException(LOGGER, "Couldn't delete obsolete report output {} due to a exception", e, reportOutput);
problem = true;
}
if (problem) {
problems++;
} else {
deleted++;
}
}
result.computeStatusIfUnknown();
LOGGER.info("Report cleanup procedure " + (interrupted ? "was interrupted" : "finished") + ". Successfully deleted {} report outputs; there were problems with deleting {} report ouptuts.", deleted, problems);
String suffix = interrupted ? " Interrupted." : "";
if (problems == 0) {
parentResult.createSubresult(CLEANUP_REPORT_OUTPUTS + ".statistics").recordStatus(OperationResultStatus.SUCCESS, "Successfully deleted " + deleted + " report output(s)." + suffix);
} else {
parentResult.createSubresult(CLEANUP_REPORT_OUTPUTS + ".statistics").recordPartialError("Successfully deleted " + deleted + " report output(s), " + "there was problems with deleting " + problems + " report outputs.");
}
}
use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class ObjectValuePolicyEvaluator method validateMinAge.
private void validateMinAge(StringBuilder messageBuilder, OperationResult result) {
if (oldCredentialType == null) {
return;
}
Duration minAge = getMinAge();
if (minAge == null) {
return;
}
MetadataType currentCredentialMetadata = oldCredentialType.getMetadata();
if (currentCredentialMetadata == null) {
return;
}
XMLGregorianCalendar lastChangeTimestamp = currentCredentialMetadata.getModifyTimestamp();
if (lastChangeTimestamp == null) {
lastChangeTimestamp = currentCredentialMetadata.getCreateTimestamp();
}
if (lastChangeTimestamp == null) {
return;
}
XMLGregorianCalendar changeAllowedTimestamp = XmlTypeConverter.addDuration(lastChangeTimestamp, minAge);
if (changeAllowedTimestamp.compare(now) == DatatypeConstants.GREATER) {
LOGGER.trace("Password minAge violated. lastChange={}, minAge={}, now={}", lastChangeTimestamp, minAge, now);
String msg = shortDesc + " could not be changed because password minimal age was not yet reached.";
result.addSubresult(new OperationResult("Password minimal age", OperationResultStatus.FATAL_ERROR, msg));
messageBuilder.append(msg);
messageBuilder.append("\n");
}
}
use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class Mapping method parseTime.
private XMLGregorianCalendar parseTime(MappingTimeDeclarationType timeType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
if (timeType == null) {
return null;
}
XMLGregorianCalendar time;
VariableBindingDefinitionType referenceTimeType = timeType.getReferenceTime();
if (referenceTimeType == null) {
if (defaultReferenceTime == null) {
throw new SchemaException("No reference time specified (and there is also no default) in time specification in " + getMappingContextDescription());
} else {
time = (XMLGregorianCalendar) defaultReferenceTime.clone();
}
} else {
time = parseTimeSource(referenceTimeType, task, result);
if (time == null) {
// Reference time is specified but the value is not present.
return null;
}
time = (XMLGregorianCalendar) time.clone();
}
Duration offset = timeType.getOffset();
if (offset != null) {
time.add(offset);
}
return time;
}
use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class AuthenticationEvaluatorImpl method recordPasswordAuthenticationFailure.
private void recordPasswordAuthenticationFailure(@NotNull MidPointPrincipal principal, @NotNull ConnectionEnvironment connEnv, @NotNull C passwordType, CredentialPolicyType credentialsPolicy, String reason) {
Integer failedLogins = passwordType.getFailedLogins();
LoginEventType lastFailedLogin = passwordType.getLastFailedLogin();
XMLGregorianCalendar lastFailedLoginTs = null;
if (lastFailedLogin != null) {
lastFailedLoginTs = lastFailedLogin.getTimestamp();
}
if (credentialsPolicy != null) {
Duration lockoutFailedAttemptsDuration = credentialsPolicy.getLockoutFailedAttemptsDuration();
if (lockoutFailedAttemptsDuration != null) {
if (lastFailedLoginTs != null) {
XMLGregorianCalendar failedLoginsExpirationTs = XmlTypeConverter.addDuration(lastFailedLoginTs, lockoutFailedAttemptsDuration);
if (clock.isPast(failedLoginsExpirationTs)) {
failedLogins = 0;
}
}
}
}
if (failedLogins == null) {
failedLogins = 1;
} else {
failedLogins++;
}
passwordType.setFailedLogins(failedLogins);
LoginEventType event = new LoginEventType();
event.setTimestamp(clock.currentTimeXMLGregorianCalendar());
event.setFrom(connEnv.getRemoteHostAddress());
passwordType.setLastFailedLogin(event);
ActivationType activationType = principal.getUser().getActivation();
if (failedLogins != null && isOverFailedLockoutAttempts(failedLogins, credentialsPolicy)) {
if (activationType == null) {
activationType = new ActivationType();
principal.getUser().setActivation(activationType);
}
activationType.setLockoutStatus(LockoutStatusType.LOCKED);
XMLGregorianCalendar lockoutExpirationTs = null;
if (credentialsPolicy != null) {
Duration lockoutDuration = credentialsPolicy.getLockoutDuration();
if (lockoutDuration != null) {
lockoutExpirationTs = XmlTypeConverter.addDuration(event.getTimestamp(), lockoutDuration);
}
}
activationType.setLockoutExpirationTimestamp(lockoutExpirationTs);
}
userProfileService.updateUser(principal);
recordAuthenticationFailure(principal, connEnv, reason);
}
Aggregations