use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.
the class JwtPermissionsMapperTest method mapNoRestrictions.
@Test
void mapNoRestrictions() {
final AccountBO account = AccountBO.builder().permissions(Arrays.asList(PermissionBO.builder().group("test").name("read").build(), PermissionBO.builder().group("test").name("write").build(), PermissionBO.builder().group("test").name("nothing").build())).build();
final String[] expected = new String[] { "test:read", "test:write", "test:nothing" };
final String[] actual = JwtPermissionsMapper.map(account, null);
assertThat(Arrays.asList(actual)).isEqualTo(Arrays.asList(expected));
}
use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.
the class JwtPermissionsMapperTest method mapNoPermissionRestrictions.
@Test
void mapNoPermissionRestrictions() {
final AccountBO account = AccountBO.builder().permissions(Arrays.asList(PermissionBO.builder().group("test").name("read").build(), PermissionBO.builder().group("test").name("write").build(), PermissionBO.builder().group("test").name("nothing").build())).build();
final TokenRestrictionsBO restrictions = TokenRestrictionsBO.builder().build();
final String[] expected = new String[] { "test:read", "test:write", "test:nothing" };
final String[] actual = JwtPermissionsMapper.map(account, restrictions);
assertThat(Arrays.asList(actual)).isEqualTo(Arrays.asList(expected));
}
use of com.nexblocks.authguard.service.model.AccountBO 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");
}
});
}
use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.
the class AuthorizationCodeProviderTest method generateToken.
@Test
void generateToken() {
final AccountTokensRepository accountTokensRepository = Mockito.mock(AccountTokensRepository.class);
final AuthorizationCodeProvider authorizationCodeProvider = new AuthorizationCodeProvider(accountTokensRepository, new ServiceMapperImpl(), config());
final AccountBO account = AccountBO.builder().id("account-id").build();
final AuthResponseBO tokens = authorizationCodeProvider.generateToken(account);
assertThat(tokens.getType()).isEqualTo("authorizationCode");
assertThat(tokens.getToken()).isNotNull();
assertThat(tokens.getRefreshToken()).isNull();
final ArgumentCaptor<AccountTokenDO> argCaptor = ArgumentCaptor.forClass(AccountTokenDO.class);
Mockito.verify(accountTokensRepository, Mockito.times(1)).save(argCaptor.capture());
assertThat(argCaptor.getValue().getToken()).isEqualTo(tokens.getToken());
assertThat(argCaptor.getValue().getAssociatedAccountId()).isEqualTo(account.getId());
assertThat(argCaptor.getValue().getExpiresAt()).isAfter(OffsetDateTime.now()).isBefore(OffsetDateTime.now().plus(Duration.ofMinutes(6)));
}
use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.
the class JwtTokenVerifierTest method validate.
@Test
void validate() {
final StrategyConfig strategyConfig = strategyConfig(false);
final JwtConfig jwtConfig = jwtConfig();
final JwtTokenVerifier jwtTokenVerifier = newVerifierInstance(strategyConfig);
final AccountBO account = RANDOM.nextObject(AccountBO.class);
final AuthResponseBO tokens = generateToken(jwtConfig, account, null);
final Either<Exception, DecodedJWT> validatedToken = jwtTokenVerifier.verify(tokens.getToken().toString());
assertThat(validatedToken.isRight()).isTrue();
verifyToken(validatedToken.get(), account.getId(), null, null, null);
}
Aggregations