-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AWS Lambda HTTP Security Integration
sam local docs convert lambda security to auth mechanism default providers add mechanism if empty credential types use QuarkusPrincipal fix test don't fire mech if request not set revert idp
- Loading branch information
1 parent
505876b
commit 3d39209
Showing
43 changed files
with
1,296 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...ent/src/main/java/io/quarkus/amazon/lambda/http/deployment/LambdaHttpBuildTimeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.amazon.lambda.http.deployment; | ||
|
||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
@ConfigRoot | ||
public class LambdaHttpBuildTimeConfig { | ||
/** | ||
* Enable security mechanisms to process lambda and AWS based security (i.e. Cognito, IAM) from | ||
* the http event sent from API Gateway | ||
*/ | ||
@ConfigItem(defaultValue = "false") | ||
public boolean enableSecurity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...zon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/CognitoPrincipal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.amazon.lambda.http; | ||
|
||
import java.security.Principal; | ||
|
||
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; | ||
|
||
/** | ||
* Represents a Cognito JWT used to authenticate request | ||
* | ||
* Will only be allocated if requestContext.authorizer.jwt.claims.cognito:username is set | ||
* in the http event sent by API Gateway | ||
*/ | ||
public class CognitoPrincipal implements Principal { | ||
private APIGatewayV2HTTPEvent.RequestContext.Authorizer.JWT jwt; | ||
private String name; | ||
|
||
public CognitoPrincipal(APIGatewayV2HTTPEvent.RequestContext.Authorizer.JWT jwt) { | ||
this.jwt = jwt; | ||
this.name = jwt.getClaims().get("cognito:username"); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public APIGatewayV2HTTPEvent.RequestContext.Authorizer.JWT getClaims() { | ||
return jwt; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...azon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/CustomPrincipal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.amazon.lambda.http; | ||
|
||
import java.security.Principal; | ||
import java.util.Map; | ||
|
||
/** | ||
* Represents a custom principal sent by API Gateway i.e. a Lambda authorizer | ||
* | ||
* Will only be allocated if requestContext.authorizer.lambda.principalId is set | ||
* in the http event sent by API Gateway | ||
* | ||
*/ | ||
public class CustomPrincipal implements Principal { | ||
private String name; | ||
private Map<String, Object> claims; | ||
|
||
public CustomPrincipal(String name, Map<String, Object> claims) { | ||
this.claims = claims; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Map<String, Object> getClaims() { | ||
return claims; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ntime/src/main/java/io/quarkus/amazon/lambda/http/DefaultLambdaAuthenticationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkus.amazon.lambda.http; | ||
|
||
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; | ||
|
||
import io.quarkus.security.identity.request.BaseAuthenticationRequest; | ||
|
||
/** | ||
* This will execute if and only if there is no identity after invoking a LambdaAuthenticationRequest | ||
*/ | ||
final public class DefaultLambdaAuthenticationRequest extends BaseAuthenticationRequest { | ||
private APIGatewayV2HTTPEvent event; | ||
|
||
public DefaultLambdaAuthenticationRequest(APIGatewayV2HTTPEvent event) { | ||
this.event = event; | ||
} | ||
|
||
public APIGatewayV2HTTPEvent getEvent() { | ||
return event; | ||
} | ||
} |
Oops, something went wrong.