Search in sources :

Example 11 with JwtConfig

use of com.nexblocks.authguard.service.config.JwtConfig in project AuthGuard by AuthGuard.

the class TokenEncryptorAdapterTest method initializeWithUnsupportedAlgorithm.

@Test
void initializeWithUnsupportedAlgorithm() {
    final JwtConfig jwtConfig = JwtConfig.builder().encryption(EncryptionConfig.builder().algorithm("unknown").build()).build();
    assertThatThrownBy(() -> new TokenEncryptorAdapter(jwtConfig)).isInstanceOf(ConfigurationException.class);
}
Also used : JwtConfig(com.nexblocks.authguard.service.config.JwtConfig) Test(org.junit.jupiter.api.Test)

Example 12 with JwtConfig

use of com.nexblocks.authguard.service.config.JwtConfig in project AuthGuard by AuthGuard.

the class TokenEncryptorAdapterTest method encryptAndDecryptNotEnabled.

@Test
void encryptAndDecryptNotEnabled() {
    final JwtConfig jwtConfig = JwtConfig.builder().build();
    final TokenEncryptorAdapter encryptor = new TokenEncryptorAdapter(jwtConfig);
    assertThat(encryptor.encryptAndEncode("").isLeft()).isTrue();
    assertThat(encryptor.decryptEncoded("").isLeft()).isTrue();
}
Also used : JwtConfig(com.nexblocks.authguard.service.config.JwtConfig) Test(org.junit.jupiter.api.Test)

Example 13 with JwtConfig

use of com.nexblocks.authguard.service.config.JwtConfig in project AuthGuard by AuthGuard.

the class TokenEncryptorAdapterTest method encryptAndDecryptAes.

@Test
void encryptAndDecryptAes() {
    final JwtConfig jwtConfig = JwtConfig.builder().encryption(EncryptionConfig.builder().algorithm("AES_CBC").privateKey("src/test/resources/aes128.txt").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);
}
Also used : JwtConfig(com.nexblocks.authguard.service.config.JwtConfig) Test(org.junit.jupiter.api.Test)

Aggregations

JwtConfig (com.nexblocks.authguard.service.config.JwtConfig)13 Test (org.junit.jupiter.api.Test)11 StrategyConfig (com.nexblocks.authguard.service.config.StrategyConfig)5 AccountBO (com.nexblocks.authguard.service.model.AccountBO)5 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)4 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)4 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)4 Algorithm (com.auth0.jwt.algorithms.Algorithm)3