Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
844807d
refactor: add changeset for new tables
ashearin Feb 17, 2025
3951a8d
feat: add role and mappedrole classes (#2)
ashearin Feb 24, 2025
a538ecf
refactor: add changeset for new tables
ashearin Feb 20, 2025
62aa1ea
fix: changeset unique constraints
ashearin Feb 21, 2025
7e7bf31
Define new Role permissisons & Initial creation of RoleResource.java …
jmayer-lm Feb 25, 2025
d0cd774
add roleQueryManager method stubs (#6)
lmphil Feb 26, 2025
63d8c2f
Add /v1/user Endpoints & CRUD Method Stubs (#7)
jmayer-lm Feb 27, 2025
0400b83
Add default roles and permissions for project management (#8)
EphraimEM Feb 27, 2025
53b42cf
fix: add role UUID field (#9)
jhoward-lm Mar 3, 2025
9959ada
refactor: implement role endpoint methods (#10)
jhoward-lm Mar 3, 2025
1a0cc70
feat: get user project permissions (wip) (#11)
lmphil Mar 29, 2025
07aedbe
refactor: implement adding/removing users to/from roles (#13)
jhoward-lm Mar 4, 2025
68cd5a8
refactor: flatten user role join tables (#14)
jhoward-lm Mar 17, 2025
17a5210
refactor: create view of project effective permissions for user (#15)
jhoward-lm Mar 19, 2025
894d799
Role DAO fixes (#16)
jhoward-lm Mar 24, 2025
02c3b03
Revert "feat: get user project permissions (wip) (#11)" (#17)
ashearin Mar 29, 2025
38dfe4f
refactor: add triggers to update effective permissions table with rol…
jhoward-lm Apr 1, 2025
29a21fc
test: add unit tests for RoleQueryManager class (#19)
lmphil May 7, 2025
4dc0e77
test: add RoleResource unit tests (#20)
lmphil May 7, 2025
ba28c80
Update createRole API to create a new role with permissions (#22)
alamb-lm Apr 30, 2025
90bd768
Merge pull request #23 from jhoward-lm/roles-consolidate-user-tables
jhoward-lm May 12, 2025
d1cca65
fix: cascade delete user foreign key (#24)
jhoward-lm May 14, 2025
5b77284
Regenerate jooq with role tables
ashearin May 21, 2025
a922bba
Endpoint request changes and unittests (#26)
emeremikwu-lm May 23, 2025
8b8f1e9
chore: clean up rebase
jhoward-lm May 23, 2025
7e7d87e
tests: codacy cleanup
ashearin May 23, 2025
025e192
fix: remove getUserProjectPermissions from roleQueryManager
ashearin May 24, 2025
6fee046
fix: adjust asserts in testGetUnassignedProjects
ashearin May 24, 2025
ba51997
refactor: address PR comments
ashearin May 26, 2025
a003314
refactor: migrate JDBI methods to query manager (#27)
jhoward-lm May 28, 2025
40ab23c
Merge branch 'main' into add-roles-model
jhoward-lm May 28, 2025
62a889b
refactor: renamed RoleProjectRequest to ModifyUserProjectRoleRequest
ashearin May 30, 2025
85b4379
refactor: change List<User> field to User
jhoward-lm May 30, 2025
5e008f1
chore: remove unused method
jhoward-lm May 30, 2025
f377f15
chore: redo test cleanup and name change
ashearin May 30, 2025
b6685d0
style: fix codacy style issues
jhoward-lm May 30, 2025
4a76f33
Merge branch 'main' of https://github.com/DependencyTrack/hyades-apis…
jhoward-lm May 31, 2025
ffa2975
style: formatting
jhoward-lm May 31, 2025
3bf1846
tests: add additional unit tests
ashearin May 31, 2025
63f1690
tests: add additional unit test coverage
ashearin Jun 1, 2025
eda79ac
chore: cleanup merge duplication
ashearin Jun 1, 2025
12e8d76
chore: remove unused imports
ashearin Jun 1, 2025
237b9c7
chore: address PR comments
ashearin Jun 2, 2025
b4006b5
fix: combine user project effective permissions triggers
jhoward-lm Jun 2, 2025
4d0d0f0
refactor: update addRoleToUser to check for existing role on project
ashearin Jun 2, 2025
a4e2699
Merge branch 'main' of https://github.com/jhoward-lm/hyades-apiserver…
jhoward-lm Jun 3, 2025
40d69f5
refactor: schema suggestions
jhoward-lm Jun 3, 2025
9325a10
fix: trigger function call
jhoward-lm Jun 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import java.util.Map;
import java.util.Set;

import org.datanucleus.store.rdbms.query.JDOQLQuery;

/**
* This QueryManager provides a concrete extension of {@link AbstractAlpineQueryManager} by
* providing methods that operate on the default Alpine models such as ManagedUser and Team.
Expand Down Expand Up @@ -537,8 +539,11 @@ public List<ManagedUser> getManagedUsers() {
* @since 1.0.0
*/
public User getUser(String username) {
final Query<User> query = pm.newQuery(User.class, "username == :username");
query.setParameters(username);
final Query<User> query = pm.newQuery(User.class)
.filter("username == :username")
.setNamedParameters(Map.of("username", username))
.extension(JDOQLQuery.EXTENSION_CANDIDATE_DONT_RESTRICT_DISCRIMINATOR, true);

return executeAndCloseUnique(query);
}

Expand Down
154 changes: 154 additions & 0 deletions apiserver/src/main/java/org/dependencytrack/model/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* 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.Comparator;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;

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::getName)
.sorted(Comparator.comparing(Function.identity(), String.CASE_INSENSITIVE_ORDER))
.toList();

return "%s{uuid='%s', name='%s', permissions=%s}".formatted(
getClass().getSimpleName(),
uuid,
name,
permissionStrings);
}

}
109 changes: 109 additions & 0 deletions apiserver/src/main/java/org/dependencytrack/model/UserProjectRole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* 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.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;

import alpine.model.User;

import java.io.Serializable;

import javax.jdo.annotations.Column;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Index;
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)
@Index(name = "USER_PROJECT_ROLES_IDX", unique = "true", members = { "user", "project" })
public class UserProjectRole implements Serializable {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.NATIVE)
@JsonIgnore
private long id;

@Persistent(defaultFetchGroup = "true")
@Column(name = "USER_ID")
private User user;

@Persistent(defaultFetchGroup = "true")
@Column(name = "PROJECT_ID")
private Project project;

@Persistent(defaultFetchGroup = "true")
@Column(name = "ROLE_ID")
private Role role;

public UserProjectRole() {}

public UserProjectRole(final User user, final Project project, final Role role) {
this.user = user;
this.project = project;
this.role = role;
}

public long getId() {
return id;
}

public void setId(final long id) {
this.id = id;
}

public User getUser() {
return user;
}

public void setUser(final User user) {
this.user = user;
}

public Project getProject() {
return project;
}

public void setProject(final Project project) {
this.project = project;
}

public Role getRole() {
return role;
}

public void setRole(final Role role) {
this.role = role;
}

@Override
public String toString() {
return "%s{user='%s', project='%s', role='%s'}".formatted(
getClass().getSimpleName(), user.getUsername(), project.getName(), role.getName());
}

}
Loading
Loading