Search in sources :

Example 11 with Provider

use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.

the class APIManagerFactory method newProvider.

private APIPublisher newProvider(String username) throws APIManagementException {
    try {
        APIPublisherImpl apiPublisher = new APIPublisherImpl(username, getIdentityProvider(), getKeyManager(), DAOFactory.getApiDAO(), DAOFactory.getApplicationDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getPolicyDAO(), geApiLifecycleManager(), DAOFactory.getLabelDAO(), DAOFactory.getWorkflowDAO(), DAOFactory.getTagDAO(), DAOFactory.getThreatProtectionDAO(), new GatewaySourceGeneratorImpl(), new APIGatewayPublisherImpl());
        // Register all the observers which need to observe 'Publisher' component
        apiPublisher.registerObserver(new EventLogger());
        apiPublisher.registerObserver(new FunctionTrigger(DAOFactory.getFunctionDAO(), new RestCallUtilImpl()));
        return apiPublisher;
    } catch (APIMgtDAOException e) {
        log.error("Couldn't Create API Provider", e);
        throw new APIMgtDAOException("Couldn't Create API Provider", ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 12 with Provider

use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.

the class ServiceReferenceHolder method getAPIMConfiguration.

/**
 * Gives the APIMConfigurations explicitly set in the deployment yaml or the default configurations
 *
 * @return APIMConfigurations
 */
public APIMConfigurations getAPIMConfiguration() {
    try {
        if (configProvider != null) {
            apimConfigurations = configProvider.getConfigurationObject(APIMConfigurations.class);
        } else {
            log.error("Configuration provider is null");
        }
    } catch (ConfigurationException e) {
        log.error("error getting config : org.wso2.carbon.apimgt.core.internal.APIMConfiguration", e);
    }
    if (apimConfigurations == null) {
        apimConfigurations = new APIMConfigurations();
        log.info("APIMConfiguration: Setting default configurations...");
    }
    return apimConfigurations;
}
Also used : ConfigurationException(org.wso2.carbon.config.ConfigurationException) APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations)

Example 13 with Provider

use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.

the class ServiceReferenceHolder method getEnvironmentConfigurations.

/**
 * Gives the EnvironmentConfigurations explicitly set in the deployment yaml or the default configurations
 *
 * @return EnvironmentConfigurations
 */
public EnvironmentConfigurations getEnvironmentConfigurations() {
    try {
        if (configProvider != null) {
            environmentConfigurations = configProvider.getConfigurationObject(EnvironmentConfigurations.class);
        } else {
            log.error("Configuration provider is null");
        }
    } catch (ConfigurationException e) {
        log.error("error getting config : org.wso2.carbon.apimgt.core.internal.EnvironmentConfigurations", e);
    }
    if (environmentConfigurations == null) {
        environmentConfigurations = new EnvironmentConfigurations();
        log.info("EnvironmentConfigurations: Setting default configurations...");
    }
    return environmentConfigurations;
}
Also used : EnvironmentConfigurations(org.wso2.carbon.apimgt.core.configuration.models.EnvironmentConfigurations) ConfigurationException(org.wso2.carbon.config.ConfigurationException)

Example 14 with Provider

use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createUniqueCompositeAPI.

public static CompositeAPI.Builder createUniqueCompositeAPI() {
    Set<String> transport = new HashSet<>();
    transport.add(HTTP);
    HashMap permissionMap = new HashMap();
    permissionMap.put(DEVELOPER_ROLE_ID, 6);
    permissionMap.put(ADMIN_ROLE_ID, 15);
    permissionMap.put(ADMIN_ROLE_ID, 7);
    Application app = createDefaultApplication();
    // generate random name for each time when generating unique composite API
    app.setName(UUID.randomUUID().toString());
    try {
        DAOFactory.getApplicationDAO().addApplication(app);
    } catch (APIMgtDAOException e) {
        log.error("Error adding application", e);
    }
    CompositeAPI.Builder apiBuilder = new CompositeAPI.Builder().id(UUID.randomUUID().toString()).name(UUID.randomUUID().toString()).provider(UUID.randomUUID().toString()).version(API_VERSION).context(UUID.randomUUID().toString()).description("Get Food & Beverage Info").transport(transport).permissionMap(permissionMap).applicationId(app.getId()).createdTime(LocalDateTime.now()).createdBy(API_CREATOR).uriTemplates(Collections.emptyMap()).apiDefinition(apiDefinition).lastUpdatedTime(LocalDateTime.now()).threatProtectionPolicies(threatProtectionPolicies);
    return apiBuilder;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) HashMap(java.util.HashMap) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) Application(org.wso2.carbon.apimgt.core.models.Application) HashSet(java.util.HashSet)

Example 15 with Provider

use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testGetAPIsWhenUserRolesInAPIPermissionsWithoutREAD.

@Test(description = "Tests getting the APIs when the user roles are contained in the API permission list " + "but without READ permissions")
public void testGetAPIsWhenUserRolesInAPIPermissionsWithoutREAD() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    Set<String> rolesOfUser = new HashSet<>();
    rolesOfUser.add(SampleTestObjectCreator.DEVELOPER_ROLE_ID);
    // This user is not the provider of the API
    List<API> apiList = apiDAO.getAPIs(rolesOfUser, ALTERNATIVE_USER);
    Assert.assertTrue(apiList.isEmpty());
    Map map = new HashMap();
    map.put(SampleTestObjectCreator.DEVELOPER_ROLE_ID, 0);
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().permissionMap(map);
    API api1 = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api1);
    apiList = apiDAO.getAPIs(rolesOfUser, ALTERNATIVE_USER);
    // Since the API has the role ID of the user but without READ permissions, it is not visible to this user
    Assert.assertTrue(apiList.size() == 0);
}
Also used : HashMap(java.util.HashMap) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) HashMap(java.util.HashMap) Map(java.util.Map) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)82 ArrayList (java.util.ArrayList)70 API (org.wso2.carbon.apimgt.api.model.API)64 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)50 Test (org.junit.Test)49 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)45 HashMap (java.util.HashMap)40 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)36 IOException (java.io.IOException)35 Resource (org.wso2.carbon.registry.core.Resource)34 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)32 HashSet (java.util.HashSet)30 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)29 UserStoreException (org.wso2.carbon.user.api.UserStoreException)29 PreparedStatement (java.sql.PreparedStatement)28 Connection (java.sql.Connection)27 SQLException (java.sql.SQLException)27 ResultSet (java.sql.ResultSet)25 QName (javax.xml.namespace.QName)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25