Search in sources :

Example 1 with DefaultGoogleAuthenticatorSetting

use of io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting 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)

Example 2 with DefaultGoogleAuthenticatorSetting

use of io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting in project sailfish-mfa by picos-io.

the class GoogleAuthenticatorStoreImpl method saveOrUpdate.

/**
 * @param googleAuthenticatorSetting
 */
@Override
public GoogleAuthenticatorSetting saveOrUpdate(GoogleAuthenticatorSetting googleAuthenticatorSetting) {
    if (googleAuthenticatorSetting instanceof DefaultGoogleAuthenticatorSetting) {
        googleAuthenticatorSettingRepository.save((DefaultGoogleAuthenticatorSetting) googleAuthenticatorSetting);
    }
    DefaultGoogleAuthenticatorSetting defaultGoogleAuthenticatorSetting = googleAuthenticatorSettingRepository.findFirstByUsername(googleAuthenticatorSetting.getUsername());
    if (defaultGoogleAuthenticatorSetting == null) {
        defaultGoogleAuthenticatorSetting = new DefaultGoogleAuthenticatorSetting();
    }
    BeanUtils.copyProperties(googleAuthenticatorSetting, defaultGoogleAuthenticatorSetting);
    return googleAuthenticatorSettingRepository.save((DefaultGoogleAuthenticatorSetting) googleAuthenticatorSetting);
}
Also used : DefaultGoogleAuthenticatorSetting(io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting)

Example 3 with DefaultGoogleAuthenticatorSetting

use of io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting in project sailfish-mfa by picos-io.

the class GoogleAuthnServiceImpl method enableGoogleAuthenticator.

/**
 * If the previous GoogleAuthenticator existed, return it directly. Otherwise create new one for the identity.
 *
 * @param username
 * @return
 */
@Override
public GoogleAuthenticatorSetting enableGoogleAuthenticator(String username) {
    MutableGoogleAuthenticatorSetting googleAuthenticatorSetting = (MutableGoogleAuthenticatorSetting) googleAuthenticatorStore.findByUsername(username);
    if (googleAuthenticatorSetting == null) {
        googleAuthenticatorSetting = new DefaultGoogleAuthenticatorSetting();
        googleAuthenticatorSetting.setUsername(username);
        if (googleAuthenticatorSetting instanceof DefaultGoogleAuthenticatorSetting) {
            ((DefaultGoogleAuthenticatorSetting) googleAuthenticatorSetting).setCreatedAt(new Date());
        }
        GoogleAuthenticatorKey googleAuthenticatorKey = googleAuthenticator.createCredentials();
        googleAuthenticatorSetting.setSecret(googleAuthenticatorKey.getKey());
    }
    googleAuthenticatorSetting.setEnabled(true);
    if (googleAuthenticatorSetting instanceof DefaultGoogleAuthenticatorSetting) {
        ((DefaultGoogleAuthenticatorSetting) googleAuthenticatorSetting).setModifiedAt(new Date());
    }
    return googleAuthenticatorStore.saveOrUpdate(googleAuthenticatorSetting);
}
Also used : GoogleAuthenticatorKey(com.warrenstrange.googleauth.GoogleAuthenticatorKey) MutableGoogleAuthenticatorSetting(io.picos.sailfish.mfa.google.spi.MutableGoogleAuthenticatorSetting) DefaultGoogleAuthenticatorSetting(io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting) Date(java.util.Date)

Example 4 with DefaultGoogleAuthenticatorSetting

use of io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting in project sailfish-mfa by picos-io.

the class GoogleAuthnServiceImpl method disableGoogleAuthenticator.

/**
 * Disable the GoogleAuthenticator for specified identity whatever the GoogleAuthenticator existed or not.
 *
 * @param username
 */
@Override
public void disableGoogleAuthenticator(String username) {
    MutableGoogleAuthenticatorSetting googleAuthenticatorSetting = (MutableGoogleAuthenticatorSetting) googleAuthenticatorStore.findByUsername(username);
    if (googleAuthenticatorSetting == null) {
        return;
    }
    googleAuthenticatorSetting.setEnabled(false);
    if (googleAuthenticatorSetting instanceof DefaultGoogleAuthenticatorSetting) {
        ((DefaultGoogleAuthenticatorSetting) googleAuthenticatorSetting).setModifiedAt(new Date());
    }
    googleAuthenticatorStore.saveOrUpdate(googleAuthenticatorSetting);
}
Also used : MutableGoogleAuthenticatorSetting(io.picos.sailfish.mfa.google.spi.MutableGoogleAuthenticatorSetting) DefaultGoogleAuthenticatorSetting(io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting) Date(java.util.Date)

Aggregations

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