-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert lambda security to auth mechanism
- Loading branch information
1 parent
5085f15
commit f9df78c
Showing
19 changed files
with
211 additions
and
287 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
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
17 changes: 17 additions & 0 deletions
17
...http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaAuthenticationRequest.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,17 @@ | ||
package io.quarkus.amazon.lambda.http; | ||
|
||
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; | ||
|
||
import io.quarkus.security.identity.request.BaseAuthenticationRequest; | ||
|
||
public class LambdaAuthenticationRequest extends BaseAuthenticationRequest { | ||
private APIGatewayV2HTTPEvent event; | ||
|
||
public LambdaAuthenticationRequest(APIGatewayV2HTTPEvent event) { | ||
this.event = event; | ||
} | ||
|
||
public APIGatewayV2HTTPEvent getEvent() { | ||
return event; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...untime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpAuthenticationMechanism.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,61 @@ | ||
package io.quarkus.amazon.lambda.http; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; | ||
|
||
import io.quarkus.security.identity.IdentityProviderManager; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
import io.quarkus.security.identity.request.AuthenticationRequest; | ||
import io.quarkus.vertx.http.runtime.QuarkusHttpHeaders; | ||
import io.quarkus.vertx.http.runtime.security.ChallengeData; | ||
import io.quarkus.vertx.http.runtime.security.HttpAuthenticationMechanism; | ||
import io.quarkus.vertx.http.runtime.security.HttpCredentialTransport; | ||
import io.quarkus.vertx.http.runtime.security.HttpSecurityUtils; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.core.MultiMap; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
@ApplicationScoped | ||
public class LambdaHttpAuthenticationMechanism implements HttpAuthenticationMechanism { | ||
@Override | ||
public Uni<SecurityIdentity> authenticate(RoutingContext routingContext, IdentityProviderManager identityProviderManager) { | ||
MultiMap qheaders = routingContext.request().headers(); | ||
if (qheaders instanceof QuarkusHttpHeaders) { | ||
Map<Class<?>, Object> contextObjects = ((QuarkusHttpHeaders) qheaders).getContextObjects(); | ||
if (contextObjects.containsKey(APIGatewayV2HTTPEvent.class)) { | ||
APIGatewayV2HTTPEvent event = (APIGatewayV2HTTPEvent) contextObjects.get(APIGatewayV2HTTPEvent.class); | ||
Uni<SecurityIdentity> identity = identityProviderManager | ||
.authenticate(HttpSecurityUtils.setRoutingContextAttribute( | ||
new LambdaAuthenticationRequest(event), routingContext)); | ||
return identity; | ||
} | ||
} | ||
return Uni.createFrom().optional(Optional.empty()); | ||
} | ||
|
||
@Override | ||
public Uni<Boolean> sendChallenge(RoutingContext context) { | ||
return Uni.createFrom().item(false); | ||
} | ||
|
||
@Override | ||
public Uni<ChallengeData> getChallenge(RoutingContext context) { | ||
return Uni.createFrom().nullItem(); | ||
} | ||
|
||
@Override | ||
public Set<Class<? extends AuthenticationRequest>> getCredentialTypes() { | ||
return Collections.singleton(LambdaAuthenticationRequest.class); | ||
} | ||
|
||
@Override | ||
public HttpCredentialTransport getCredentialTransport() { | ||
return null; | ||
} | ||
} |
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
13 changes: 0 additions & 13 deletions
13
...n-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpRecorder.java
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
...mbda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaIdentityProvider.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,42 @@ | ||
package io.quarkus.amazon.lambda.http; | ||
|
||
import java.util.Optional; | ||
|
||
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; | ||
|
||
import io.quarkus.security.identity.AuthenticationRequestContext; | ||
import io.quarkus.security.identity.IdentityProvider; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
/** | ||
* Helper interface that removes some boilerplate for creating | ||
* an IdentityProvider that processes APIGatewayV2HTTPEvent | ||
*/ | ||
public interface LambdaIdentityProvider extends IdentityProvider<LambdaAuthenticationRequest> { | ||
@Override | ||
default public Class<LambdaAuthenticationRequest> getRequestType() { | ||
return LambdaAuthenticationRequest.class; | ||
} | ||
|
||
@Override | ||
default Uni<SecurityIdentity> authenticate(LambdaAuthenticationRequest request, AuthenticationRequestContext context) { | ||
APIGatewayV2HTTPEvent event = request.getEvent(); | ||
SecurityIdentity identity = authenticate(event); | ||
if (identity == null) { | ||
return Uni.createFrom().optional(Optional.empty()); | ||
} | ||
return Uni.createFrom().item(identity); | ||
} | ||
|
||
/** | ||
* Helper method that reduces some code. You can ignore if you directly override | ||
* IdentityProvider.authenticate | ||
* | ||
* @param event | ||
* @return | ||
*/ | ||
default SecurityIdentity authenticate(APIGatewayV2HTTPEvent event) { | ||
return null; | ||
} | ||
} |
64 changes: 0 additions & 64 deletions
64
...mbda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaSecurityIdentity.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...p/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaSecurityIdentityProvider.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
...bda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/SecurityIdentityHandler.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.