/** * Updates authzObj -> [Paths] mapping to replace an existing path with a new one * given an authzObj. * * @param pm PersistenceManager * @param authzObj an authzObj * @param oldPath the existing path maps to the given authzObj * @param newPath a non-empty path to replace the existing one * @throws SentryNoSuchObjectException if no such path found * in the authzObj -> [Paths] mapping. */ private void updateAuthzPathsMappingCore(PersistenceManager pm, String authzObj, String oldPath, String newPath) { long currentSnapshotID = getCurrentAuthzPathsSnapshotID(pm); if (currentSnapshotID <= EMPTY_PATHS_SNAPSHOT_ID) { LOGGER.error("No paths snapshot ID is found. Cannot update authzoObj: {}", authzObj); } MAuthzPathsMapping mAuthzPathsMapping = getMAuthzPathsMappingCore(pm, currentSnapshotID, authzObj); if (mAuthzPathsMapping == null) { mAuthzPathsMapping = new MAuthzPathsMapping(currentSnapshotID, getNextAuthzObjectID(pm), authzObj, Collections.singleton(newPath)); } else { mAuthzPathsMapping.deletePersistent(pm, Collections.singleton(oldPath)); mAuthzPathsMapping.addPathToPersist(Collections.singleton(newPath)); } mAuthzPathsMapping.makePersistent(pm); }
MAuthzPathsMapping mapping = new MAuthzPathsMapping(nextSnapshotID, nextObjectId++, authzPath.getKey(), authzPath.getValue()); mapping.makePersistent(pm);
/** * Adds the authzObj and with a set of paths into the authzObj -> [Paths] mapping. * If the given authzObj already exists in the mapping, only need to add the new paths * into its mapping. * * @param pm PersistenceManager * @param authzObj an authzObj * @param paths a set of paths need to be added into the authzObj -> [Paths] mapping */ private void addAuthzPathsMappingCore(PersistenceManager pm, String authzObj, Collection<String> paths) { long currentSnapshotID = getCurrentAuthzPathsSnapshotID(pm); if (currentSnapshotID <= EMPTY_PATHS_SNAPSHOT_ID) { LOGGER.warn("AuthzObj: {} cannot be persisted if paths snapshot ID does not exist yet.", authzObj); } MAuthzPathsMapping mAuthzPathsMapping = getMAuthzPathsMappingCore(pm, currentSnapshotID, authzObj); if (mAuthzPathsMapping == null) { mAuthzPathsMapping = new MAuthzPathsMapping(currentSnapshotID, getNextAuthzObjectID(pm), authzObj, paths); } else { mAuthzPathsMapping.addPathToPersist(paths); } mAuthzPathsMapping.makePersistent(pm); }