-
-
Notifications
You must be signed in to change notification settings - Fork 36
Add roles #1069
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
Merged
Merged
Add roles #1069
Changes from 32 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
844807d
refactor: add changeset for new tables
ashearin 3951a8d
feat: add role and mappedrole classes (#2)
ashearin a538ecf
refactor: add changeset for new tables
ashearin 62aa1ea
fix: changeset unique constraints
ashearin 7e7bf31
Define new Role permissisons & Initial creation of RoleResource.java …
jmayer-lm d0cd774
add roleQueryManager method stubs (#6)
lmphil 63d8c2f
Add /v1/user Endpoints & CRUD Method Stubs (#7)
jmayer-lm 0400b83
Add default roles and permissions for project management (#8)
EphraimEM 53b42cf
fix: add role UUID field (#9)
jhoward-lm 9959ada
refactor: implement role endpoint methods (#10)
jhoward-lm 1a0cc70
feat: get user project permissions (wip) (#11)
lmphil 07aedbe
refactor: implement adding/removing users to/from roles (#13)
jhoward-lm 68cd5a8
refactor: flatten user role join tables (#14)
jhoward-lm 17a5210
refactor: create view of project effective permissions for user (#15)
jhoward-lm 894d799
Role DAO fixes (#16)
jhoward-lm 02c3b03
Revert "feat: get user project permissions (wip) (#11)" (#17)
ashearin 38dfe4f
refactor: add triggers to update effective permissions table with rol…
jhoward-lm 29a21fc
test: add unit tests for RoleQueryManager class (#19)
lmphil 4dc0e77
test: add RoleResource unit tests (#20)
lmphil ba28c80
Update createRole API to create a new role with permissions (#22)
alamb-lm 90bd768
Merge pull request #23 from jhoward-lm/roles-consolidate-user-tables
jhoward-lm d1cca65
fix: cascade delete user foreign key (#24)
jhoward-lm 5b77284
Regenerate jooq with role tables
ashearin a922bba
Endpoint request changes and unittests (#26)
emeremikwu-lm 8b8f1e9
chore: clean up rebase
jhoward-lm 7e7d87e
tests: codacy cleanup
ashearin 025e192
fix: remove getUserProjectPermissions from roleQueryManager
ashearin 6fee046
fix: adjust asserts in testGetUnassignedProjects
ashearin ba51997
refactor: address PR comments
ashearin a003314
refactor: migrate JDBI methods to query manager (#27)
jhoward-lm 40ab23c
Merge branch 'main' into add-roles-model
jhoward-lm 62a889b
refactor: renamed RoleProjectRequest to ModifyUserProjectRoleRequest
ashearin 85b4379
refactor: change List<User> field to User
jhoward-lm 5e008f1
chore: remove unused method
jhoward-lm f377f15
chore: redo test cleanup and name change
ashearin b6685d0
style: fix codacy style issues
jhoward-lm 4a76f33
Merge branch 'main' of https://github.com/DependencyTrack/hyades-apis…
jhoward-lm ffa2975
style: formatting
jhoward-lm 3bf1846
tests: add additional unit tests
ashearin 63f1690
tests: add additional unit test coverage
ashearin eda79ac
chore: cleanup merge duplication
ashearin 12e8d76
chore: remove unused imports
ashearin 237b9c7
chore: address PR comments
ashearin b4006b5
fix: combine user project effective permissions triggers
jhoward-lm 4d0d0f0
refactor: update addRoleToUser to check for existing role on project
ashearin a4e2699
Merge branch 'main' of https://github.com/jhoward-lm/hyades-apiserver…
jhoward-lm 40d69f5
refactor: schema suggestions
jhoward-lm 9325a10
fix: trigger function call
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
152 changes: 152 additions & 0 deletions
152
apiserver/src/main/java/org/dependencytrack/model/Role.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,152 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import alpine.common.validation.RegexSequence; | ||
| import alpine.model.Permission; | ||
| import alpine.server.json.TrimmedStringDeserializer; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Pattern; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| import java.util.LinkedHashSet; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
|
|
||
| import javax.jdo.annotations.Column; | ||
| import javax.jdo.annotations.Element; | ||
| import javax.jdo.annotations.FetchGroup; | ||
| import javax.jdo.annotations.IdGeneratorStrategy; | ||
| import javax.jdo.annotations.Join; | ||
| import javax.jdo.annotations.PersistenceCapable; | ||
| import javax.jdo.annotations.Persistent; | ||
| import javax.jdo.annotations.PrimaryKey; | ||
| import javax.jdo.annotations.Unique; | ||
|
|
||
| /** | ||
| * Model for tracking roles. Roles define static sets of permissions | ||
| * that can be applied to a user with the scope of a project. | ||
| * | ||
| * @author Allen Shearin | ||
| * @since 5.6.0 | ||
| */ | ||
| @PersistenceCapable | ||
| @FetchGroup(name = "ALL", members = { | ||
| @Persistent(name = "name"), | ||
| @Persistent(name = "permissions"), | ||
| @Persistent(name = "uuid"), | ||
| }) | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public class Role implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = -427858073810766917L; | ||
|
|
||
| /** | ||
| * Defines JDO fetch groups for this class. | ||
| */ | ||
| public enum FetchGroup { | ||
| ALL | ||
| } | ||
|
|
||
| @PrimaryKey | ||
| @Persistent(valueStrategy = IdGeneratorStrategy.NATIVE) | ||
| @JsonIgnore | ||
| private long id; | ||
|
|
||
| @Persistent | ||
| @Unique(name = "ROLE_NAME_IDX", deferred = "true") | ||
| @Column(name = "NAME", jdbcType = "VARCHAR", allowsNull = "false") | ||
| @NotBlank | ||
| @Size(min = 1, max = 255) | ||
| @JsonDeserialize(using = TrimmedStringDeserializer.class) | ||
| @Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The name may only contain printable characters") | ||
| private String name; | ||
|
|
||
| @Persistent(table = "ROLES_PERMISSIONS", defaultFetchGroup = "true") | ||
| @Join(column = "ROLE_ID") | ||
| @Element(column = "PERMISSION_ID") | ||
| private Set<Permission> permissions = new LinkedHashSet<>(); | ||
|
|
||
| @Persistent(customValueStrategy = "uuid") | ||
| @Unique(name = "ROLE_UUID_IDX") | ||
| @Column(name = "UUID", sqlType = "UUID", allowsNull = "false") | ||
| @NotNull | ||
| private UUID uuid; | ||
|
|
||
| public long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public Set<Permission> getPermissions() { | ||
| return permissions; | ||
| } | ||
|
|
||
| public void setPermissions(Set<Permission> permissions) { | ||
| this.permissions = permissions; | ||
| } | ||
|
|
||
| public boolean addPermissions(Permission... permissions) { | ||
| this.permissions = Objects.requireNonNullElse(this.permissions, new LinkedHashSet<>()); | ||
|
|
||
| return this.permissions.addAll(Set.of(permissions)); | ||
| } | ||
|
|
||
| public UUID getUuid() { | ||
| return uuid; | ||
| } | ||
|
|
||
| public void setUuid(UUID uuid) { | ||
| this.uuid = uuid; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| var permissionStrings = permissions.stream() | ||
| .map(permission -> permission.getName()) | ||
| .toList(); | ||
|
|
||
| return "%s{uuid='%s', name='%s', permissions=%s}".formatted( | ||
| getClass().getSimpleName(), | ||
| uuid, | ||
| name, | ||
| permissionStrings); | ||
| } | ||
|
|
||
| } |
105 changes: 105 additions & 0 deletions
105
apiserver/src/main/java/org/dependencytrack/model/UserProjectRole.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,105 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
|
||
| import alpine.model.User; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import javax.jdo.annotations.Column; | ||
| import javax.jdo.annotations.Element; | ||
| import javax.jdo.annotations.Extension; | ||
| import javax.jdo.annotations.Order; | ||
| import javax.jdo.annotations.PersistenceCapable; | ||
| import javax.jdo.annotations.Persistent; | ||
| import javax.jdo.annotations.PrimaryKey; | ||
|
|
||
| /** | ||
| * Base class for user-project-role mapping. | ||
| * | ||
| * @author Jonathan Howard | ||
| * @since 5.6.0 | ||
| */ | ||
| @PersistenceCapable(table = "USER_PROJECT_ROLES") | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| @PrimaryKey(name = "USER_PROJECT_ROLES_PK", columns = { | ||
| @Column(name = "USER_ID"), | ||
| @Column(name = "PROJECT_ID"), | ||
| @Column(name = "ROLE_ID") | ||
| }) | ||
| public class UserProjectRole implements Serializable { | ||
|
|
||
| @Persistent(defaultFetchGroup = "true") | ||
| @Column(name = "ROLE_ID", allowsNull = "false") | ||
| private Role role; | ||
|
|
||
| @Persistent(defaultFetchGroup = "true") | ||
| @Column(name = "PROJECT_ID", allowsNull = "false") | ||
| private Project project; | ||
|
|
||
| @Persistent(defaultFetchGroup = "true") | ||
| @Element(column = "USER_ID") | ||
| @Order(extensions = @Extension(vendorName = "datanucleus", key = "list-ordering", value = "username ASC")) | ||
| private List<User> users; | ||
|
|
||
| public List<User> getUsers() { | ||
| return users; | ||
| } | ||
|
|
||
| public void setUsers(List<User> users) { | ||
| this.users = users; | ||
| } | ||
|
|
||
| public Role getRole() { | ||
| return role; | ||
| } | ||
|
|
||
| public void setRole(Role role) { | ||
| this.role = role; | ||
| } | ||
|
|
||
| public Project getProject() { | ||
| return project; | ||
| } | ||
|
|
||
| public void setProject(Project project) { | ||
| this.project = project; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| // var userStrings = users.stream() | ||
| // .map(user -> user.getUsername()) | ||
| // .toList(); | ||
|
|
||
| return "%s{role='%s', project='%s'}".formatted( | ||
| getClass().getSimpleName(), | ||
| role, | ||
| project); | ||
| //userStrings); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.