Search in sources :

Example 31 with PermissionException

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;
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Path(java.nio.file.Path) Configuration(org.jbei.ice.storage.model.Configuration) InputStream(java.io.InputStream) IOException(java.io.IOException) Archiver(org.rauschig.jarchivelib.Archiver) URL(java.net.URL) IOException(java.io.IOException) PermissionException(org.jbei.ice.lib.access.PermissionException) AccountController(org.jbei.ice.lib.account.AccountController)

Example 32 with PermissionException

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();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) ConfigurationKey(org.jbei.ice.lib.dto.ConfigurationKey) Configuration(org.jbei.ice.storage.model.Configuration) WoRController(org.jbei.ice.lib.net.WoRController) AccountController(org.jbei.ice.lib.account.AccountController)

Example 33 with PermissionException

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);
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) RemotePartner(org.jbei.ice.storage.model.RemotePartner) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner)

Example 34 with PermissionException

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();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) RemotePartner(org.jbei.ice.storage.model.RemotePartner)

Example 35 with PermissionException

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;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) RemotePartner(org.jbei.ice.storage.model.RemotePartner)

Aggregations

PermissionException (org.jbei.ice.lib.access.PermissionException)49 Account (org.jbei.ice.storage.model.Account)10 AccountController (org.jbei.ice.lib.account.AccountController)7 RemotePartner (org.jbei.ice.storage.model.RemotePartner)6 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)5 TokenHash (org.jbei.ice.lib.account.TokenHash)4 Results (org.jbei.ice.lib.dto.common.Results)4 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)4 Configuration (org.jbei.ice.storage.model.Configuration)4 Group (org.jbei.ice.storage.model.Group)4 ArrayList (java.util.ArrayList)3 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)3 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)3 PartData (org.jbei.ice.lib.dto.entry.PartData)3 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)3 HasEntry (org.jbei.ice.lib.entry.HasEntry)3 Annotations (org.jbei.ice.lib.entry.sequence.annotation.Annotations)3 ApiKey (org.jbei.ice.storage.model.ApiKey)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2