Search in sources :

Example 1 with TwoFactorAuthenticationType

use of eu.bcvsolutions.idm.core.security.api.domain.TwoFactorAuthenticationType in project CzechIdMng by bcvsolutions.

the class DefaultTwoFactorAuthenticationManager method requireTwoFactorAuthentication.

@Override
@Transactional
public boolean requireTwoFactorAuthentication(UUID identityId, UUID tokenId) {
    // check two factor authentication is enabled
    TwoFactorAuthenticationType twoFactorAuthenticationType = getTwoFactorAuthenticationType(identityId);
    if (twoFactorAuthenticationType == null) {
        return false;
    }
    // 
    IdmTokenDto token = tokenManager.getToken(tokenId);
    if (token.isSecretVerified()) {
        // token was already verified
        return false;
    }
    // 
    if (TwoFactorAuthenticationType.NOTIFICATION == twoFactorAuthenticationType) {
        IdmPasswordDto password = passwordService.findOneByIdentity(identityId);
        if (password == null) {
            throw new EntityNotFoundException(IdmIdentityDto.class, identityId);
        }
        sendVerificationCode(identityService.get(identityId), generateCode(new GuardedString(password.getVerificationSecret())));
    }
    // 
    return true;
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) TwoFactorAuthenticationType(eu.bcvsolutions.idm.core.security.api.domain.TwoFactorAuthenticationType) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)1 IdmTokenDto (eu.bcvsolutions.idm.core.api.dto.IdmTokenDto)1 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 TwoFactorAuthenticationType (eu.bcvsolutions.idm.core.security.api.domain.TwoFactorAuthenticationType)1 Transactional (org.springframework.transaction.annotation.Transactional)1