Search in sources :

Example 16 with ServiceException

use of com.nexblocks.authguard.service.exceptions.ServiceException in project AuthGuard by AuthGuard.

the class JwtConfigParser method parseEc.

private static Algorithm parseEc(final String algorithmName, final String publicKeyPath, final String privateKeyPath) {
    final byte[] publicKey = KeyLoader.readPemKeyFile(publicKeyPath);
    final byte[] privateKey = KeyLoader.readPemKeyFile(privateKeyPath);
    final KeyPair keyPair = readEcKeys(publicKey, privateKey);
    switch(algorithmName) {
        case "EC256":
            return Algorithm.ECDSA256((ECPublicKey) keyPair.getPublic(), (ECPrivateKey) keyPair.getPrivate());
        case "EC512":
            return Algorithm.ECDSA512((ECPublicKey) keyPair.getPublic(), (ECPrivateKey) keyPair.getPrivate());
        case "EC256K":
            return Algorithm.ECDSA256K((ECPublicKey) keyPair.getPublic(), (ECPrivateKey) keyPair.getPrivate());
        default:
            throw new ServiceException(ErrorCode.UNSUPPORTED_JWT_ALGORITHM, "Unsupported algorithm " + algorithmName);
    }
}
Also used : KeyPair(java.security.KeyPair) ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException)

Example 17 with ServiceException

use of com.nexblocks.authguard.service.exceptions.ServiceException in project AuthGuard by AuthGuard.

the class JwtConfigParser method parseRsa.

private static Algorithm parseRsa(final String algorithmName, final String publicKeyPath, final String privateKeyPath) {
    final byte[] publicKey = KeyLoader.readPemKeyFile(publicKeyPath);
    final byte[] privateKey = KeyLoader.readPemKeyFile(privateKeyPath);
    final KeyPair keyPair = readRsaKeys(publicKey, privateKey);
    switch(algorithmName) {
        case "RSA256":
            return Algorithm.RSA256((RSAPublicKey) keyPair.getPublic(), (RSAPrivateKey) keyPair.getPrivate());
        case "RSA512":
            return Algorithm.RSA512((RSAPublicKey) keyPair.getPublic(), (RSAPrivateKey) keyPair.getPrivate());
        default:
            throw new ServiceException(ErrorCode.UNSUPPORTED_JWT_ALGORITHM, "Unsupported algorithm " + algorithmName);
    }
}
Also used : KeyPair(java.security.KeyPair) ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException)

Aggregations

ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)17 AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)8 ServiceNotFoundException (com.nexblocks.authguard.service.exceptions.ServiceNotFoundException)6 OffsetDateTime (java.time.OffsetDateTime)6 Inject (com.google.inject.Inject)5 AccountsService (com.nexblocks.authguard.service.AccountsService)5 ErrorCode (com.nexblocks.authguard.service.exceptions.codes.ErrorCode)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)4 AccountTokensRepository (com.nexblocks.authguard.dal.cache.AccountTokensRepository)3 MessageBus (com.nexblocks.authguard.emb.MessageBus)3 Messages (com.nexblocks.authguard.emb.Messages)3 IdempotencyService (com.nexblocks.authguard.service.IdempotencyService)3 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)3 ServiceConflictException (com.nexblocks.authguard.service.exceptions.ServiceConflictException)3 ActionTokenBO (com.nexblocks.authguard.service.model.ActionTokenBO)3 Duration (java.time.Duration)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Named (com.google.inject.name.Named)2 com.nexblocks.authguard.basic.passwords (com.nexblocks.authguard.basic.passwords)2