@Test public void testApply() { try (ODatabaseDocumentTx securityDb = securityDatabase.getInstance().connect()) { createPrivilege("a_test_priv", "read,edit,delete,add"); createPrivilege("b_test_priv", "mark,read,edit,delete"); createPrivilege("c_test_priv", "create,read,edit,delete,add"); createPrivilege("d_test_priv", "mark,read,edit,delete,create"); } underTest.apply(); try (ODatabaseDocumentTx securityDb = securityDatabase.getInstance().connect()) { List<ODocument> result = securityDb.command(new OCommandSQL("select from privilege")).execute(); assertThat(result.size(), is(4)); assertThat(result.get(0).field(P_NAME), is("a_test_priv")); assertThat(result.get(0).field(P_PROPERTIES), hasEntry(is("actions"), is("read,edit,delete,create"))); assertThat(result.get(1).field(P_NAME), is("b_test_priv")); assertThat(result.get(1).field(P_PROPERTIES), hasEntry(is("actions"), is("read,edit,delete,create"))); assertThat(result.get(2).field(P_NAME), is("c_test_priv")); assertThat(result.get(2).field(P_PROPERTIES), hasEntry(is("actions"), is("create,read,edit,delete"))); assertThat(result.get(3).field(P_NAME), is("d_test_priv")); assertThat(result.get(3).field(P_PROPERTIES), hasEntry(is("actions"), is("read,edit,delete,create"))); } }
@Override public void apply() { withDatabaseAndClass(securityDatabaseInstance, DB_CLASS, (db, type) -> { List<ODocument> results = db.command(new OCommandSQL(QUERY)).execute(); results.forEach(result -> { Map<String, String> properties = result.field(P_PROPERTIES, OType.EMBEDDEDMAP); if (properties != null) { String actionString = properties.get(P_ACTIONS); if (actionString != null) { List<String> actions = new ArrayList(Arrays.asList(actionString.split(","))); if (actions.contains("add") || actions.contains("mark")) { actions.remove("add"); actions.remove("mark"); if (!actions.contains("create")) { actions.add("create"); } properties.put(P_ACTIONS, String.join(",", actions)); result.field(P_PROPERTIES, properties); log.info("Updated application privilege {} to align with CRUD actions", (String) result.field(P_NAME)); result.save(); } } } }); }); }
SecurityDatabaseUpgrade_1_3 extends DatabaseUpgradeSupport { @Override public void apply() { withDatabaseAndClass(securityDatabaseInstance, DB_CLASS, (db, type) -> { List<ODocument> results = db.command(new OCommandSQL(QUERY)).execute(); results.forEach(result -> { Map<String, String> properties = result.field(P_PROPERTIES, OType.EMBEDDEDMAP); if (properties != null) { String actionString = properties.get(P_ACTIONS); if (actionString != null) { List<String> actions = new ArrayList(Arrays.asList(actionString.split(","))); if (actions.contains("add") || actions.contains("mark")) { actions.remove("add"); actions.remove("mark"); if (!actions.contains("create")) { actions.add("create"); } properties.put(P_ACTIONS, String.join(",", actions)); result.field(P_PROPERTIES, properties); log.info("Updated application privilege {} to align with CRUD actions", (String) result.field(P_NAME)); result.save(); } } } }); }); } }
SecurityDatabaseUpgrade_1_3 extends DatabaseUpgradeSupport { @Override public void apply() { withDatabaseAndClass(securityDatabaseInstance, DB_CLASS, (db, type) -> { List<ODocument> results = db.command(new OCommandSQL(QUERY)).execute(); results.forEach(result -> { Map<String, String> properties = result.field(P_PROPERTIES, OType.EMBEDDEDMAP); if (properties != null) { String actionString = properties.get(P_ACTIONS); if (actionString != null) { List<String> actions = new ArrayList(Arrays.asList(actionString.split(","))); if (actions.contains("add") || actions.contains("mark")) { actions.remove("add"); actions.remove("mark"); if (!actions.contains("create")) { actions.add("create"); } properties.put(P_ACTIONS, String.join(",", actions)); result.field(P_PROPERTIES, properties); log.info("Updated application privilege {} to align with CRUD actions", (String) result.field(P_NAME)); result.save(); } } } }); }); } @Inject  SecurityDatabaseUpgrade_1_3(@Named(
      DatabaseInstanceNames.SECURITY) final Provider<DatabaseInstance> securityDatabaseInstance); }
SecurityDatabaseUpgrade_1_3 extends DatabaseUpgradeSupport { @Override public void apply() { withDatabaseAndClass(securityDatabaseInstance, DB_CLASS, (db, type) -> { List<ODocument> results = db.command(new OCommandSQL(QUERY)).execute(); results.forEach(result -> { Map<String, String> properties = result.field(P_PROPERTIES, OType.EMBEDDEDMAP); if (properties != null) { String actionString = properties.get(P_ACTIONS); if (actionString != null) { List<String> actions = new ArrayList(Arrays.asList(actionString.split(","))); if (actions.contains("add") || actions.contains("mark")) { actions.remove("add"); actions.remove("mark"); if (!actions.contains("create")) { actions.add("create"); } properties.put(P_ACTIONS, String.join(",", actions)); result.field(P_PROPERTIES, properties); log.info("Updated application privilege {} to align with CRUD actions", (String) result.field(P_NAME)); result.save(); } } } }); }); } @Inject  SecurityDatabaseUpgrade_1_3(@Named(
      DatabaseInstanceNames.SECURITY) final Provider<DatabaseInstance> securityDatabaseInstance); @Override void apply(); }
SecurityDatabaseUpgrade_1_3 extends DatabaseUpgradeSupport { @Override public void apply() { withDatabaseAndClass(securityDatabaseInstance, DB_CLASS, (db, type) -> { List<ODocument> results = db.command(new OCommandSQL(QUERY)).execute(); results.forEach(result -> { Map<String, String> properties = result.field(P_PROPERTIES, OType.EMBEDDEDMAP); if (properties != null) { String actionString = properties.get(P_ACTIONS); if (actionString != null) { List<String> actions = new ArrayList(Arrays.asList(actionString.split(","))); if (actions.contains("add") || actions.contains("mark")) { actions.remove("add"); actions.remove("mark"); if (!actions.contains("create")) { actions.add("create"); } properties.put(P_ACTIONS, String.join(",", actions)); result.field(P_PROPERTIES, properties); log.info("Updated application privilege {} to align with CRUD actions", (String) result.field(P_NAME)); result.save(); } } } }); }); } @Inject  SecurityDatabaseUpgrade_1_3(@Named(
      DatabaseInstanceNames.SECURITY) final Provider<DatabaseInstance> securityDatabaseInstance); @Override void apply();  }