Skip to content

Commit b9294b0

Browse files
PLUGINS-228 Adding allowance for using xsync between local projects with whitelist.
1 parent 490d5ed commit b9294b0

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/main/java/org/nrg/xsync/services/local/impl/WhitelistXsyncSiteServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.nrg.framework.orm.hibernate.AbstractHibernateEntityService;
55
import org.nrg.xapi.exceptions.DataFormatException;
66
import org.nrg.xapi.exceptions.NotFoundException;
7+
import org.nrg.xdat.XDAT;
78
import org.nrg.xsync.manifest.whitelist.SiteClassification;
89
import org.nrg.xsync.manifest.whitelist.WhitelistSite;
910
import org.nrg.xsync.manifest.whitelist.WhitelistSiteRepository;
@@ -24,6 +25,12 @@ public class WhitelistXsyncSiteServiceImpl extends AbstractHibernateEntityServic
2425
public List<WhitelistSitePojo> getAllWhitelistedSites() {
2526
List<WhitelistSite> allWhitelistedSites = getDao().findAll();
2627
List<WhitelistSitePojo> allSitePojos = new ArrayList<>();
28+
if (allWhitelistedSites.stream().noneMatch(w -> w.getSiteUrl().equals(XDAT.getSiteUrl()))) {
29+
WhitelistSite sourceSiteWhitelist = new WhitelistSite(XDAT.getSiteId(), XDAT.getSiteId(), XDAT.getSiteUrl(),
30+
SiteClassification.PUBLIC);
31+
getDao().saveOrUpdate(sourceSiteWhitelist);
32+
allWhitelistedSites.add(sourceSiteWhitelist);
33+
}
2734
for (WhitelistSite site : allWhitelistedSites) {
2835
WhitelistSitePojo pojo = new WhitelistSitePojo(site.getSiteId(), site.getSiteName(), site.getSiteUrl(),
2936
site.getClassification().toString());

src/main/java/org/nrg/xsync/xapi/XsyncSetupController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.nrg.xdat.security.services.RoleHolder;
1313
import org.nrg.xdat.security.services.UserManagementServiceI;
1414
import org.nrg.xsync.components.XsyncSitePreferencesBean;
15+
import org.nrg.xsync.pojo.WhitelistSitePojo;
1516
import org.nrg.xsync.pojo.configuration.SyncConfigurationPojo;
1617
import org.nrg.xsync.services.local.WhitelistXsyncSiteService;
1718
import org.nrg.xsync.services.local.XsyncConfigurationService;
@@ -78,11 +79,11 @@ public String setup(@PathVariable("projectId") String projectId,
7879
if (project == null) {
7980
throw new DataFormatException(" Project " + projectId + " not found. ");
8081
}
81-
if (!_xsyncConfigService.checkForWhitelistConformation(_prefs.toPojo().getXsyncWhitelistEnabled(),
82-
_whitelistXsyncSiteService.getAllWhitelistedSites(), configurationPojo.getRemote_url())) {
83-
throw new DataFormatException(" Site URL " + configurationPojo.getRemote_url() +
84-
" is not an allowed option to receive data. ");
85-
}
82+
if (_prefs.toPojo().getXsyncWhitelistEnabled() && _whitelistXsyncSiteService.getAllWhitelistedSites()
83+
.stream().noneMatch(wl -> wl.getSiteUrl().equals(configurationPojo.getRemote_url()))) {
84+
throw new DataFormatException(" Site URL " + configurationPojo.getRemote_url() +
85+
" is not an allowed option to receive data. ");
86+
}
8687

8788
XsyncUtils xsyncUtils = new XsyncUtils(_jdbcTemplate, getSessionUser());
8889
xsyncUtils.loadConfigurationToDB(configurationPojo);

0 commit comments

Comments
 (0)