@Override public ZonedDateTime convert(final String s) { final GeneralizedTimeValueTranscoder transcoder = new GeneralizedTimeValueTranscoder(); return transcoder.decodeStringValue(s); } }
@Override public String convert(final ZonedDateTime t) { final GeneralizedTimeValueTranscoder transcoder = new GeneralizedTimeValueTranscoder(); return transcoder.encodeStringValue(t); } }
@Override public ZonedDateTime decodeStringValue(final String value) { try { return parseGeneralizedTime(value); } catch (ParseException | DateTimeException e) { throw new IllegalArgumentException(e); } }
/** * Initializes the set of default single value transcoders. * * @return single value transcoders */ protected Set<SingleValueReflectionTranscoder<?>> getDefaultSingleValueTranscoders() { final Set<SingleValueReflectionTranscoder<?>> transcoders = new HashSet<>(); transcoders.add(new SingleValueReflectionTranscoder<>(new ObjectValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new BooleanValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new BooleanValueTranscoder(true))); transcoders.add(new SingleValueReflectionTranscoder<>(new DoubleValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new DoubleValueTranscoder(true))); transcoders.add(new SingleValueReflectionTranscoder<>(new FloatValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new FloatValueTranscoder(true))); transcoders.add(new SingleValueReflectionTranscoder<>(new IntegerValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new IntegerValueTranscoder(true))); transcoders.add(new SingleValueReflectionTranscoder<>(new LongValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new LongValueTranscoder(true))); transcoders.add(new SingleValueReflectionTranscoder<>(new ShortValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new ShortValueTranscoder(true))); transcoders.add(new SingleValueReflectionTranscoder<>(new StringValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new ByteArrayValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new CharArrayValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new CertificateValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new GeneralizedTimeValueTranscoder())); transcoders.add(new SingleValueReflectionTranscoder<>(new UUIDValueTranscoder())); return transcoders; }
/** * @param date to compare * @param generalizedTime ldap attribute string value * @param formatTime formatted ldap attribute string value * * @throws Exception On test failure. */ @Test(groups = {"io"}, dataProvider = "dates") public void decodeGeneralized(final ZonedDateTime date, final String generalizedTime, final String formatTime) throws Exception { Assert.assertEquals(transcoder.decodeStringValue(generalizedTime), date); }
/** * @param date to compare * @param generalizedTime ldap attribute string value * @param formatTime formatted ldap attribute string value * * @throws Exception On test failure. */ @Test(groups = {"io"}, dataProvider = "dates") public void encodeFormat(final ZonedDateTime date, final String generalizedTime, final String formatTime) throws Exception { Assert.assertEquals(transcoder.encodeStringValue(date), formatTime); }
final Calendar exp = expTime.getValue(new GeneralizedTimeValueTranscoder()); if (warningHours > 0) { final Calendar now = Calendar.getInstance();
/** * @param generalizedTime ldap attribute string value * * @throws Exception On test failure. */ @Test(groups = {"io"}, dataProvider = "invalid") public void testInvalid(final String generalizedTime) throws Exception { try { transcoder.decodeStringValue(generalizedTime); Assert.fail("Should have thrown exception"); } catch (Exception e) { Assert.assertEquals(e.getClass(), IllegalArgumentException.class); } }
exp = expTime.getValue(new GeneralizedTimeValueTranscoder()); } else if (expirationPeriod != null && lastPwdChange != null) { exp = lastPwdChange.getValue(new GeneralizedTimeValueTranscoder()).plus(expirationPeriod);
/** * @param date to compare * @param generalizedTime ldap attribute string value * @param formatTime formatted ldap attribute string value * * @throws Exception On test failure. */ @Test(groups = {"io"}, dataProvider = "dates") public void decodeFormat(final ZonedDateTime date, final String generalizedTime, final String formatTime) throws Exception { Assert.assertEquals(transcoder.decodeStringValue(formatTime), date.withZoneSameInstant(ZoneOffset.UTC)); }
@Override public ZonedDateTime decodeStringValue(final String value) { try { return parseGeneralizedTime(value); } catch (ParseException | DateTimeException e) { throw new IllegalArgumentException(e); } }
exp = expTime.getValue(new GeneralizedTimeValueTranscoder()); } else if (expirationPeriod != null && lastPwdChange != null) { exp = lastPwdChange.getValue(new GeneralizedTimeValueTranscoder()).plus(expirationPeriod);
@Override public Calendar decodeStringValue(final String value) { try { return parseGeneralizedTime(value); } catch (ParseException e) { throw new IllegalArgumentException(e); } }
@Override public void handle(final AuthenticationResponse response) { if (response.getMessage() != null) { final EDirectoryAccountState.Error edError = EDirectoryAccountState.Error.parse(response.getMessage()); if (edError != null) { response.setAccountState(new EDirectoryAccountState(edError)); } } else if (response.getResult()) { final LdapEntry entry = response.getLdapEntry(); final LdapAttribute expTime = entry.getAttribute("passwordExpirationTime"); final LdapAttribute loginRemaining = entry.getAttribute("loginGraceRemaining"); final int loginRemainingValue = loginRemaining != null ? Integer.parseInt(loginRemaining.getStringValue()) : 0; if (expTime != null) { final ZonedDateTime exp = expTime.getValue(new GeneralizedTimeValueTranscoder()); if (warningPeriod != null) { final ZonedDateTime warn = exp.minus(warningPeriod); if (ZonedDateTime.now().isAfter(warn)) { response.setAccountState(new EDirectoryAccountState(exp, loginRemainingValue)); } } else { response.setAccountState(new EDirectoryAccountState(exp, loginRemainingValue)); } } else if (loginRemaining != null) { response.setAccountState(new EDirectoryAccountState(null, loginRemainingValue)); } } }
@Override public void handle(final AuthenticationResponse response) { if (response.getMessage() != null) { final EDirectoryAccountState.Error edError = EDirectoryAccountState.Error.parse(response.getMessage()); if (edError != null) { response.setAccountState(new EDirectoryAccountState(edError)); } } else if (response.getResult()) { final LdapEntry entry = response.getLdapEntry(); final LdapAttribute expTime = entry.getAttribute("passwordExpirationTime"); final LdapAttribute loginRemaining = entry.getAttribute("loginGraceRemaining"); final int loginRemainingValue = loginRemaining != null ? Integer.parseInt(loginRemaining.getStringValue()) : 0; if (expTime != null) { final ZonedDateTime exp = expTime.getValue(new GeneralizedTimeValueTranscoder()); if (warningPeriod != null) { final ZonedDateTime warn = exp.minus(warningPeriod); if (ZonedDateTime.now().isAfter(warn)) { response.setAccountState(new EDirectoryAccountState(exp, loginRemainingValue)); } } else { response.setAccountState(new EDirectoryAccountState(exp, loginRemainingValue)); } } else if (loginRemaining != null) { response.setAccountState(new EDirectoryAccountState(null, loginRemainingValue)); } } }