Search in sources :

Example 1 with AuthenticatorNotFoundException

use of io.picos.sailfish.mfa.google.exception.AuthenticatorNotFoundException in project sailfish-mfa by picos-io.

the class GoogleAuthnServiceImpl method refreshGoogleAuthnSecret.

/**
 * Generate new secret for the specified identity. If the GoogleAuthenticator is not existed, GoogleAuthnException will be thrown.
 *
 * @param username
 * @return
 */
@Override
public GoogleAuthenticatorSetting refreshGoogleAuthnSecret(String username) {
    MutableGoogleAuthenticatorSetting googleAuthenticatorSetting = (MutableGoogleAuthenticatorSetting) googleAuthenticatorStore.findByUsername(username);
    if (googleAuthenticatorSetting == null) {
        throw new AuthenticatorNotFoundException();
    }
    GoogleAuthenticatorKey googleAuthenticatorKey = googleAuthenticator.createCredentials();
    googleAuthenticatorSetting.setSecret(googleAuthenticatorKey.getKey());
    if (googleAuthenticatorSetting instanceof DefaultGoogleAuthenticatorSetting) {
        ((DefaultGoogleAuthenticatorSetting) googleAuthenticatorSetting).setModifiedAt(new Date());
    }
    return googleAuthenticatorStore.saveOrUpdate(googleAuthenticatorSetting);
}
Also used : GoogleAuthenticatorKey(com.warrenstrange.googleauth.GoogleAuthenticatorKey) AuthenticatorNotFoundException(io.picos.sailfish.mfa.google.exception.AuthenticatorNotFoundException) MutableGoogleAuthenticatorSetting(io.picos.sailfish.mfa.google.spi.MutableGoogleAuthenticatorSetting) DefaultGoogleAuthenticatorSetting(io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting) Date(java.util.Date)

Aggregations

GoogleAuthenticatorKey (com.warrenstrange.googleauth.GoogleAuthenticatorKey)1 AuthenticatorNotFoundException (io.picos.sailfish.mfa.google.exception.AuthenticatorNotFoundException)1 MutableGoogleAuthenticatorSetting (io.picos.sailfish.mfa.google.spi.MutableGoogleAuthenticatorSetting)1 DefaultGoogleAuthenticatorSetting (io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting)1 Date (java.util.Date)1