Skip to content

Commit

Permalink
Merge pull request grpc#7842 from jboeuf/security_context_extension
Browse files Browse the repository at this point in the history
Adding extension points for security context.
  • Loading branch information
markdroth authored Aug 31, 2016
2 parents fbe8428 + bb04c0a commit 79d7d99
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/grpc++/impl/codegen/client_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ class ClientContext {
};
static void SetGlobalCallbacks(GlobalCallbacks* callbacks);

// Should be used for framework-level extensions only.
// Applications never need to call this method.
grpc_call* c_call() { return call_; }

private:
// Disallow copy and assign.
ClientContext(const ClientContext&);
Expand Down
4 changes: 4 additions & 0 deletions include/grpc++/impl/codegen/server_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ class ServerContext {
async_notify_when_done_tag_ = tag;
}

// Should be used for framework-level extensions only.
// Applications never need to call this method.
grpc_call* c_call() { return call_; }

private:
friend class ::grpc::testing::InteropServerContextInspector;
friend class ::grpc::ServerInterface;
Expand Down
6 changes: 6 additions & 0 deletions src/core/lib/security/context/security_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ void grpc_client_security_context_destroy(void *ctx) {
grpc_client_security_context *c = (grpc_client_security_context *)ctx;
grpc_call_credentials_unref(c->creds);
GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context");
if (c->extension.instance != NULL && c->extension.destroy != NULL) {
c->extension.destroy(c->extension.instance);
}
gpr_free(ctx);
}

Expand All @@ -114,6 +117,9 @@ grpc_server_security_context *grpc_server_security_context_create(void) {
void grpc_server_security_context_destroy(void *ctx) {
grpc_server_security_context *c = (grpc_server_security_context *)ctx;
GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "server_security_context");
if (c->extension.instance != NULL && c->extension.destroy != NULL) {
c->extension.destroy(c->extension.instance);
}
gpr_free(ctx);
}

Expand Down
12 changes: 12 additions & 0 deletions src/core/lib/security/context/security_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,24 @@ void grpc_auth_context_unref(grpc_auth_context *policy);

void grpc_auth_property_reset(grpc_auth_property *property);

/* --- grpc_security_context_extension ---
Extension to the security context that may be set in a filter and accessed
later by a higher level method on a grpc_call object. */

typedef struct {
void *instance;
void (*destroy)(void *);
} grpc_security_context_extension;

/* --- grpc_client_security_context ---
Internal client-side security context. */

typedef struct {
grpc_call_credentials *creds;
grpc_auth_context *auth_context;
grpc_security_context_extension extension;
} grpc_client_security_context;

grpc_client_security_context *grpc_client_security_context_create(void);
Expand All @@ -102,6 +113,7 @@ void grpc_client_security_context_destroy(void *ctx);

typedef struct {
grpc_auth_context *auth_context;
grpc_security_context_extension extension;
} grpc_server_security_context;

grpc_server_security_context *grpc_server_security_context_create(void);
Expand Down

0 comments on commit 79d7d99

Please sign in to comment.