-
Notifications
You must be signed in to change notification settings - Fork 358
security: add authorization checks to UsageHandler #16158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ | |
| import io.cdap.cdap.proto.id.ApplicationId; | ||
| import io.cdap.cdap.proto.id.DatasetId; | ||
| import io.cdap.cdap.proto.id.ProgramId; | ||
| import io.cdap.cdap.proto.security.StandardPermission; | ||
| import io.cdap.cdap.security.spi.authorization.ContextAccessEnforcer; | ||
| import io.cdap.http.AbstractHttpHandler; | ||
| import io.cdap.http.HttpResponder; | ||
| import io.netty.handler.codec.http.HttpRequest; | ||
|
|
@@ -41,10 +43,12 @@ public class UsageHandler extends AbstractHttpHandler { | |
|
|
||
| private static final Gson GSON = new Gson(); | ||
| private final UsageRegistry registry; | ||
| private final ContextAccessEnforcer contextAccessEnforcer; | ||
|
|
||
| @Inject | ||
| public UsageHandler(UsageRegistry registry) { | ||
| public UsageHandler(UsageRegistry registry, ContextAccessEnforcer contextAccessEnforcer) { | ||
| this.registry = registry; | ||
| this.contextAccessEnforcer = contextAccessEnforcer; | ||
| } | ||
|
|
||
| @GET | ||
|
|
@@ -53,6 +57,7 @@ public void getAppDatasetUsage(HttpRequest request, HttpResponder responder, | |
| @PathParam("namespace-id") String namespaceId, | ||
| @PathParam("app-id") String appId) { | ||
| final ApplicationId id = new ApplicationId(namespaceId, appId); | ||
| contextAccessEnforcer.enforce(id, StandardPermission.GET); | ||
| Set<DatasetId> ids = registry.getDatasets(id); | ||
| responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids)); | ||
| } | ||
|
|
@@ -66,6 +71,7 @@ public void getProgramDatasetUsage(HttpRequest request, HttpResponder responder, | |
| @PathParam("program-id") String programId) { | ||
| ProgramType type = ProgramType.valueOfCategoryName(programType); | ||
| final ProgramId id = new ProgramId(namespaceId, appId, type, programId); | ||
| contextAccessEnforcer.enforce(id, StandardPermission.GET); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| Set<DatasetId> ids = registry.getDatasets(id); | ||
| responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids)); | ||
| } | ||
|
|
@@ -77,6 +83,7 @@ public void getDatasetAppUsage(HttpRequest request, HttpResponder responder, | |
| @PathParam("namespace-id") String namespaceId, | ||
| @PathParam("dataset-id") String datasetId) { | ||
| final DatasetId id = new DatasetId(namespaceId, datasetId); | ||
| contextAccessEnforcer.enforce(id, StandardPermission.GET); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| Set<ProgramId> ids = registry.getPrograms(id); | ||
| responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids)); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
contextAccessEnforcer.enforcemethod throwsAccessException, which is a checked exception. Since thegetAppDatasetUsagemethod does not declarethrows Exception(orthrows AccessException) in its signature, this will result in a compilation error. Please update the method signature to declarethrows Exception.