-
-
Notifications
You must be signed in to change notification settings - Fork 35
Normalize permission model #1207
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
jhoward-lm
wants to merge
36
commits into
DependencyTrack:main
Choose a base branch
from
jhoward-lm:normalize-permission-model
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 34 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
23057e5
refactor: normalize permission model
jhoward-lm c32a1c4
Merge branch 'main' of https://github.com/DependencyTrack/hyades-apis…
jhoward-lm 5498303
fix: accidental overwrite during resolve
jhoward-lm 2c4e931
test: fix asserts
jhoward-lm b3d3882
test: enable portfolio access control where needed
jhoward-lm a68d944
fix: generated JDBI statement
jhoward-lm 1b2ad79
test: fix asserts
jhoward-lm df7ddda
test: fix asserts
jhoward-lm 082cac6
Merge branch 'main' of https://github.com/jhoward-lm/hyades-apiserver…
jhoward-lm aa48c35
chore: revert workaround
jhoward-lm f59b065
refactor: validate that only project-scoped permissions can be added …
jhoward-lm abcdfe4
chore: resolve PR conflict
jhoward-lm 0ef25e7
refactor: add migration to update old permissions
jhoward-lm 384b7e2
refactor: clean up migration DDL
jhoward-lm fb58cbb
refactor: use temp tables for migrations
jhoward-lm 3eff73c
fix: population of existing permission map
jhoward-lm 5891fd9
fix: update references to changed permission names
jhoward-lm d44ec9f
Merge branch 'main' into normalize-permission-model
jhoward-lm b442807
fix: checkstyle violation
jhoward-lm aa1306b
fix: update references to changed permission names
jhoward-lm b56ab2e
fix: permissions for update/patch projects
jhoward-lm 527e98a
Merge branch 'main' of https://github.com/DependencyTrack/hyades-apis…
jhoward-lm 64a49e4
fix: permissions in v2 resources
jhoward-lm ffaefaf
fix: permissions in v2 resources
jhoward-lm 47534df
test: fix permission setup
jhoward-lm 752229a
test: fix permission setup
jhoward-lm 41f82d6
fix: notification rule resource permissions
jhoward-lm ec6b9fb
Merge branch 'main' of https://github.com/DependencyTrack/hyades-apis…
jhoward-lm d54ab29
fix: changeset permission names, address comments
jhoward-lm 68665c4
fix: update v2 metrics resource
jhoward-lm b336128
Merge branch 'main' of github.com:DependencyTrack/hyades-apiserver in…
nscuro 21b608b
Fix missing unique index on `PERMISSION.NAME`
nscuro f21cc84
Merge pull request #16 from DependencyTrack/normalize-permission-mode…
jhoward-lm b54a60e
refactor: use explicit AND/OR with PermissionRequired
jhoward-lm 2bdf477
Merge branch 'main' of https://github.com/DependencyTrack/hyades-apis…
jhoward-lm 22923ba
chore: create new changelog file
jhoward-lm 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
45 changes: 45 additions & 0 deletions
45
apiserver/src/main/java/org/dependencytrack/model/validation/ValidRolePermission.java
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,45 @@ | ||
| /* | ||
| * This file is part of Dependency-Track. | ||
| * | ||
| * Licensed 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. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright (c) OWASP Foundation. All Rights Reserved. | ||
| */ | ||
| package org.dependencytrack.model.validation; | ||
|
|
||
| import jakarta.validation.Constraint; | ||
| import jakarta.validation.Payload; | ||
| import jakarta.validation.ReportAsSingleViolation; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| /** | ||
| * @since 5.6.0 | ||
| */ | ||
| @Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE_USE }) | ||
| @Constraint(validatedBy = ValidRolePermissionValidator.class) | ||
| @Retention(RUNTIME) | ||
| @ReportAsSingleViolation | ||
| public @interface ValidRolePermission { | ||
|
|
||
| String message() default "{org.dependencytrack.model.validation.ValidRolePermission.message}"; | ||
|
|
||
| Class<?>[] groups() default {}; | ||
|
|
||
| Class<? extends Payload>[] payload() default {}; | ||
|
|
||
| } |
63 changes: 63 additions & 0 deletions
63
...rver/src/main/java/org/dependencytrack/model/validation/ValidRolePermissionValidator.java
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,63 @@ | ||
| /* | ||
| * This file is part of Dependency-Track. | ||
| * | ||
| * Licensed 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. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright (c) OWASP Foundation. All Rights Reserved. | ||
| */ | ||
| package org.dependencytrack.model.validation; | ||
|
|
||
| import jakarta.validation.ConstraintValidator; | ||
| import jakarta.validation.ConstraintValidatorContext; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.dependencytrack.auth.Permissions; | ||
|
|
||
| /** | ||
| * @since 5.6.0 | ||
| */ | ||
| public class ValidRolePermissionValidator implements ConstraintValidator<ValidRolePermission, String> { | ||
|
|
||
| private static final List<String> PROJECT_PERMISSIONS = Stream.of(Permissions.values()) | ||
| .filter(Permissions::isProjectScope) | ||
| .map(Permissions::name) | ||
| .toList(); | ||
|
|
||
| private static final List<String> SYSTEM_PERMISSIONS = Stream.of(Permissions.values()) | ||
| .filter(Permissions::isSystemScope) | ||
| .map(Permissions::name) | ||
| .toList(); | ||
|
|
||
| @Override | ||
| public boolean isValid(final String permission, final ConstraintValidatorContext validatorContext) { | ||
| if (SYSTEM_PERMISSIONS.contains(permission)) { | ||
| validatorContext.buildConstraintViolationWithTemplate("System permissions cannot be assigned to roles") | ||
| .addConstraintViolation(); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| if (!PROJECT_PERMISSIONS.contains(permission)) { | ||
| validatorContext.buildConstraintViolationWithTemplate("Invalid permission name") | ||
| .addConstraintViolation(); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
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.
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.
Note so we don't forget:
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.
@nscuro I added a change set for the migration. Not sure if it's what you were looking for, so any suggestions are welcome. Will work on the frontend tomorrow