Search in sources :

Example 21 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.

the class SmsPasswordlessSubscriberTest method onValidMessageNoPhoneNumber.

@Test
void onValidMessageNoPhoneNumber() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().build();
    final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
    final Message message = Messages.passwordlessGenerated(messageBody);
    smsPasswordlessSubscriber.onMessage(message);
    Mockito.verify(smsProvider, Mockito.never()).send(Mockito.any());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody) Test(org.junit.jupiter.api.Test)

Example 22 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.

the class AccessTokenProvider method storeRefreshToken.

private void storeRefreshToken(final String accountId, final String refreshToken, final TokenRestrictionsBO tokenRestrictions) {
    final AccountTokenDO accountToken = AccountTokenDO.builder().id(ID.generate()).token(refreshToken).associatedAccountId(accountId).expiresAt(refreshTokenExpiry()).tokenRestrictions(// Mapstruct already checks for null
    serviceMapper.toDO(tokenRestrictions)).build();
    accountTokensRepository.save(accountToken).join();
}
Also used : AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO)

Example 23 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.

the class AuthorizationCodeProvider method generateToken.

@Override
public AuthResponseBO generateToken(final AccountBO account, final TokenRestrictionsBO restrictions, final TokenOptionsBO options) {
    final String code = random.base64(config.getRandomSize());
    final AccountTokenDO accountToken = AccountTokenDO.builder().token(TOKEN_TYPE).id(ID.generate()).token(code).associatedAccountId(account.getId()).expiresAt(OffsetDateTime.now().plus(tokenTtl)).tokenRestrictions(serviceMapper.toDO(restrictions)).build();
    accountTokensRepository.save(accountToken);
    return AuthResponseBO.builder().type("authorizationCode").token(code).entityType(EntityType.ACCOUNT).entityId(account.getId()).build();
}
Also used : AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO)

Example 24 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.

the class AccessTokenProviderTest method newProviderInstance.

private AccessTokenProvider newProviderInstance(final JwtConfig jwtConfig, final StrategyConfig strategyConfig) {
    jtiProvider = Mockito.mock(JtiProvider.class);
    accountTokensRepository = Mockito.mock(AccountTokensRepository.class);
    tokenEncryptor = Mockito.mock(TokenEncryptorAdapter.class);
    Mockito.when(accountTokensRepository.save(Mockito.any())).thenAnswer(invocation -> {
        final AccountTokenDO arg = invocation.getArgument(0);
        return CompletableFuture.completedFuture(arg);
    });
    return new AccessTokenProvider(accountTokensRepository, jwtConfig, strategyConfig, jtiProvider, tokenEncryptor, new ServiceMapperImpl());
}
Also used : AccountTokensRepository(com.nexblocks.authguard.dal.cache.AccountTokensRepository) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ServiceMapperImpl(com.nexblocks.authguard.service.mappers.ServiceMapperImpl) TokenEncryptorAdapter(com.nexblocks.authguard.jwt.crypto.TokenEncryptorAdapter)

Example 25 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.

the class VerificationSubscriber method doSendEmails.

private void doSendEmails(final VerificationRequestBO verificationRequest) {
    final AccountBO account = verificationRequest.getAccount();
    verificationRequest.getEmails().forEach(email -> {
        if (email == null) {
            LOG.warn("Email is null. Skipping.");
        } else if (email.isVerified()) {
            LOG.warn("Email is already verified. Skipping.");
        } else {
            final String token = generateVerificationString();
            final AccountTokenDO accountToken = AccountTokenDO.builder().expiresAt(OffsetDateTime.now().plus(tokenTtl)).associatedAccountId(account.getId()).token(token).additionalInformation(Collections.singletonMap("email", email.getEmail())).build();
            accountTokensRepository.save(accountToken);
            final ImmutableEmail email1 = ImmutableEmail.builder().template(EMAIL_TEMPLATE).to(email.getEmail()).putParameters("token", token).build();
            emailProvider.send(email1);
            LOG.info("Sent a verification email");
        }
    });
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ImmutableEmail(com.nexblocks.authguard.external.email.ImmutableEmail)

Aggregations

AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)36 Test (org.junit.jupiter.api.Test)22 AccountBO (com.nexblocks.authguard.service.model.AccountBO)21 Message (com.nexblocks.authguard.emb.model.Message)9 PasswordlessMessageBody (com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody)8 ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)8 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)7 AccountTokensRepository (com.nexblocks.authguard.dal.cache.AccountTokensRepository)6 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)6 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)5 ResetTokenMessage (com.nexblocks.authguard.service.messaging.ResetTokenMessage)5 OffsetDateTime (java.time.OffsetDateTime)5 ImmutableEmail (com.nexblocks.authguard.external.email.ImmutableEmail)4 ImmutableTextMessage (com.nexblocks.authguard.external.sms.ImmutableTextMessage)3 ServiceNotFoundException (com.nexblocks.authguard.service.exceptions.ServiceNotFoundException)3 ActionTokenBO (com.nexblocks.authguard.service.model.ActionTokenBO)3 Optional (java.util.Optional)3 Inject (com.google.inject.Inject)2 AccountsService (com.nexblocks.authguard.service.AccountsService)2 ErrorCode (com.nexblocks.authguard.service.exceptions.codes.ErrorCode)2