Search in sources :

Example 91 with Duration

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();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Duration(javax.xml.datatype.Duration)

Example 92 with Duration

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.");
    }
}
Also used : ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Duration(javax.xml.datatype.Duration) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Date(java.util.Date) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JRException(net.sf.jasperreports.engine.JRException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 93 with Duration

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");
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) MetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType) Duration(javax.xml.datatype.Duration) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 94 with Duration

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;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Duration(javax.xml.datatype.Duration)

Example 95 with Duration

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);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Duration(javax.xml.datatype.Duration)

Aggregations

Duration (javax.xml.datatype.Duration)137 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)57 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 Date (java.util.Date)12 BigDecimal (java.math.BigDecimal)9 Calendar (java.util.Calendar)9 GregorianCalendar (java.util.GregorianCalendar)9 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 IOException (java.io.IOException)5 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)5 FileNotFoundException (java.io.FileNotFoundException)4 Collection (java.util.Collection)4 DatatypeFactory (javax.xml.datatype.DatatypeFactory)4 NotNull (org.jetbrains.annotations.NotNull)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3