Skip to content

Commit

Permalink
Fixed authorization migration
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinovg committed Dec 12, 2024
1 parent ee1e06a commit c8039f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ private static Long[] updatePolicyDatasets(AccessObjectType aot,
EntityPolicyController.getDataValueStatements(entityUri, aot, ao, rolesToAdd, additions);
Set<String> rolesToRemove = new HashSet<>(ALL_ROLES);
rolesToRemove.removeAll(rolesToAdd);
// Don't remove public publish and update data sets, as there are no public policies for that
// operation
// groups
if (OperationGroup.PUBLISH_GROUP.equals(og) || OperationGroup.UPDATE_GROUP.equals(og)) {
rolesToRemove.remove(ROLE_PUBLIC_URI);
}
if (!rolesToRemove.isEmpty()) {
log.info(String.format("Revoked access to %s %s %s for roles %s", ao, aot, entityUri,
rolesToString(rolesToRemove)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

public class AuthMigrator implements ServletContextListener {

private static final long CURRENT_VERSION = 2;
private static final Log log = LogFactory.getLog(AuthMigrator.class);
protected static final Set<String> ALL_ROLES = new HashSet<String>(
Arrays.asList(ROLE_ADMIN_URI, ROLE_CURATOR_URI, ROLE_EDITOR_URI, ROLE_SELF_EDITOR_URI, ROLE_PUBLIC_URI));
Expand Down Expand Up @@ -72,6 +73,10 @@ public void contextInitialized(ServletContextEvent sce) {
if (!isMigrationRequired()) {
return;
}
runCompleteMigration(sce, begin);
}

private void runCompleteMigration(ServletContextEvent sce, long begin) {
ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
log.info("Started authorization configuration update");
Expand All @@ -97,7 +102,7 @@ protected void convertAuthorizationConfiguration() {
}
migrateSimplePermissions();
removeVersion(getVersion());
setVersion(1L);
setVersion(CURRENT_VERSION);
}

private void migrateSimplePermissions() {
Expand All @@ -112,15 +117,14 @@ private void migrateAnnotationConfiguation() {
}

private boolean isMigrationRequired() {
if (getVersion() == 0L) {
if (getVersion() < 1) {
return true;
}
return false;
}

protected long getVersion() {
long version = 0L;

try {
ResultSet rs = RDFServiceUtils.sparqlSelectQuery(VERSION_QUERY, configurationRdfService);
while (rs.hasNext()) {
Expand Down

0 comments on commit c8039f4

Please sign in to comment.