Search in sources :

Example 1 with KeyLengthException

use of com.nimbusds.jose.KeyLengthException in project knox by apache.

the class DefaultTokenAuthorityService method signTokenWithHMAC.

private void signTokenWithHMAC(final JWT token) throws TokenServiceException {
    try {
        final JWSSigner signer = new MACSigner(getHmacSecret());
        token.sign(signer);
    } catch (KeyLengthException e) {
        throw new TokenServiceException(e);
    }
}
Also used : MACSigner(com.nimbusds.jose.crypto.MACSigner) JWSSigner(com.nimbusds.jose.JWSSigner) KeyLengthException(com.nimbusds.jose.KeyLengthException) TokenServiceException(org.apache.knox.gateway.services.security.token.TokenServiceException)

Example 2 with KeyLengthException

use of com.nimbusds.jose.KeyLengthException in project knox by apache.

the class TokenResource method setSignatureAlogrithm.

private void setSignatureAlogrithm() throws AliasServiceException, KeyLengthException {
    final String configuredSigAlg = context.getInitParameter(TOKEN_SIG_ALG);
    final GatewayConfig config = (GatewayConfig) request.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
    final GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    AliasService aliasService = services.getService(ServiceType.ALIAS_SERVICE);
    signatureAlgorithm = TokenUtils.getSignatureAlgorithm(configuredSigAlg, aliasService, config.getSigningKeystoreName());
    char[] hmacSecret = aliasService.getPasswordFromAliasForGateway(TokenUtils.SIGNING_HMAC_SECRET_ALIAS);
    if (hmacSecret != null && !isAlgCompatibleWithSecret(signatureAlgorithm, hmacSecret)) {
        throw new KeyLengthException(JWSAlgorithm.parse(signatureAlgorithm));
    }
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) KeyLengthException(com.nimbusds.jose.KeyLengthException) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig)

Aggregations

KeyLengthException (com.nimbusds.jose.KeyLengthException)2 JWSSigner (com.nimbusds.jose.JWSSigner)1 MACSigner (com.nimbusds.jose.crypto.MACSigner)1 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)1 GatewayServices (org.apache.knox.gateway.services.GatewayServices)1 AliasService (org.apache.knox.gateway.services.security.AliasService)1 TokenServiceException (org.apache.knox.gateway.services.security.token.TokenServiceException)1