use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class ConfigurationSettings method autoUpdateSetting.
// update the setting automatically. Currently works only for blast installations
public Setting autoUpdateSetting(String userId, Setting setting) {
AccountController accountController = new AccountController();
if (!accountController.isAdministrator(userId))
throw new PermissionException("Cannot auto update system setting without admin privileges");
Configuration configuration = dao.get(setting.getKey());
if (configuration == null) {
Logger.warn("Could not retrieve setting " + setting.getKey() + ". Creating...");
if (setting.getValue() == null)
setting.setValue("");
configuration = dao.create(new Configuration(setting.getKey(), setting.getValue()));
}
String osName = System.getProperty("os.name").replaceAll("\\s+", "").toLowerCase();
String blast = "ncbi-blast-2.6.0+-x64-" + osName + ".tar.gz";
Path path = Paths.get(dao.get(ConfigurationKey.TEMPORARY_DIRECTORY).getValue(), blast);
Path dest = Paths.get(dao.get(ConfigurationKey.DATA_DIRECTORY).getValue());
if (!Files.exists(dest)) {
Logger.error("Cannot access access dir : " + dest.toString());
return null;
}
try (InputStream is = (new URL(BLAST_FTP_DIR + blast)).openStream()) {
Files.copy(is, path.toAbsolutePath(), StandardCopyOption.REPLACE_EXISTING);
Archiver archiver = ArchiverFactory.createArchiver("tar", "gz");
archiver.extract(path.toFile(), dest.toFile());
Path valuePath = Paths.get(dest.toString(), "ncbi-blast-2.6.0+", "bin");
configuration.setValue(valuePath.toString());
Files.list(valuePath).forEach(dirPath -> {
try {
Files.setPosixFilePermissions(dirPath, PosixFilePermissions.fromString("rwxrwxrwx"));
} catch (IOException e) {
Logger.error(e);
}
});
return dao.update(configuration).toDataTransferObject();
} catch (Exception e) {
Logger.error(e);
return null;
}
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class ConfigurationSettings method updateSetting.
public Setting updateSetting(String userId, Setting setting, String url) {
AccountController accountController = new AccountController();
if (!accountController.isAdministrator(userId))
throw new PermissionException("Cannot update system setting without admin privileges");
ConfigurationKey key = ConfigurationKey.valueOf(setting.getKey());
Configuration configuration = setPropertyValue(key, setting.getValue());
// check if the setting being updated is related to the web of registries
if (key == ConfigurationKey.JOIN_WEB_OF_REGISTRIES) {
WoRController woRController = new WoRController();
boolean enable = "yes".equalsIgnoreCase(setting.getValue()) || "true".equalsIgnoreCase(setting.getValue());
woRController.setEnable(userId, enable, url);
}
return configuration.toDataTransferObject();
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class WebPartners method addNewPartner.
/**
* Adds the registry instance specified by the url to the list of existing partners (if not already in there)
* and sends a request to the remote instance that includes a security token that the remote instance
* can use to communicate with this instance.
* <p>
* Information about the remote instance is still saved even when it cannot be communicated with. This
* allows a future communication attempt.
*
* @param userId id of user performing action (must have admin privileges)
* @param partner registry partner object that contains unique uniform resource identifier & name for the registry
* @return add partner ofr
*/
public RegistryPartner addNewPartner(String userId, RegistryPartner partner, String thisUrl) {
if (!isInWebOfRegistries())
return null;
// check for admin privileges before granting request
if (!accountController.isAdministrator(userId))
throw new PermissionException("Non admin attempting to add remote partner " + partner.getUrl());
if (StringUtils.isEmpty(partner.getUrl()))
throw new IllegalArgumentException("Cannot add partner without valid url");
// check if there is a partner with that url
RemotePartner remotePartner = dao.getByUrl(partner.getUrl());
if (remotePartner != null) {
// if so just update the api key
return updateAPIKey(userId, remotePartner.getId());
}
Logger.info(userId + ": adding WoR partner [" + partner.getUrl() + "]");
// create information about this instance to send to potential partner
// including a random token for use when contacting this instance
RegistryPartner thisPartner = getThisInstanceWithNewApiKey();
// validate this url
if (!isValidUrl(thisPartner.getUrl())) {
if (isValidUrl(thisUrl))
thisPartner.setUrl(thisUrl);
else {
Logger.error("Could not obtain a valid url for this instance.");
thisPartner = null;
}
}
if (thisPartner == null) {
// will not contact
Logger.error("Cannot exchange api token with remote host due to invalid local url");
partner.setStatus(RemotePartnerStatus.NOT_CONTACTED);
} else {
RegistryPartner newPartner = remoteContact.contactPotentialPartner(thisPartner, partner.getUrl());
if (newPartner == null) {
// contact failed
Logger.error("Remote contact of partner " + partner.getUrl() + " failed");
partner.setStatus(RemotePartnerStatus.CONTACT_FAILED);
} else {
// contact succeeded with return of api key
partner.setStatus(RemotePartnerStatus.APPROVED);
partner.setApiKey(newPartner.getApiKey());
}
}
// if status is not approved, then the token is irrelevant since it is not stored and was not
// successfully transmitted
String apiKey = thisPartner != null ? thisPartner.getApiKey() : null;
return createRemotePartnerObject(partner, apiKey);
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class WebPartners method update.
// only updates the status
public RegistryPartner update(String userId, long id, RegistryPartner partner) {
if (!isInWebOfRegistries())
return null;
if (!accountController.isAdministrator(userId))
throw new PermissionException(userId + " is not an admin");
RemotePartner existing = dao.get(id);
if (existing == null)
throw new IllegalArgumentException("Cannot retrieve partner with id " + id);
Logger.info(userId + ": updating partner (" + existing.getUrl() + ") to " + partner.toString());
existing.setPartnerStatus(partner.getStatus());
return dao.update(existing).toDataTransferObject();
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class WebPartners method remove.
public boolean remove(String userId, long id) {
if (!accountController.isAdministrator(userId))
throw new PermissionException(userId + " is not an admin");
RemotePartner partner = dao.get(id);
if (partner == null)
return false;
dao.delete(partner);
// todo : contact deleted partner since they cannot contact anymore?
return true;
}
Aggregations