forked from blcham/record-manager
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Design fine-grained access control within record manager #70
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b0b4648
[kbss-cvut/record-manager-ui#202] Implement roles
palagdan 0a8cfee
[kbss-cvut/record-manager-ui#202] Implement Role group assignment
palagdan 3797055
[kbss-cvut/record-manager-ui#202] Implement RoleGroup Service and Rep…
palagdan e68a489
[kbss-cvut/record-manager-ui#202] Refactor model.ttl
palagdan 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 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,109 @@ | ||
package cz.cvut.kbss.study.model; | ||
|
||
import cz.cvut.kbss.jopa.model.annotations.Individual; | ||
|
||
public enum Role { | ||
|
||
// TODO deprecated -- should be removed. | ||
@Individual(iri=Vocabulary.s_i_administrator) | ||
administrator(Vocabulary.s_i_administrator), | ||
// TODO deprecated -- should be removed. | ||
@Individual(iri = Vocabulary.s_i_user) | ||
user(Vocabulary.s_i_user), | ||
|
||
@Individual(iri = Vocabulary.s_i_impersonate_role) | ||
impersonate(Vocabulary.s_i_impersonate_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_delete_all_records_role) | ||
deleteAllRecords(Vocabulary.s_i_delete_all_records_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_view_all_records_role) | ||
viewAllRecords(Vocabulary.s_i_view_all_records_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_edit_all_records_role) | ||
editAllRecords(Vocabulary.s_i_edit_all_records_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_delete_organization_records_role) | ||
deleteOrganizationRecords(Vocabulary.s_i_delete_organization_records_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_view_organization_records_role) | ||
viewOrganizationRecords(Vocabulary.s_i_view_organization_records_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_edit_organization_records_role) | ||
editOrganizationRecords(Vocabulary.s_i_edit_organization_records_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_edit_users_role) | ||
editUsers(Vocabulary.s_i_edit_users_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_complete_records_role) | ||
completeRecords(Vocabulary.s_i_complete_records_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_reject_records_role) | ||
rejectRecords(Vocabulary.s_i_reject_records_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_publish_records_role) | ||
publishRecords(Vocabulary.s_i_publish_records_role), | ||
|
||
@Individual(iri = Vocabulary.s_i_import_codelists_role) | ||
importCodelists(Vocabulary.s_i_import_codelists_role); | ||
|
||
private final String iri; | ||
|
||
Role(String iri) { | ||
this.iri = iri; | ||
} | ||
|
||
public String getIri() { | ||
return iri; | ||
} | ||
|
||
/** | ||
* Returns {@link Role} with the specified IRI. | ||
* | ||
* @param iri role identifier | ||
* @return matching {@code Role} | ||
* @throws IllegalArgumentException When no matching role is found | ||
*/ | ||
public static Role fromIri(String iri) { | ||
for (Role r : values()) { | ||
if (r.getIri().equals(iri)) { | ||
return r; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown role identifier '" + iri + "'."); | ||
} | ||
|
||
/** | ||
* Returns {@link Role} with the specified constant name. | ||
* | ||
* @param name role name | ||
* @return matching {@code Role} | ||
* @throws IllegalArgumentException When no matching role is found | ||
*/ | ||
public static Role fromName(String name) { | ||
for (Role r : values()) { | ||
if (r.name().equalsIgnoreCase(name)) { | ||
return r; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown role '" + name + "'."); | ||
} | ||
|
||
/** | ||
* Returns a {@link Role} with the specified IRI or constant name. | ||
* <p> | ||
* This function first tries to find the enum constant by IRI. If it is not found, constant name matching is | ||
* attempted. | ||
* | ||
* @param identification Constant IRI or name to find match by | ||
* @return matching {@code Role} | ||
* @throws IllegalArgumentException When no matching role is found | ||
*/ | ||
public static Role fromIriOrName(String identification) { | ||
try { | ||
return fromIri(identification); | ||
} catch (IllegalArgumentException e) { | ||
return fromName(identification); | ||
} | ||
} | ||
} |
This file contains 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,59 @@ | ||
package cz.cvut.kbss.study.model; | ||
import cz.cvut.kbss.jopa.model.annotations.*; | ||
import cz.cvut.kbss.study.model.util.HasDerivableUri; | ||
import cz.cvut.kbss.study.model.util.HasOwlKey; | ||
import cz.cvut.kbss.study.util.Constants; | ||
|
||
import java.net.URI; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@OWLClass(iri = Vocabulary.s_c_role_group) | ||
public class RoleGroup implements HasDerivableUri { | ||
|
||
@Id | ||
private URI uri; | ||
|
||
@OWLAnnotationProperty(iri = Vocabulary.s_p_label) | ||
private String name; | ||
|
||
@OWLObjectProperty(iri = Vocabulary.s_p_has_role) | ||
private Set<Role> roles; | ||
|
||
public void addRole(Role role){ | ||
if(roles == null){ | ||
roles = new HashSet<>(); | ||
} | ||
roles.add(role); | ||
} | ||
|
||
|
||
public URI getUri() { | ||
return uri; | ||
} | ||
|
||
public void setUri(URI uri) { | ||
this.uri = uri; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Set<Role> getRoles() { | ||
return roles; | ||
} | ||
|
||
public void setRoles(Set<Role> roles) { | ||
this.roles = roles; | ||
} | ||
|
||
@Override | ||
public void generateUri() { | ||
this.uri = URI.create(Constants.BASE_URI + name); | ||
} | ||
} |
This file contains 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
31 changes: 31 additions & 0 deletions
31
src/main/java/cz/cvut/kbss/study/persistence/dao/RoleGroupDao.java
This file contains 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,31 @@ | ||
package cz.cvut.kbss.study.persistence.dao; | ||
|
||
import cz.cvut.kbss.jopa.exceptions.NoResultException; | ||
import cz.cvut.kbss.jopa.model.EntityManager; | ||
import cz.cvut.kbss.study.model.RoleGroup; | ||
import cz.cvut.kbss.study.util.Constants; | ||
import org.springframework.stereotype.Repository; | ||
import java.net.URI; | ||
import cz.cvut.kbss.study.model.Vocabulary; | ||
|
||
@Repository | ||
public class RoleGroupDao extends DerivableUriDao<RoleGroup> { | ||
|
||
protected RoleGroupDao(EntityManager em) { | ||
super(RoleGroup.class, em); | ||
} | ||
|
||
public RoleGroup findByName(String name) { | ||
if (name == null) { | ||
return null; | ||
} | ||
try { | ||
return em.createNativeQuery("SELECT ?x WHERE { ?x ?hasName ?name . }", RoleGroup.class) | ||
.setParameter("hasName", URI.create(Vocabulary.s_p_label)) | ||
.setParameter("name", name, Constants.PU_LANGUAGE).getSingleResult(); | ||
} catch (NoResultException e) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains 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 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
8 changes: 8 additions & 0 deletions
8
src/main/java/cz/cvut/kbss/study/service/RoleGroupService.java
This file contains 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,8 @@ | ||
package cz.cvut.kbss.study.service; | ||
|
||
import cz.cvut.kbss.study.model.RoleGroup; | ||
import org.springframework.stereotype.Service; | ||
|
||
public interface RoleGroupService { | ||
RoleGroup findByName(String name); | ||
} |
This file contains 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
21 changes: 21 additions & 0 deletions
21
src/main/java/cz/cvut/kbss/study/service/repository/RepositoryRoleGroup.java
This file contains 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,21 @@ | ||
package cz.cvut.kbss.study.service.repository; | ||
|
||
import cz.cvut.kbss.study.model.RoleGroup; | ||
import cz.cvut.kbss.study.persistence.dao.RoleGroupDao; | ||
import cz.cvut.kbss.study.service.RoleGroupService; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class RepositoryRoleGroup implements RoleGroupService { | ||
|
||
private final RoleGroupDao roleGroupDao; | ||
|
||
public RepositoryRoleGroup(RoleGroupDao roleGroupDao) { | ||
this.roleGroupDao = roleGroupDao; | ||
} | ||
|
||
@Override | ||
public RoleGroup findByName(String name) { | ||
return roleGroupDao.findByName(name); | ||
} | ||
} |
This file contains 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
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.
Why do we need those constants? Why Role enum is not enough for this case? (same way as we discussed in frontend)