Search in sources :

Example 1 with GoogleAuthenticatorKey

use of com.warrenstrange.googleauth.GoogleAuthenticatorKey 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 GoogleAuthenticatorKey

use of com.warrenstrange.googleauth.GoogleAuthenticatorKey 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 3 with GoogleAuthenticatorKey

use of com.warrenstrange.googleauth.GoogleAuthenticatorKey in project cia by Hack23.

the class SetGoogleAuthenticatorCredentialService method processService.

@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
public SetGoogleAuthenticatorCredentialResponse processService(final SetGoogleAuthenticatorCredentialRequest serviceRequest) {
    final SetGoogleAuthenticatorCredentialResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getSessionId());
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    final SetGoogleAuthenticatorCredentialResponse response = new SetGoogleAuthenticatorCredentialResponse(ServiceResult.SUCCESS);
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
        final GoogleAuthenticator gAuth = new GoogleAuthenticator();
        final GoogleAuthenticatorKey gKey = gAuth.createCredentials();
        final UserAccount updateUserAccount = userDAO.load(userAccount.getHjid());
        updateUserAccount.setGoogleAuthKey(gKey.getKey());
        updateUserAccount.setGoogleAuthVerificationCode(gKey.getVerificationCode());
        updateUserAccount.setGoogleAuthScratchCodes(gKey.getScratchCodes());
        userDAO.merge(updateUserAccount);
        final String otpAuthTotpURL = GoogleAuthenticatorQRGenerator.getOtpAuthTotpURL(agencyDAO.getAll().get(0).getAgencyName(), updateUserAccount.getEmail(), gKey);
        response.setOtpAuthTotpURL(otpAuthTotpURL);
        response.setGoogleAuthKey(gKey.getKey());
        response.setGoogleAuthVerificationCode(gKey.getVerificationCode());
        response.setGoogleAuthScratchCodes(gKey.getScratchCodes());
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : GoogleAuthenticatorKey(com.warrenstrange.googleauth.GoogleAuthenticatorKey) GoogleAuthenticator(com.warrenstrange.googleauth.GoogleAuthenticator) SetGoogleAuthenticatorCredentialResponse(com.hack23.cia.service.api.action.user.SetGoogleAuthenticatorCredentialResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

GoogleAuthenticatorKey (com.warrenstrange.googleauth.GoogleAuthenticatorKey)3 MutableGoogleAuthenticatorSetting (io.picos.sailfish.mfa.google.spi.MutableGoogleAuthenticatorSetting)2 DefaultGoogleAuthenticatorSetting (io.picos.sailfish.mfa.google.spi.mongo.DefaultGoogleAuthenticatorSetting)2 Date (java.util.Date)2 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)1 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)1 SetGoogleAuthenticatorCredentialResponse (com.hack23.cia.service.api.action.user.SetGoogleAuthenticatorCredentialResponse)1 GoogleAuthenticator (com.warrenstrange.googleauth.GoogleAuthenticator)1 AuthenticatorNotFoundException (io.picos.sailfish.mfa.google.exception.AuthenticatorNotFoundException)1 Secured (org.springframework.security.access.annotation.Secured)1