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);
}
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);
}
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;
}
Aggregations