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);
}
}
}
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);
}
}
}
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;
}
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);
}
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);
}
}
Aggregations