Search in sources :

Example 16 with Organization

use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.

the class ApiMgtDAO method getKeyManagerConfigurations.

public List<KeyManagerConfigurationDTO> getKeyManagerConfigurations() throws APIManagementException {
    List<KeyManagerConfigurationDTO> keyManagerConfigurationDTOS = new ArrayList<>();
    final String query = "SELECT * FROM AM_KEY_MANAGER";
    try (Connection conn = APIMgtDBUtil.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(query)) {
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
                String uuid = resultSet.getString("UUID");
                keyManagerConfigurationDTO.setUuid(uuid);
                keyManagerConfigurationDTO.setName(resultSet.getString("NAME"));
                keyManagerConfigurationDTO.setDisplayName(resultSet.getString("DISPLAY_NAME"));
                keyManagerConfigurationDTO.setDescription(resultSet.getString("DESCRIPTION"));
                keyManagerConfigurationDTO.setType(resultSet.getString("TYPE"));
                keyManagerConfigurationDTO.setEnabled(resultSet.getBoolean("ENABLED"));
                keyManagerConfigurationDTO.setOrganization(resultSet.getString("ORGANIZATION"));
                keyManagerConfigurationDTO.setTokenType(resultSet.getString("TOKEN_TYPE"));
                keyManagerConfigurationDTO.setExternalReferenceId(resultSet.getString("EXTERNAL_REFERENCE_ID"));
                try (InputStream configuration = resultSet.getBinaryStream("CONFIGURATION")) {
                    String configurationContent = IOUtils.toString(configuration);
                    Map map = new Gson().fromJson(configurationContent, Map.class);
                    keyManagerConfigurationDTO.setAdditionalProperties(map);
                } catch (IOException e) {
                    log.error("Error while converting configurations in " + uuid, e);
                }
                keyManagerConfigurationDTOS.add(keyManagerConfigurationDTO);
            }
        }
    } catch (SQLException e) {
        throw new APIManagementException("Error while retrieving all key manager configurations", e);
    }
    return keyManagerConfigurationDTOS;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) Gson(com.google.gson.Gson) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ResultSet(java.sql.ResultSet) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 17 with Organization

use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.

the class ApiMgtDAO method isIDPExistInOrg.

public boolean isIDPExistInOrg(String organization, String resourceId) throws APIManagementException {
    final String query = "SELECT 1 FROM AM_KEY_MANAGER WHERE EXTERNAL_REFERENCE_ID  = ? AND ORGANIZATION = ?";
    try (Connection conn = APIMgtDBUtil.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(query)) {
        preparedStatement.setString(1, resourceId);
        preparedStatement.setString(2, organization);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            if (resultSet.next()) {
                return true;
            }
        }
    } catch (SQLException e) {
        throw new APIManagementException("Error while checking key manager for " + resourceId + " in organization " + organization, e);
    }
    return false;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 18 with Organization

use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.

the class ApiMgtDAO method getCommonOperationPolicyByPolicyID.

private OperationPolicyData getCommonOperationPolicyByPolicyID(Connection connection, String policyId, String organization, boolean isWithPolicyDefinition) throws SQLException {
    String dbQuery = SQLConstants.OperationPolicyConstants.GET_COMMON_OPERATION_POLICY_WITH_OUT_DEFINITION_FROM_POLICY_ID;
    PreparedStatement statement = connection.prepareStatement(dbQuery);
    statement.setString(1, policyId);
    statement.setString(2, organization);
    ResultSet rs = statement.executeQuery();
    OperationPolicyData policyData = null;
    if (rs.next()) {
        policyData = new OperationPolicyData();
        policyData.setPolicyId(policyId);
        policyData.setOrganization(organization);
        policyData.setMd5Hash(rs.getString("POLICY_MD5"));
        policyData.setSpecification(populatePolicySpecificationFromRS(rs));
    }
    rs.close();
    statement.close();
    if (isWithPolicyDefinition && policyData != null) {
        populatePolicyDefinitions(connection, policyId, policyData);
    }
    return policyData;
}
Also used : OperationPolicyData(org.wso2.carbon.apimgt.api.model.OperationPolicyData) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 19 with Organization

use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.

the class ApiMgtDAO method getLightweightApplicationByConsumerKey.

public ApplicationInfo getLightweightApplicationByConsumerKey(String consumerKey) throws APIManagementException {
    Connection connection = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    try {
        connection = APIMgtDBUtil.getConnection();
        String query = SQLConstants.GET_APPLICATION_INFO_BY_CK;
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, consumerKey);
        rs = prepStmt.executeQuery();
        if (rs.next()) {
            ApplicationInfo applicationInfo = new ApplicationInfo();
            applicationInfo.setName(rs.getString("NAME"));
            applicationInfo.setUuid(rs.getString("UUID"));
            applicationInfo.setOrganizationId(rs.getString("ORGANIZATION"));
            applicationInfo.setOwner(rs.getString("OWNER"));
            return applicationInfo;
        }
    } catch (SQLException e) {
        handleException("Error while obtaining organisation of the application for client id " + consumerKey, e);
    } finally {
        APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) ApplicationInfo(org.wso2.carbon.apimgt.api.model.ApplicationInfo) PreparedStatement(java.sql.PreparedStatement)

Example 20 with Organization

use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.

the class ApiMgtDAO method getConsumerKeysForApplication.

/**
 * Retrieves the consumer keys and keymanager in a given application
 *
 * @param appId application id
 * @return Map<ConsumerKey, Pair<keyManagerName, keyManagerTenantDomain>
 * @throws APIManagementException
 */
public Map<String, Pair<String, String>> getConsumerKeysForApplication(int appId) throws APIManagementException {
    Map<String, Pair<String, String>> consumerKeysOfApplication = new HashMap<>();
    try (Connection connection = APIMgtDBUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(SQLConstants.GET_CONSUMER_KEY_OF_APPLICATION_SQL)) {
        preparedStatement.setInt(1, appId);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                String consumerKey = resultSet.getString("CONSUMER_KEY");
                String keyManagerName = resultSet.getString("NAME");
                String keyManagerOrganization = resultSet.getString("ORGANIZATION");
                consumerKeysOfApplication.put(consumerKey, Pair.of(keyManagerName, keyManagerOrganization));
            }
        }
    } catch (SQLException e) {
        String msg = "Error occurred while getting consumer keys for application " + appId;
        log.error(msg, e);
        throw new APIManagementException(msg, e);
    }
    return consumerKeysOfApplication;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)304 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)106 API (org.wso2.carbon.apimgt.api.model.API)100 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)89 ArrayList (java.util.ArrayList)79 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)72 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)70 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)65 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)64 IOException (java.io.IOException)61 Registry (org.wso2.carbon.registry.core.Registry)58 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)57 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)56 HashMap (java.util.HashMap)54 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)53 Resource (org.wso2.carbon.registry.core.Resource)51 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)49 JSONObject (org.json.simple.JSONObject)45 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)44 URISyntaxException (java.net.URISyntaxException)42