Skip to content
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

WIP: Feature/group permissions2.0 #277

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
628d0d9
propose migration of docker file to eclipse jdk
Jan 3, 2024
2903cf4
add gitignore changes
Jan 3, 2024
6073b04
trying to refactor group permissions
Enquier Apr 10, 2024
89815bb
Finalized refactor
Enquier Apr 17, 2024
9ce5178
removing GroupDAO
Enquier Apr 17, 2024
2c9def5
Merge branch 'feature/groupPermissions2.0' into snc-develop
Enquier Apr 17, 2024
462d8b0
Merge remote-tracking branch 'upstream/feature/docker-eclipse' into s…
Enquier Apr 17, 2024
ee80387
reverting ldap changes
Enquier Apr 17, 2024
96b4c23
Merge branch 'feature/groupPermissions2.0' into snc-develop
Enquier Apr 17, 2024
bec1636
fix lingering import
Enquier Apr 17, 2024
d43e7d2
Merge branch 'feature/groupPermissions2.0' into snc-develop
Enquier Apr 17, 2024
2c51e17
fix commit retrieval loop
Enquier Apr 17, 2024
6703a9e
Merge branch 'bugfix/commit-loop' into snc-develop
Enquier Apr 17, 2024
4c5de36
add missing set to delete
Enquier Apr 18, 2024
98cf62a
Merge branch 'bugfix/commit-loop' into snc-develop
Enquier Apr 18, 2024
28fbf1d
stronger comparison
Enquier Apr 18, 2024
03da763
Merge branch 'bugfix/commit-loop' into snc-develop
Enquier Apr 18, 2024
2f01a6c
more work on persistance refactor and auth updates
Enquier May 3, 2024
4c36ad9
add stash
Enquier May 3, 2024
ceee046
Merge commit '4c36ad944a27aa66fca4411754aace2d9150f4f6' into snc-develop
Enquier May 3, 2024
6cc2e30
bugfixes to group permissions
Enquier May 6, 2024
b5cafb8
feature/groupPermissions2.0
Enquier May 6, 2024
5b51661
fix error with documents add more admin functions for users controller
Enquier May 20, 2024
fdc3643
add features for delete and api updates
Enquier May 21, 2024
0ecd320
fix conflict with mdk
Enquier May 28, 2024
ecbf9dc
fix npe
Enquier May 29, 2024
f1c4e8f
group perms fixes
Enquier Jul 3, 2024
e7f1a20
fix gitignore
Enquier Jul 3, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
application.properties
localhost-env.json
.vscode
certs

### STS ###
.apt_generated
Expand Down
2 changes: 1 addition & 1 deletion authenticator/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ References
* `Overview of Spring Security <https://spring.io/guides/topicals/spring-security-architecture#_authentication_and_access_control>`_
* `UserDetails <https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/core/userdetails/UserDetails.html>`_
* `Authentication <https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/core/Authentication.html>`_
* :ref:`localuser`
* :ref:`localauth`
* :ref:`ldap`
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PermissionUpdatesResponseBuilder insertGroups(PermissionUpdateResponse pe
return this;
}

public PermissionUpdatesResponse getPermissionUpdatesReponse() {
public PermissionUpdatesResponse getPermissionUpdatesResponse() {
PermissionUpdatesResponse permissionUpdatesResponse = new PermissionUpdatesResponse();
permissionUpdatesResponse.setInherit(this.inherit);
permissionUpdatesResponse.setPublic(this.isPublic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public class AuthorizationConstants {
public static final String EVERYONE = "everyone";

public static final String ADMIN = "ADMIN";
public static final String READER = "READER";
public static final String WRITER = "WRITER";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Constants {
public static final String PROJECT_KEY = "projects";
public static final String BRANCH_KEY = "refs";
public static final String ELEMENT_KEY = "elements";
public static final String GROUP_KEY = "groups";
public static final String COMMIT_KEY = "commits";
public static final String WEBHOOK_KEY = "webhooks";
public static final String BRANCH_TYPE = "Branch";
Expand Down Expand Up @@ -40,9 +41,10 @@ public class Constants {
public static final String ELEMENT_DELETE = "Element Already Deleted";

static {
aPriv = Arrays.asList("ORG_READ", "ORG_EDIT", "ORG_UPDATE_PERMISSIONS", "ORG_READ_PERMISSIONS", "ORG_CREATE_PROJECT", "ORG_DELETE", "PROJECT_READ", "PROJECT_EDIT", "PROJECT_READ_COMMITS", "PROJECT_CREATE_BRANCH", "PROJECT_DELETE", "PROJECT_UPDATE_PERMISSIONS", "PROJECT_READ_PERMISSIONS", "PROJECT_CREATE_WEBHOOKS", "BRANCH_READ", "BRANCH_EDIT_CONTENT", "BRANCH_DELETE", "BRANCH_UPDATE_PERMISSIONS", "BRANCH_READ_PERMISSIONS");
rPriv = Arrays.asList("ORG_READ", "ORG_READ_PERMISSIONS", "PROJECT_READ", "PROJECT_READ_COMMITS", "PROJECT_READ_PERMISSIONS", "BRANCH_READ", "BRANCH_READ_PERMISSIONS");
wPriv = Arrays.asList("ORG_READ", "ORG_EDIT", "ORG_READ_PERMISSIONS", "ORG_CREATE_PROJECT", "PROJECT_READ", "PROJECT_EDIT", "PROJECT_READ_COMMITS", "PROJECT_CREATE_BRANCH", "PROJECT_READ_PERMISSIONS", "PROJECT_CREATE_WEBHOOKS", "BRANCH_READ", "BRANCH_EDIT_CONTENT", "BRANCH_READ_PERMISSIONS");

aPriv = Arrays.asList("ORG_READ", "ORG_EDIT", "ORG_UPDATE_PERMISSIONS", "ORG_READ_PERMISSIONS", "ORG_CREATE_PROJECT", "ORG_DELETE", "PROJECT_READ", "PROJECT_EDIT", "PROJECT_READ_COMMITS", "PROJECT_CREATE_BRANCH", "PROJECT_DELETE", "PROJECT_UPDATE_PERMISSIONS", "PROJECT_READ_PERMISSIONS", "PROJECT_CREATE_WEBHOOKS", "BRANCH_READ", "BRANCH_EDIT_CONTENT", "BRANCH_DELETE", "BRANCH_UPDATE_PERMISSIONS", "BRANCH_READ_PERMISSIONS", "GROUP_READ", "GROUP_EDIT", "GROUP_DELETE", "GROUP_UPDATE_PERMISSIONS", "GROUP_READ_PERMISSIONS");
rPriv = Arrays.asList("ORG_READ", "ORG_READ_PERMISSIONS", "PROJECT_READ", "PROJECT_READ_COMMITS", "PROJECT_READ_PERMISSIONS", "BRANCH_READ", "BRANCH_READ_PERMISSIONS", "GROUP_READ", "GROUP_READ_PERMISSIONS");
wPriv = Arrays.asList("ORG_READ", "ORG_EDIT", "ORG_READ_PERMISSIONS", "ORG_CREATE_PROJECT", "PROJECT_READ", "PROJECT_EDIT", "PROJECT_READ_COMMITS", "PROJECT_CREATE_BRANCH", "PROJECT_READ_PERMISSIONS", "PROJECT_CREATE_WEBHOOKS", "BRANCH_READ", "BRANCH_EDIT_CONTENT", "BRANCH_READ_PERMISSIONS", "GROUP_READ", "GROUP_EDIT", "GROUP_READ_PERMISSIONS");
RPmap.put(ADMIN, aPriv);
RPmap.put(READER, rPriv);
RPmap.put(WRITER, wPriv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public enum Privileges {
BRANCH_EDIT_CONTENT,
BRANCH_DELETE,
BRANCH_UPDATE_PERMISSIONS,
BRANCH_READ_PERMISSIONS
BRANCH_READ_PERMISSIONS,
GROUP_READ,
GROUP_EDIT,
GROUP_DELETE,
GROUP_UPDATE_PERMISSIONS,
GROUP_READ_PERMISSIONS

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface GroupPersistence {
void delete(GroupJson groupJson);
Optional<GroupJson> findByName(String name);
Collection<GroupJson> findAll();
boolean hasPublicPermissions(String projectId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public interface OrgPersistence {

Collection<OrgJson> findAll();

OrgJson deleteById(String orgId);
void deleteById(String orgId);

void archiveById(String orgId);

boolean hasPublicPermissions(String orgId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public interface ProjectPersistence {

Collection<ProjectJson> findAllByOrgId(String orgId);

void softDelete(String projectId);
void archiveById(String projectId);

void hardDelete(String projectId);
void deleteById(String projectId);

boolean inheritsPermissions(String projectId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.openmbee.mms.json.OrgJson;
import org.openmbee.mms.json.ProjectJson;
import org.openmbee.mms.json.RefJson;
import org.openmbee.mms.json.GroupJson;

public interface PermissionsDelegateFactory {

Expand All @@ -11,4 +12,6 @@ public interface PermissionsDelegateFactory {
PermissionsDelegate getPermissionsDelegate(OrgJson organization);

PermissionsDelegate getPermissionsDelegate(RefJson branch);

PermissionsDelegate getPermissionsDelegate(GroupJson group);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public List<OrgJson> getOrgs() {
return orgs;
}

public void setOrgs(List<OrgJson> orgs) {
public OrganizationsResponse setOrgs(List<OrgJson> orgs) {
this.orgs = orgs;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public static class PermissionUpdate {

private boolean inherited;

private String groupName;

public PermissionUpdate() {}

public PermissionUpdate(Action action, String name, String role, String orgId, String orgName,
String projectId, String projectName, String branchId, boolean inherited) {
String projectId, String projectName, String branchId, String groupName, boolean inherited) {
this.action = action;
this.name = name;
this.role = role;
Expand All @@ -42,6 +44,7 @@ public PermissionUpdate(Action action, String name, String role, String orgId, S
this.projectName = projectName;
this.branchId = branchId;
this.inherited = inherited;
this.groupName = groupName;
}

public Action getAction() {
Expand Down Expand Up @@ -118,6 +121,14 @@ public boolean isInherited() {
public void setInherited(boolean inherited) {
this.inherited = inherited;
}

public String getGroupName() {
return groupName;
}

public void setGroupName(String groupName) {
this.groupName = groupName;
}
}

public List<PermissionUpdate> getPermissionUpdates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.CompletionException;

import org.openmbee.mms.core.dao.BranchPersistence;
import org.openmbee.mms.core.dao.GroupPersistence;
import org.openmbee.mms.core.dao.ProjectPersistence;
import org.openmbee.mms.core.exceptions.NotFoundException;
import org.openmbee.mms.core.config.ContextHolder;
Expand All @@ -14,6 +15,7 @@
import org.openmbee.mms.json.OrgJson;
import org.openmbee.mms.json.ProjectJson;
import org.openmbee.mms.json.RefJson;
import org.openmbee.mms.json.GroupJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand All @@ -26,6 +28,7 @@ public class MethodSecurityService {
private ProjectPersistence projectPersistence;
private BranchPersistence branchPersistence;
private OrgPersistence orgPersistence;
private GroupPersistence groupPersistence;

@Autowired
public void setPermissionService(PermissionService permissionService) {
Expand All @@ -47,6 +50,11 @@ public void setBranchPersistence(BranchPersistence branchPersistence) {
this.branchPersistence = branchPersistence;
}

@Autowired
public void setGroupPersistence(GroupPersistence groupPersistence) {
this.groupPersistence = groupPersistence;
}

public boolean hasOrgPrivilege(Authentication authentication, String orgId, String privilege, boolean allowAnonIfPublic) {
CompletableFuture<Boolean> permissionsFuture = CompletableFuture.supplyAsync(() ->
{
Expand Down Expand Up @@ -104,6 +112,25 @@ public boolean hasBranchPrivilege(Authentication authentication, String projectI
return completeFutures(permissionsFuture, existsFuture, "Branch");
}

public boolean hasGroupPrivilege(Authentication authentication, String groupName, String privilege, boolean allowAnonIfPublic) {
CompletableFuture<Boolean> permissionsFuture = CompletableFuture.supplyAsync(() ->
{
if (allowAnonIfPublic && permissionService.isGroupPublic(groupName)) {
return true;
}
if (authentication == null || authentication instanceof AnonymousAuthenticationToken) {
return false;
}
if (permissionService.hasGroupPrivilege(privilege, authentication.getName(), AuthenticationUtils.getGroups(authentication), groupName)) {
return true;
}
return false;
});

CompletableFuture<Boolean> existsFuture = CompletableFuture.supplyAsync(() -> groupExists(groupName));
return completeFutures(permissionsFuture, existsFuture, "Group");
}

private boolean orgExists(String orgId) {
Optional<OrgJson> o = orgPersistence.findById(orgId);
return o.isPresent();
Expand All @@ -123,6 +150,11 @@ private boolean branchExists(String projectId, String branchId){
return branchesOption.isPresent();
}

private boolean groupExists(String groupName) {
Optional<GroupJson> g = groupPersistence.findByName(groupName);
return g.isPresent();
}

private boolean completeFutures(CompletableFuture<Boolean> permissionsFuture, CompletableFuture<Boolean> existsFuture, String context) {
try {
if (!isBooleanFutureTrue(permissionsFuture)){
Expand Down
Loading
Loading