Search in sources :

Example 31 with Duration

use of javax.xml.datatype.Duration in project j2objc by google.

the class ICUDurationTest method TestSimpleXMLDuration.

@Test
public void TestSimpleXMLDuration() {
    Duration d;
    DurationFormat df;
    String out;
    String expected;
    String expected2;
    // test 1
    // "PT2H46M40S"
    d = newDuration(1, 2, 46, 40);
    df = DurationFormat.getInstance(new ULocale("en"));
    expected = "2 hours, 46 minutes, and 40 seconds";
    out = df.format(d);
    if (out.equals(expected)) {
        logln("out=expected: " + expected + " from " + d);
    } else {
        errln("FAIL: got " + out + " wanted " + expected + " from " + d);
    }
    // test 2
    d = newDuration(10000);
    df = DurationFormat.getInstance(new ULocale("en"));
    expected = "10 seconds";
    out = df.format(d);
    if (out.equals(expected)) {
        logln("out=expected: " + expected + " from " + d);
    } else {
        errln("FAIL: got " + out + " wanted " + expected + " from " + d);
    }
    // test 3
    // "P0DT0H0M10.0S"
    d = newDuration(1, 0, 0, 0, 10);
    df = DurationFormat.getInstance(new ULocale("en"));
    expected = "10 seconds";
    out = df.format(d);
    if (out.equals(expected)) {
        logln("out=expected: " + expected + " from " + d);
    } else {
        errln("FAIL: got " + out + " wanted " + expected + " from " + d);
    }
    // test 4
    d = newDuration(86400000);
    df = DurationFormat.getInstance(new ULocale("en"));
    expected = "1 day, 0 hours, 0 minutes, and 0 seconds";
    // This is the expected result for Windows with IBM JRE6
    expected2 = "1 day and 0 seconds";
    out = df.format(d);
    if (out.equals(expected)) {
        logln("out=expected: " + expected + " from " + d);
    } else {
        if (out.equals(expected2)) {
            logln("WARNING: got " + out + " wanted " + expected + " from " + d);
        } else {
            errln("FAIL: got " + out + " wanted " + expected + " from " + d);
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) DurationFormat(android.icu.text.DurationFormat) Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 32 with Duration

use of javax.xml.datatype.Duration in project j2objc by google.

the class ICUDurationTest method TestXMLDuration.

@Test
public void TestXMLDuration() {
    final class TestCase {

        final String localeString;

        final ULocale locale;

        final String durationString;

        final Duration duration;

        final String expected;

        TestCase(String loc, String ds, Duration d, String exp) {
            localeString = loc;
            locale = new ULocale(loc);
            durationString = ds;
            duration = d;
            expected = exp;
        }
    }
    TestCase[] cases = { new TestCase("en", "PT10.00099S", newDuration(1, 10.00099F), "10 seconds"), new TestCase("en", "#10000", newDuration(10000), "10 seconds"), new TestCase("en", "-PT10.00099S", newDuration(-1, 10.00099F), "10 seconds"), new TestCase("en", "#-10000", newDuration(-10000), "10 seconds"), // from BD req's
    new TestCase("en", "PT2H46M40S", newDuration(1, 2, 46, 40), "2 hours, 46 minutes, and 40 seconds"), new TestCase("it", "PT2H46M40S", newDuration(1, 2, 46, 40), "due ore, 46 minuti e 40 secondi"), // more cases
    new TestCase("en", "PT10S", newDuration(1, 10), "10 seconds"), new TestCase("en", "PT88M70S", newDuration(1, -1, 88, 70), "88 minutes and 70 seconds"), new TestCase("en", "PT10.100S", newDuration(1, 10.100F), "10 seconds and 100 milliseconds"), new TestCase("en", "-PT10S", newDuration(-1, 10), "10 seconds"), new TestCase("en", "PT0H5M0S", newDuration(1, 0, 5, 0), "5 minutes and 0 seconds") };
    for (TestCase tc : cases) {
        String loc = tc.localeString;
        String from = tc.durationString;
        String to = tc.expected;
        ULocale locale = tc.locale;
        Duration d = tc.duration;
        DurationFormat df = DurationFormat.getInstance(locale);
        String output = df.format(d);
        if (output.equals(to)) {
            logln("SUCCESS: locale: " + loc + ", from " + from + " [" + d.toString() + "] " + " to " + to + "= " + output);
        } else {
            logln("FAIL: locale: " + loc + ", from " + from + " [" + d.toString() + "] " + ": expected " + to + " got " + output);
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) DurationFormat(android.icu.text.DurationFormat) Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 33 with Duration

use of javax.xml.datatype.Duration in project midpoint by Evolveum.

the class CertDefinitionDto method getUpdatedDefinition.

public AccessCertificationDefinitionType getUpdatedDefinition(PrismContext prismContext) throws SchemaException {
    updateOwner();
    updateScopeDefinition(prismContext);
    updateStageDefinition(prismContext);
    if (remediationStyle != null) {
        AccessCertificationRemediationDefinitionType remDef = new AccessCertificationRemediationDefinitionType(prismContext);
        remDef.setStyle(remediationStyle);
        remDef.getRevokeOn().addAll(revokeOn);
        definition.setRemediationDefinition(remDef);
    } else {
        definition.setRemediationDefinition(null);
    }
    if (automaticIterationAfter != null || automaticIterationLimit != null || overallIterationLimit != null) {
        Duration startsAfter;
        try {
            startsAfter = XmlTypeConverter.createDuration(automaticIterationAfter);
        } catch (IllegalArgumentException e) {
            // TODO better validation
            throw new IllegalArgumentException("Couldn't parse automatic reiteration time interval ('" + automaticIterationAfter + "')", e);
        }
        definition.setReiterationDefinition(new AccessCertificationReiterationDefinitionType(prismContext).startsAfter(startsAfter).limitWhenAutomatic(automaticIterationLimit).limit(overallIterationLimit));
    } else {
        definition.setReiterationDefinition(null);
    }
    if (outcomeStrategy != null) {
        if (definition.getReviewStrategy() == null) {
            definition.setReviewStrategy(new AccessCertificationCaseReviewStrategyType());
        }
        definition.getReviewStrategy().setOutcomeStrategy(outcomeStrategy);
    } else {
        if (definition.getReviewStrategy() != null) {
            definition.getReviewStrategy().setOutcomeStrategy(null);
        }
    }
    return definition;
}
Also used : Duration(javax.xml.datatype.Duration)

Example 34 with Duration

use of javax.xml.datatype.Duration in project midpoint by Evolveum.

the class AuthenticationEvaluatorImpl method isLockoutExpired.

private boolean isLockoutExpired(AbstractCredentialType credentialsType, CredentialPolicyType credentialsPolicy) {
    Duration lockoutDuration = credentialsPolicy.getLockoutDuration();
    if (lockoutDuration == null) {
        return false;
    }
    LoginEventType lastFailedLogin = credentialsType.getLastFailedLogin();
    if (lastFailedLogin == null) {
        return true;
    }
    XMLGregorianCalendar lastFailedLoginTimestamp = lastFailedLogin.getTimestamp();
    if (lastFailedLoginTimestamp == null) {
        return true;
    }
    XMLGregorianCalendar lockedUntilTimestamp = XmlTypeConverter.addDuration(lastFailedLoginTimestamp, lockoutDuration);
    return clock.isPast(lockedUntilTimestamp);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Duration(javax.xml.datatype.Duration)

Example 35 with Duration

use of javax.xml.datatype.Duration in project midpoint by Evolveum.

the class AuthenticationEvaluatorImpl method recordPasswordAuthenticationFailure.

protected void recordPasswordAuthenticationFailure(@NotNull MidPointPrincipal principal, @NotNull ConnectionEnvironment connEnv, @NotNull AuthenticationBehavioralDataType behavioralData, CredentialPolicyType credentialsPolicy, String reason, boolean audit) {
    FocusType focusBefore = principal.getFocus().clone();
    Integer failedLogins = behavioralData.getFailedLogins();
    LoginEventType lastFailedLogin = behavioralData.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++;
    }
    behavioralData.setFailedLogins(failedLogins);
    LoginEventType event = new LoginEventType();
    event.setTimestamp(clock.currentTimeXMLGregorianCalendar());
    event.setFrom(connEnv.getRemoteHostAddress());
    behavioralData.setLastFailedLogin(event);
    ActivationType activationType = principal.getFocus().getActivation();
    if (isOverFailedLockoutAttempts(failedLogins, credentialsPolicy)) {
        if (activationType == null) {
            activationType = new ActivationType();
            principal.getFocus().setActivation(activationType);
        }
        activationType.setLockoutStatus(LockoutStatusType.LOCKED);
        XMLGregorianCalendar lockoutExpirationTs = null;
        Duration lockoutDuration = credentialsPolicy.getLockoutDuration();
        if (lockoutDuration != null) {
            lockoutExpirationTs = XmlTypeConverter.addDuration(event.getTimestamp(), lockoutDuration);
        }
        activationType.setLockoutExpirationTimestamp(lockoutExpirationTs);
    }
    if (AuthSequenceUtil.isAllowUpdatingAuthBehavior(true)) {
        focusProfileService.updateFocus(principal, computeModifications(focusBefore, principal.getFocus()));
    }
    if (audit) {
        recordAuthenticationFailure(principal, connEnv, reason);
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Duration(javax.xml.datatype.Duration)

Aggregations

Duration (javax.xml.datatype.Duration)110 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)50 Test (org.junit.Test)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 ArrayList (java.util.ArrayList)11 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)8 GregorianCalendar (java.util.GregorianCalendar)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 Date (java.util.Date)7 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)6 Calendar (java.util.Calendar)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)5 Collection (java.util.Collection)4 NodeValue (org.apache.jena.sparql.expr.NodeValue)4 NotNull (org.jetbrains.annotations.NotNull)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 Task (com.evolveum.midpoint.task.api.Task)3