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 java.lang.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 Summary
Fields Modifier and Type Field Description static java.lang.StringALL_PATHSstatic java.lang.StringALLOW_EFFECTstatic java.lang.StringANY_HTTP_METHODstatic java.lang.StringANY_RESOURCEstatic intAPI_GATEWAY_IDENTIFIER_INDEXstatic java.lang.StringAUTHORIZATION_HEADERstatic java.lang.StringCOULD_NOT_READ_PRINCIPAL_ID_ERRORstatic java.lang.StringEXECUTE_API_ACTIONstatic java.lang.StringPATH_DELIMITERstatic intSTAGE_INDEX
-
Constructor Summary
Constructors Modifier Constructor Description protectedRequestAuthorizer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleancallerIsAllowedToPerformAction(com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent requestInfo)protected AuthPolicycreateAllowAuthPolicy(java.lang.String methodArn)protected AuthPolicycreateDenyAuthPolicy()protected abstract java.lang.StringfetchSecret()protected java.lang.StringformatPolicyResource(java.lang.String methodArn)This method can be overridden to change the template of the accessed resource.AuthorizerResponsehandleRequest(com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent input, com.amazonaws.services.lambda.runtime.Context context)protected abstract java.lang.StringprincipalId()
-
-
-
Field Detail
-
EXECUTE_API_ACTION
public static final java.lang.String EXECUTE_API_ACTION
- See Also:
- Constant Field Values
-
ALLOW_EFFECT
public static final java.lang.String ALLOW_EFFECT
- See Also:
- Constant Field Values
-
ANY_RESOURCE
public static final java.lang.String ANY_RESOURCE
- See Also:
- Constant Field Values
-
ANY_HTTP_METHOD
public static final java.lang.String ANY_HTTP_METHOD
- See Also:
- Constant Field Values
-
ALL_PATHS
public static final java.lang.String ALL_PATHS
- See Also:
- Constant Field Values
-
PATH_DELIMITER
public static final java.lang.String PATH_DELIMITER
- See Also:
- Constant Field Values
-
API_GATEWAY_IDENTIFIER_INDEX
public static final int API_GATEWAY_IDENTIFIER_INDEX
- See Also:
- Constant Field Values
-
STAGE_INDEX
public static final int STAGE_INDEX
- See Also:
- Constant Field Values
-
AUTHORIZATION_HEADER
public static final java.lang.String AUTHORIZATION_HEADER
- See Also:
- Constant Field Values
-
COULD_NOT_READ_PRINCIPAL_ID_ERROR
public static final java.lang.String COULD_NOT_READ_PRINCIPAL_ID_ERROR
- See Also:
- Constant Field Values
-
-
Method Detail
-
handleRequest
public AuthorizerResponse handleRequest(com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent input, com.amazonaws.services.lambda.runtime.Context context)
- Specified by:
handleRequestin interfacecom.amazonaws.services.lambda.runtime.RequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent,AuthorizerResponse>
-
formatPolicyResource
protected java.lang.String formatPolicyResource(java.lang.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(java.lang.String methodArn)
-
createDenyAuthPolicy
protected AuthPolicy createDenyAuthPolicy()
-
principalId
protected abstract java.lang.String principalId()
-
fetchSecret
protected abstract java.lang.String fetchSecret() throws ForbiddenException- Throws:
ForbiddenException
-
callerIsAllowedToPerformAction
protected boolean callerIsAllowedToPerformAction(com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent requestInfo) throws ForbiddenException- Throws:
ForbiddenException
-
-