/** * <p>Checks if the given {@link OTPCredentialStorage} references the given <code>device</code>. A null device * means that this storage can reference any device and this method will return true.</p> * * @param device * @param storage * @return */ private boolean isDeviceStorage(String device, final OTPCredentialStorage storage) { return device == null || device.equals(storage.getDevice()); }
@Override public void update(IdentityContext context, Account account, TOTPCredential credential, CredentialStore<?> store, Date effectiveDate, Date expiryDate) { // if a credential was not provided, updates only the secret. if (credential.getValue() != null && credential.getValue().length > 0) { super.update(context, account, credential, store, effectiveDate, expiryDate); } OTPCredentialStorage storage = new OTPCredentialStorage(); if (effectiveDate != null) { storage.setEffectiveDate(effectiveDate); } storage.setExpiryDate(expiryDate); storage.setSecretKey(credential.getSecret()); storage.setDevice(getDevice(credential.getDevice())); store.storeCredential(context, account, storage); }
private boolean isValid(final IdentityContext context, final TOTPCredentials credentials, final CredentialStore<?> store) { for (OTPCredentialStorage storage : getCredentialStorages(context, credentials, store)) { String secretKey = storage.getSecretKey(); String token = credentials.getToken(); if (this.totp.validate(token, secretKey.getBytes())) { return true; } } return false; }
@Override public void update(IdentityContext context, Account account, TOTPCredential credential, CredentialStore<?> store, Date effectiveDate, Date expiryDate) { // if a credential was not provided, updates only the secret. if (credential.getValue() != null && credential.getValue().length > 0) { super.update(context, account, credential, store, effectiveDate, expiryDate); } OTPCredentialStorage storage = new OTPCredentialStorage(); if (effectiveDate != null) { storage.setEffectiveDate(effectiveDate); } storage.setExpiryDate(expiryDate); storage.setSecretKey(credential.getSecret()); storage.setDevice(getDevice(credential.getDevice())); store.storeCredential(context, account, storage); }
private boolean isValid(final IdentityContext context, final TOTPCredentials credentials, final CredentialStore<?> store) { for (OTPCredentialStorage storage : getCredentialStorages(context, credentials, store)) { String secretKey = storage.getSecretKey(); String token = credentials.getToken(); if (this.totp.validate(token, secretKey.getBytes())) { return true; } } return false; }
/** * <p>Checks if the given {@link OTPCredentialStorage} references the given <code>device</code>. A null device * means that this storage can reference any device and this method will return true.</p> * * @param device * @param storage * @return */ private boolean isDeviceStorage(String device, final OTPCredentialStorage storage) { return device == null || device.equals(storage.getDevice()); }