use of com.nexblocks.authguard.service.config.JwtConfig in project AuthGuard by AuthGuard.
the class JwtSignatureAlgorithmsTest method createVerifier.
private JwtTokenVerifier createVerifier(final String algorithm, final String publicKey, final String privateKey) {
final JwtConfig jwtConfig = jwtConfig(algorithm, publicKey, privateKey);
final Algorithm parsedAlgorithm = JwtConfigParser.parseAlgorithm(jwtConfig.getAlgorithm(), jwtConfig.getPublicKey(), jwtConfig.getPrivateKey());
return new JwtTokenVerifier(strategyConfig(), null, parsedAlgorithm);
}
use of com.nexblocks.authguard.service.config.JwtConfig 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);
}
use of com.nexblocks.authguard.service.config.JwtConfig in project AuthGuard by AuthGuard.
the class JwtTokenVerifierTest method validateWithJti.
@Test
void validateWithJti() {
final StrategyConfig strategyConfig = strategyConfig(true);
final JwtConfig jwtConfig = jwtConfig();
final JwtTokenVerifier jwtTokenVerifier = newVerifierInstance(strategyConfig);
final String jti = UUID.randomUUID().toString();
Mockito.when(jtiProvider.next()).thenReturn(jti);
Mockito.when(jtiProvider.validate(jti)).thenReturn(true);
final AccountBO account = RANDOM.nextObject(AccountBO.class);
final AuthResponseBO tokens = generateToken(jwtConfig, account, jti);
final Either<Exception, DecodedJWT> validatedToken = jwtTokenVerifier.verify(tokens.getToken().toString());
assertThat(validatedToken.isRight()).isTrue();
verifyToken(validatedToken.get(), account.getId(), jti, null, null);
}
use of com.nexblocks.authguard.service.config.JwtConfig in project AuthGuard by AuthGuard.
the class TokenEncryptorAdapterTest method encryptAndDecryptEllipticCurve.
@Test
void encryptAndDecryptEllipticCurve() {
final JwtConfig jwtConfig = JwtConfig.builder().encryption(EncryptionConfig.builder().algorithm("EC").publicKey("src/test/resources/ec256-public.pem").privateKey("src/test/resources/ec256-private.pem").build()).build();
final TokenEncryptorAdapter encryptor = new TokenEncryptorAdapter(jwtConfig);
final String encrypted = encryptor.encryptAndEncode(TOKEN).get();
final String decrypted = encryptor.decryptEncoded(encrypted).get();
assertThat(decrypted).isEqualTo(TOKEN);
}
use of com.nexblocks.authguard.service.config.JwtConfig in project AuthGuard by AuthGuard.
the class TokenEncryptorAdapterTest method initializeWithWrongKeys.
@Test
void initializeWithWrongKeys() {
final JwtConfig jwtConfig = JwtConfig.builder().encryption(EncryptionConfig.builder().algorithm("EC").publicKey("src/test/resources/hmac256.pem").privateKey("src/test/resources/hmac256.pem").build()).build();
assertThatThrownBy(() -> new TokenEncryptorAdapter(jwtConfig)).isInstanceOf(ConfigurationException.class);
}
Aggregations