use of org.curioswitch.common.server.framework.auth.ssl.SslAuthorizer in project curiostack by curioswitch.
the class ServerModule method decorateService.
private static HttpService decorateService(HttpService service, Tracing tracing, Lazy<FirebaseAuthorizer> firebaseAuthorizer, Lazy<JwtAuthorizer.Factory> jwtAuthorizer, Optional<SslCommonNamesProvider> sslCommonNamesProvider, ServerConfig serverConfig, FirebaseAuthConfig authConfig) {
if (sslCommonNamesProvider.isPresent() && !serverConfig.isDisableSslAuthorization()) {
AuthServiceBuilder authServiceBuilder = AuthService.builder();
authServiceBuilder.add(new SslAuthorizer(sslCommonNamesProvider.get()));
service = service.decorate(authServiceBuilder.newDecorator());
}
if (serverConfig.isEnableIapAuthorization()) {
service = service.decorate((delegate, ctx, req) -> {
DecodedJWT jwt = ctx.attr(JwtAuthorizer.DECODED_JWT);
String loggedInUserEmail = jwt != null ? jwt.getClaim("email").asString() : "unknown";
RequestLoggingContext.put(ctx, "logged_in_user", loggedInUserEmail);
return delegate.serve(ctx, req);
}).decorate(AuthService.builder().addTokenAuthorizer(headers -> OAuth2Token.of(headers.get(HttpHeaderNames.of("x-goog-iap-jwt-assertion"))), jwtAuthorizer.get().create(Algorithm.ES256, "https://www.gstatic.com/iap/verify/public_key")).newDecorator());
}
if (!authConfig.getServiceAccountBase64().isEmpty()) {
FirebaseAuthorizer authorizer = firebaseAuthorizer.get();
service = service.decorate(AuthService.builder().addOAuth2(authorizer).onFailure(authorizer).newDecorator());
}
service = service.decorate(MetricCollectingService.newDecorator(RpcMetricLabels.grpcRequestLabeler("grpc_services"))).decorate(BraveService.newDecorator(tracing)).decorate((delegate, ctx, req) -> {
TraceContext traceCtx = tracing.currentTraceContext().get();
if (traceCtx != null) {
RequestLoggingContext.put(ctx, "traceId", traceCtx.traceIdString());
RequestLoggingContext.put(ctx, "spanId", traceCtx.spanIdString());
}
return delegate.serve(ctx, req);
});
return service;
}
Aggregations