Search in sources :

Example 6 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class AiravataDataMigrator method main.

public static void main(String[] args) throws SQLException, ClassNotFoundException, TException, ApplicationSettingsException {
    Connection expCatConnection = ConnectionFactory.getInstance().getExpCatConnection();
    SharingRegistryServerHandler sharingRegistryServerHandler = new SharingRegistryServerHandler();
    String query = "SELECT * FROM GATEWAY";
    Statement statement = expCatConnection.createStatement();
    ResultSet rs = statement.executeQuery(query);
    while (rs.next()) {
        try {
            // Creating domain entries
            Domain domain = new Domain();
            domain.setDomainId(rs.getString("GATEWAY_ID"));
            domain.setName(rs.getString("GATEWAY_ID"));
            domain.setDescription("Domain entry for " + domain.name);
            if (!sharingRegistryServerHandler.isDomainExists(domain.domainId))
                sharingRegistryServerHandler.createDomain(domain);
            // Creating Entity Types for each domain
            EntityType entityType = new EntityType();
            entityType.setEntityTypeId(domain.domainId + ":PROJECT");
            entityType.setDomainId(domain.domainId);
            entityType.setName("PROJECT");
            entityType.setDescription("Project entity type");
            if (!sharingRegistryServerHandler.isEntityTypeExists(entityType.domainId, entityType.entityTypeId))
                sharingRegistryServerHandler.createEntityType(entityType);
            entityType = new EntityType();
            entityType.setEntityTypeId(domain.domainId + ":EXPERIMENT");
            entityType.setDomainId(domain.domainId);
            entityType.setName("EXPERIMENT");
            entityType.setDescription("Experiment entity type");
            if (!sharingRegistryServerHandler.isEntityTypeExists(entityType.domainId, entityType.entityTypeId))
                sharingRegistryServerHandler.createEntityType(entityType);
            entityType = new EntityType();
            entityType.setEntityTypeId(domain.domainId + ":FILE");
            entityType.setDomainId(domain.domainId);
            entityType.setName("FILE");
            entityType.setDescription("File entity type");
            if (!sharingRegistryServerHandler.isEntityTypeExists(entityType.domainId, entityType.entityTypeId))
                sharingRegistryServerHandler.createEntityType(entityType);
            // Creating Permission Types for each domain
            PermissionType permissionType = new PermissionType();
            permissionType.setPermissionTypeId(domain.domainId + ":READ");
            permissionType.setDomainId(domain.domainId);
            permissionType.setName("READ");
            permissionType.setDescription("Read permission type");
            if (!sharingRegistryServerHandler.isPermissionExists(permissionType.domainId, permissionType.permissionTypeId))
                sharingRegistryServerHandler.createPermissionType(permissionType);
            permissionType = new PermissionType();
            permissionType.setPermissionTypeId(domain.domainId + ":WRITE");
            permissionType.setDomainId(domain.domainId);
            permissionType.setName("WRITE");
            permissionType.setDescription("Write permission type");
            if (!sharingRegistryServerHandler.isPermissionExists(permissionType.domainId, permissionType.permissionTypeId))
                sharingRegistryServerHandler.createPermissionType(permissionType);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    // Creating user entries
    query = "SELECT * FROM USERS";
    statement = expCatConnection.createStatement();
    rs = statement.executeQuery(query);
    while (rs.next()) {
        try {
            User user = new User();
            user.setUserId(rs.getString("AIRAVATA_INTERNAL_USER_ID"));
            user.setDomainId(rs.getString("GATEWAY_ID"));
            user.setUserName(rs.getString("USER_NAME"));
            if (!sharingRegistryServerHandler.isUserExists(user.domainId, user.userId))
                sharingRegistryServerHandler.createUser(user);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    // Creating project entries
    query = "SELECT * FROM PROJECT";
    statement = expCatConnection.createStatement();
    rs = statement.executeQuery(query);
    while (rs.next()) {
        try {
            Entity entity = new Entity();
            entity.setEntityId(rs.getString("PROJECT_ID"));
            entity.setDomainId(rs.getString("GATEWAY_ID"));
            entity.setEntityTypeId(rs.getString("GATEWAY_ID") + ":PROJECT");
            entity.setOwnerId(rs.getString("USER_NAME") + "@" + rs.getString("GATEWAY_ID"));
            entity.setName(rs.getString("PROJECT_NAME"));
            entity.setDescription(rs.getString("DESCRIPTION"));
            if (entity.getDescription() == null)
                entity.setFullText(entity.getName());
            else
                entity.setFullText(entity.getName() + " " + entity.getDescription());
            Map<String, String> metadata = new HashMap<>();
            metadata.put("CREATION_TIME", rs.getDate("CREATION_TIME").toString());
            if (!sharingRegistryServerHandler.isEntityExists(entity.domainId, entity.entityId))
                sharingRegistryServerHandler.createEntity(entity);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    // Creating experiment entries
    query = "SELECT * FROM EXPERIMENT";
    statement = expCatConnection.createStatement();
    rs = statement.executeQuery(query);
    while (rs.next()) {
        try {
            Entity entity = new Entity();
            entity.setEntityId(rs.getString("EXPERIMENT_ID"));
            entity.setDomainId(rs.getString("GATEWAY_ID"));
            entity.setEntityTypeId(rs.getString("GATEWAY_ID") + ":EXPERIMENT");
            entity.setOwnerId(rs.getString("USER_NAME") + "@" + rs.getString("GATEWAY_ID"));
            entity.setParentEntityId(rs.getString("PROJECT_ID"));
            entity.setName(rs.getString("EXPERIMENT_NAME"));
            entity.setDescription(rs.getString("DESCRIPTION"));
            if (entity.getDescription() == null)
                entity.setFullText(entity.getName());
            else
                entity.setFullText(entity.getName() + " " + entity.getDescription());
            Map<String, String> metadata = new HashMap<>();
            metadata.put("CREATION_TIME", rs.getDate("CREATION_TIME").toString());
            metadata.put("EXPERIMENT_TYPE", rs.getString("EXPERIMENT_TYPE"));
            metadata.put("EXECUTION_ID", rs.getString("EXECUTION_ID"));
            metadata.put("GATEWAY_EXECUTION_ID", rs.getString("GATEWAY_EXECUTION_ID"));
            metadata.put("ENABLE_EMAIL_NOTIFICATION", rs.getString("ENABLE_EMAIL_NOTIFICATION"));
            metadata.put("EMAIL_ADDRESSES", rs.getString("EMAIL_ADDRESSES"));
            metadata.put("GATEWAY_INSTANCE_ID", rs.getString("GATEWAY_INSTANCE_ID"));
            metadata.put("ARCHIVE", rs.getString("ARCHIVE"));
            if (!sharingRegistryServerHandler.isEntityExists(entity.domainId, entity.entityId))
                sharingRegistryServerHandler.createEntity(entity);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    expCatConnection.close();
}
Also used : HashMap(java.util.HashMap) Statement(java.sql.Statement) SharingRegistryServerHandler(org.apache.airavata.sharing.registry.server.SharingRegistryServerHandler) Connection(java.sql.Connection) SQLException(java.sql.SQLException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ResultSet(java.sql.ResultSet)

Example 7 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class WorkflowUtils method getExecutionType.

public static ExecutionType getExecutionType(Experiment experiment) {
    try {
        ApplicationInterface applicationInterface = RegistryFactory.getAppCatalog().getApplicationInterface();
        List<String> allApplicationInterfaceIds = applicationInterface.getAllApplicationInterfaceIds();
        String applicationId = experiment.getApplicationId();
        if (allApplicationInterfaceIds.contains(applicationId)) {
            return ExecutionType.SINGLE_APP;
        } else {
            List<String> allWorkflows = WorkflowCatalogFactory.getWorkflowCatalog().getAllWorkflows(ServerSettings.getDefaultUserGateway());
            if (allWorkflows.contains(applicationId)) {
                return ExecutionType.WORKFLOW;
            }
        }
    } catch (AppCatalogException e) {
        logger.error(e.getMessage(), e);
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
    }
    return ExecutionType.UNKNOWN;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationInterface(org.apache.airavata.registry.cpi.ApplicationInterface)

Example 8 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class UNICORESecurityContext method getDefaultConfiguration.

public DefaultClientConfiguration getDefaultConfiguration(Boolean enableMessageLogging, UserConfigurationData userData) throws GFacException, ApplicationSettingsException {
    X509Credential cred = null;
    try {
        boolean genCert = userData.isGenerateCert();
        if (genCert) {
            String userDN = userData.getUserDN();
            if (userDN == null && "".equals(userDN)) {
                log.warn("Cannot generate cert, falling back to container configured MyProxy credentials");
                return getDefaultConfiguration(enableMessageLogging);
            } else {
                log.info("Generating X.509 certificate for: " + userDN);
                try {
                    String caCertPath = ServerSettings.getSetting(BESConstants.PROP_CA_CERT_PATH, "");
                    String caKeyPath = ServerSettings.getSetting(BESConstants.PROP_CA_KEY_PATH, "");
                    String caKeyPass = ServerSettings.getSetting(BESConstants.PROP_CA_KEY_PASS, "");
                    if (caCertPath.equals("") || caKeyPath.equals("")) {
                        throw new Exception("CA certificate or key file path missing in the properties file. " + "Please make sure " + BESConstants.PROP_CA_CERT_PATH + " or " + BESConstants.PROP_CA_KEY_PATH + " are not empty.");
                    }
                    if ("".equals(caKeyPass)) {
                        log.warn("Caution: CA key has no password. For security reasons it is highly recommended to set a CA key password");
                    }
                    cred = generateShortLivedCredential(userDN, caCertPath, caKeyPath, caKeyPass);
                } catch (Exception e) {
                    throw new GFacProviderException("Error occured while generating a short lived credential for user:" + userDN, e);
                }
            }
        } else {
            return getDefaultConfiguration(enableMessageLogging);
        }
        secProperties = new DefaultClientConfiguration(dcValidator, cred);
        setExtraSettings();
    } catch (Exception e) {
        throw new GFacException(e.getMessage(), e);
    }
    secProperties.getETDSettings().setExtendTrustDelegation(true);
    if (enableMessageLogging)
        secProperties.setMessageLogging(true);
    // secProperties.setDoSignMessage(true);
    secProperties.getETDSettings().setIssuerCertificateChain(secProperties.getCredential().getCertificateChain());
    return secProperties;
}
Also used : X509Credential(eu.emi.security.authn.x509.X509Credential) GFacException(org.apache.airavata.gfac.core.GFacException) DefaultClientConfiguration(eu.unicore.util.httpclient.DefaultClientConfiguration) GFacProviderException(org.apache.airavata.gfac.core.provider.GFacProviderException) GFacException(org.apache.airavata.gfac.core.GFacException) GFacProviderException(org.apache.airavata.gfac.core.provider.GFacProviderException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 9 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class UNICORESecurityContext method getDefaultConfiguration.

/**
 * Get client configuration from MyProxy credentials.
 *
 * @return an instance of the default client configuration
 * @throws GFacException
 * @throws ApplicationSettingsException
 * @throws GFacException, ApplicationSettingsException
 */
public DefaultClientConfiguration getDefaultConfiguration(Boolean enableMessageLogging) throws GFacException, ApplicationSettingsException {
    try {
        X509Credential cred = getX509Credentials();
        secProperties = new DefaultClientConfiguration(dcValidator, cred);
        setExtraSettings();
    } catch (Exception e) {
        throw new GFacException(e.getMessage(), e);
    }
    secProperties.getETDSettings().setExtendTrustDelegation(true);
    if (enableMessageLogging)
        secProperties.setMessageLogging(true);
    // secProperties.setMessageLogging(true);
    // secProperties.setDoSignMessage(true);
    secProperties.getETDSettings().setIssuerCertificateChain(secProperties.getCredential().getCertificateChain());
    return secProperties;
}
Also used : X509Credential(eu.emi.security.authn.x509.X509Credential) GFacException(org.apache.airavata.gfac.core.GFacException) DefaultClientConfiguration(eu.unicore.util.httpclient.DefaultClientConfiguration) GFacException(org.apache.airavata.gfac.core.GFacException) GFacProviderException(org.apache.airavata.gfac.core.provider.GFacProviderException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 10 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class X509SecurityContext method getDefaultCredentials.

/**
 * Gets the default proxy certificate.
 * @return Default my proxy credentials.
 * @throws GFacException If an error occurred while retrieving credentials.
 * @throws org.apache.airavata.common.exception.ApplicationSettingsException
 */
public X509Credential getDefaultCredentials() throws GFacException, ApplicationSettingsException {
    MyProxyLogon logon = new MyProxyLogon();
    logon.setValidator(dcValidator);
    logon.setHost(getRequestData().getMyProxyServerUrl());
    logon.setPort(getRequestData().getMyProxyPort());
    logon.setUsername(getRequestData().getMyProxyUserName());
    logon.setPassphrase(getRequestData().getMyProxyPassword().toCharArray());
    logon.setLifetime(getRequestData().getMyProxyLifeTime());
    try {
        logon.connect();
        logon.logon();
        logon.getCredentials();
        logon.disconnect();
        PrivateKey pk = logon.getPrivateKey();
        return new KeyAndCertCredential(pk, new X509Certificate[] { logon.getCertificate() });
    } catch (Exception e) {
        throw new GFacException("An error occurred while retrieving default security credentials.", e);
    }
}
Also used : PrivateKey(java.security.PrivateKey) GFacException(org.apache.airavata.gfac.core.GFacException) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) MyProxyLogon(org.apache.airavata.gfac.bes.utils.MyProxyLogon) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Aggregations

ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)263 EntityManager (javax.persistence.EntityManager)193 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)172 Query (javax.persistence.Query)147 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)129 HashMap (java.util.HashMap)71 Map (java.util.Map)69 ArrayList (java.util.ArrayList)47 WorkflowCatalogException (org.apache.airavata.registry.cpi.WorkflowCatalogException)26 IOException (java.io.IOException)23 IamAdminServicesException (org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException)20 TException (org.apache.thrift.TException)19 WorkflowCatalogQueryGenerator (org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator)18 GFacException (org.apache.airavata.gfac.core.GFacException)11 PasswordCredential (org.apache.airavata.model.credential.store.PasswordCredential)11 Keycloak (org.keycloak.admin.client.Keycloak)11 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)7 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)7 File (java.io.File)6 Connection (java.sql.Connection)6