@Override public int compare(final T o1, final T o2) { return o2.getEffectiveDate().compareTo(o1.getEffectiveDate()); } });
/** * <p>Checks if the given {@link CredentialStorage} holds an expired credential.</p> * * @param credentialStorage * @return */ public static boolean isCredentialExpired(CredentialStorage credentialStorage) { return credentialStorage != null && credentialStorage.getExpiryDate() != null && new Date().compareTo(credentialStorage.getExpiryDate()) > 0; } }
@Override public int compare(final T o1, final T o2) { return o2.getEffectiveDate().compareTo(o1.getEffectiveDate()); } });
/** * <p>Checks if the given {@link CredentialStorage} holds an expired credential.</p> * * @param credentialStorage * @return */ public static boolean isCredentialExpired(CredentialStorage credentialStorage) { return credentialStorage != null && credentialStorage.getExpiryDate() != null && new Date().compareTo(credentialStorage.getExpiryDate()) > 0; } }
/** * <p> * Checks if the specified {@link CredentialStorage} maps to the current credential. * </p> * * @param credential * @return */ public static boolean isCurrentCredential(CredentialStorage credential) { Date actualDate = new Date(); if (credential.getEffectiveDate() != null) { if (credential.getEffectiveDate().compareTo(actualDate) <= 0) { return true; } } return false; }
/** * <p> * Checks if the specified {@link CredentialStorage} maps to the current credential. * </p> * * @param credential * @return */ public static boolean isCurrentCredential(CredentialStorage credential) { Date actualDate = new Date(); if (credential.getEffectiveDate() != null) { if (credential.getEffectiveDate().compareTo(actualDate) <= 0) { return true; } } return false; }
/** * <p>Returns the current credential for the given {@link Agent}.</p> * * @param agent * @param store * @param storageClass * @return */ public static <T extends CredentialStorage> T getCurrentCredential(IdentityContext context, Account agent, CredentialStore<?> store, Class<T> storageClass) { T lastCredential = null; Date actualDate = new Date(); for (T storedCredential : store.retrieveCredentials(context, agent, storageClass)) { if (storedCredential.getEffectiveDate().compareTo(actualDate) <= 0) { if (lastCredential == null || lastCredential.getEffectiveDate().compareTo(storedCredential.getEffectiveDate()) <= 0) { lastCredential = storedCredential; } } } return lastCredential; }
/** * <p>Returns the current credential for the given {@link Agent}.</p> * * @param agent * @param store * @param storageClass * @return */ public static <T extends CredentialStorage> T getCurrentCredential(IdentityContext context, Account agent, CredentialStore<?> store, Class<T> storageClass) { T lastCredential = null; Date actualDate = new Date(); for (T storedCredential : store.retrieveCredentials(context, agent, storageClass)) { if (storedCredential.getEffectiveDate().compareTo(actualDate) <= 0) { if (lastCredential == null || lastCredential.getEffectiveDate().compareTo(storedCredential.getEffectiveDate()) <= 0) { lastCredential = storedCredential; } } } return lastCredential; }