Class RequestAuthorizer

java.lang.Object
no.unit.commons.apigateway.authentication.RequestAuthorizer
All Implemented Interfaces:
com.amazonaws.services.lambda.runtime.RequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent,AuthorizerResponse>
Direct Known Subclasses:
DefaultRequestAuthorizer

public abstract class RequestAuthorizer extends Object implements com.amazonaws.services.lambda.runtime.RequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent,AuthorizerResponse>
Abstract class for implementing a Request Authorizer. Implementation is based on the AWS examples found in the following page : "https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer .html".
  • Field Details

  • Constructor Details

    • RequestAuthorizer

      protected RequestAuthorizer()
  • Method Details

    • handleRequest

      public AuthorizerResponse handleRequest(com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent input, com.amazonaws.services.lambda.runtime.Context context)
      Specified by:
      handleRequest in interface com.amazonaws.services.lambda.runtime.RequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent,AuthorizerResponse>
    • formatPolicyResource

      protected String formatPolicyResource(String methodArn)
      This method can be overridden to change the template of the accessed resource. The resource that access will be allowed to. It can contain wildcards.

      Example methodARN: arn:aws:execute-api:eu-west-1:884807050265:2lcqynkwke/Prod/GET/some/path/to/resource Example output: arn:aws:execute-api:eu-west-1:884807050265:2lcqynkwke/Prod\/*\/*

      Another possible output is: "*"

      Parameters:
      methodArn - the method ARN as provided by the API gateway
      Returns:
      a resource for the policy
    • createAllowAuthPolicy

      protected AuthPolicy createAllowAuthPolicy(String methodArn)
    • createDenyAuthPolicy

      protected AuthPolicy createDenyAuthPolicy()
    • principalId

      protected abstract String principalId()
    • fetchSecret

      protected abstract String fetchSecret() throws ForbiddenException
      Throws:
      ForbiddenException
    • callerIsAllowedToPerformAction

      protected boolean callerIsAllowedToPerformAction(com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent requestInfo) throws ForbiddenException
      Throws:
      ForbiddenException