-
Notifications
You must be signed in to change notification settings - Fork 140
fix: enforce @RolesAllowed on microservice resources #5049
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
Open
Ma77Ball
wants to merge
20
commits into
apache:main
Choose a base branch
from
Ma77Ball:fix/RolesAllowedUnenforced
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e6ffc27
enforce @RolesAllowed on microservice resources
Ma77Ball 9c49941
Add dropwizard-auth as a dependency for workflow-compiling-service
Ma77Ball f029770
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball 6f6da20
Added appropriate licenses to License-binary
Ma77Ball e513a47
Merge remote-tracking branch 'origin/fix/RolesAllowedUnenforced' into…
Ma77Ball 76b1eff
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball 950bf39
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball 3dcfef8
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball a7963fd
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball 0a86a8f
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball 93f40f3
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball 5fda988
Added test
Ma77Ball 993e28b
Merge remote-tracking branch 'origin/fix/RolesAllowedUnenforced' into…
Ma77Ball e1bdf9e
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball 46812ef
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball a5ba0e9
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball ec42428
extract registerAuthFeatures to decouple Jersey setup from DB init
Ma77Ball df10f86
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball 877960f
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball 47a21a3
Merge branch 'main' into fix/RolesAllowedUnenforced
Ma77Ball File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
48 changes: 48 additions & 0 deletions
48
...ervice/src/test/scala/org/apache/texera/service/ComputingUnitManagingServiceRunSpec.scala
This file contains hidden or 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,48 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.texera.service | ||
|
|
||
| import io.dropwizard.auth.{AuthDynamicFeature, AuthValueFactoryProvider} | ||
| import io.dropwizard.core.setup.Environment | ||
| import io.dropwizard.jersey.setup.JerseyEnvironment | ||
| import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature | ||
| import org.mockito.Mockito.{mock, verify, when} | ||
| import org.scalatest.flatspec.AnyFlatSpec | ||
| import org.scalatest.matchers.should.Matchers | ||
|
|
||
| class ComputingUnitManagingServiceRunSpec extends AnyFlatSpec with Matchers { | ||
|
|
||
| // Verifies that the @RolesAllowed annotations on resource methods are actually | ||
| // enforced by Jersey, which requires RolesAllowedDynamicFeature, AuthDynamicFeature, | ||
| // and AuthValueFactoryProvider.Binder to be registered on the Jersey environment. | ||
| "ComputingUnitManagingService.registerAuthFeatures" should "register auth + RolesAllowedDynamicFeature on the Jersey environment" in { | ||
| val jersey = mock(classOf[JerseyEnvironment]) | ||
| val env = mock(classOf[Environment]) | ||
| when(env.jersey).thenReturn(jersey) | ||
|
|
||
| ComputingUnitManagingService.registerAuthFeatures(env) | ||
|
|
||
| verify(jersey).register(classOf[RolesAllowedDynamicFeature]) | ||
| verify(jersey).register(org.mockito.ArgumentMatchers.any(classOf[AuthDynamicFeature])) | ||
| verify(jersey).register( | ||
| org.mockito.ArgumentMatchers.any(classOf[AuthValueFactoryProvider.Binder[_]]) | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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
55 changes: 55 additions & 0 deletions
55
config-service/src/test/scala/org/apache/texera/service/ConfigServiceRunSpec.scala
This file contains hidden or 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,55 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.texera.service | ||
|
|
||
| import io.dropwizard.core.setup.Environment | ||
| import io.dropwizard.jersey.setup.JerseyEnvironment | ||
| import io.dropwizard.jetty.MutableServletContextHandler | ||
| import io.dropwizard.jetty.setup.ServletEnvironment | ||
| import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature | ||
| import org.mockito.Mockito.{mock, verify, when} | ||
| import org.scalatest.flatspec.AnyFlatSpec | ||
| import org.scalatest.matchers.should.Matchers | ||
|
|
||
| class ConfigServiceRunSpec extends AnyFlatSpec with Matchers { | ||
|
|
||
| // Verifies that the @RolesAllowed annotations on ConfigResource are actually | ||
| // enforced by Jersey, which requires RolesAllowedDynamicFeature to be | ||
| // registered on the Jersey environment. | ||
| "ConfigService.run" should "register RolesAllowedDynamicFeature on the Jersey environment" in { | ||
| val jersey = mock(classOf[JerseyEnvironment]) | ||
| val servlets = mock(classOf[ServletEnvironment]) | ||
| val context = mock(classOf[MutableServletContextHandler]) | ||
| val env = mock(classOf[Environment]) | ||
| when(env.jersey).thenReturn(jersey) | ||
| when(env.servlets).thenReturn(servlets) | ||
| when(env.getApplicationContext).thenReturn(context) | ||
|
|
||
| val service = new ConfigService | ||
| // run() reaches into SqlServer near the end to preload defaults; that throws | ||
| // here because no real DB is wired up. By that point all Jersey registrations | ||
| // have already executed, so the verification below is still valid. | ||
| intercept[Exception] { | ||
| service.run(mock(classOf[ConfigServiceConfiguration]), env) | ||
| } | ||
|
|
||
| verify(jersey).register(classOf[RolesAllowedDynamicFeature]) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
48 changes: 48 additions & 0 deletions
48
...ng-service/src/test/scala/org/apache/texera/service/WorkflowCompilingServiceRunSpec.scala
This file contains hidden or 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,48 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.texera.service | ||
|
|
||
| import io.dropwizard.auth.{AuthDynamicFeature, AuthValueFactoryProvider} | ||
| import io.dropwizard.core.setup.Environment | ||
| import io.dropwizard.jersey.setup.JerseyEnvironment | ||
| import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature | ||
| import org.mockito.Mockito.{mock, verify, when} | ||
| import org.scalatest.flatspec.AnyFlatSpec | ||
| import org.scalatest.matchers.should.Matchers | ||
|
|
||
| class WorkflowCompilingServiceRunSpec extends AnyFlatSpec with Matchers { | ||
|
|
||
| // Verifies that the @RolesAllowed annotations on resource methods are actually | ||
| // enforced by Jersey, which requires RolesAllowedDynamicFeature, AuthDynamicFeature, | ||
| // and AuthValueFactoryProvider.Binder to be registered on the Jersey environment. | ||
| "WorkflowCompilingService.registerAuthFeatures" should "register auth + RolesAllowedDynamicFeature on the Jersey environment" in { | ||
| val jersey = mock(classOf[JerseyEnvironment]) | ||
| val env = mock(classOf[Environment]) | ||
| when(env.jersey).thenReturn(jersey) | ||
|
|
||
| WorkflowCompilingService.registerAuthFeatures(env) | ||
|
|
||
| verify(jersey).register(classOf[RolesAllowedDynamicFeature]) | ||
| verify(jersey).register(org.mockito.ArgumentMatchers.any(classOf[AuthDynamicFeature])) | ||
| verify(jersey).register( | ||
| org.mockito.ArgumentMatchers.any(classOf[AuthValueFactoryProvider.Binder[_]]) | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.