Search in sources :

Example 61 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method init.

/**
 * To initialize the publisherRoleCache configurations, based on configurations.
 */
public static void init() throws APIManagementException {
    APIManagerConfiguration apiManagerConfiguration = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String isPublisherRoleCacheEnabledConfiguration = apiManagerConfiguration.getFirstProperty(APIConstants.PUBLISHER_ROLE_CACHE_ENABLED);
    isPublisherRoleCacheEnabled = isPublisherRoleCacheEnabledConfiguration == null || Boolean.parseBoolean(isPublisherRoleCacheEnabledConfiguration);
    try {
        eventPublisherFactory = ServiceReferenceHolder.getInstance().getEventPublisherFactory();
        eventPublishers.putIfAbsent(EventPublisherType.ASYNC_WEBHOOKS, eventPublisherFactory.getEventPublisher(EventPublisherType.ASYNC_WEBHOOKS));
        eventPublishers.putIfAbsent(EventPublisherType.CACHE_INVALIDATION, eventPublisherFactory.getEventPublisher(EventPublisherType.CACHE_INVALIDATION));
        eventPublishers.putIfAbsent(EventPublisherType.GLOBAL_CACHE_INVALIDATION, eventPublisherFactory.getEventPublisher(EventPublisherType.GLOBAL_CACHE_INVALIDATION));
        eventPublishers.putIfAbsent(EventPublisherType.NOTIFICATION, eventPublisherFactory.getEventPublisher(EventPublisherType.NOTIFICATION));
        eventPublishers.putIfAbsent(EventPublisherType.TOKEN_REVOCATION, eventPublisherFactory.getEventPublisher(EventPublisherType.TOKEN_REVOCATION));
        eventPublishers.putIfAbsent(EventPublisherType.BLOCKING_EVENT, eventPublisherFactory.getEventPublisher(EventPublisherType.BLOCKING_EVENT));
        eventPublishers.putIfAbsent(EventPublisherType.KEY_TEMPLATE, eventPublisherFactory.getEventPublisher(EventPublisherType.KEY_TEMPLATE));
        eventPublishers.putIfAbsent(EventPublisherType.KEYMGT_EVENT, eventPublisherFactory.getEventPublisher(EventPublisherType.KEYMGT_EVENT));
    } catch (EventPublisherException e) {
        log.error("Could not initialize the event publishers. Events might not be published properly.");
        throw new APIManagementException(e);
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) EventPublisherException(org.wso2.carbon.apimgt.eventing.EventPublisherException)

Example 62 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method isAllowedScope.

/**
 * Determines if the scope is specified in the whitelist.
 *
 * @param scope - The scope key to check
 * @return - 'true' if the scope is white listed. 'false' if not.
 */
public static boolean isAllowedScope(String scope) {
    if (allowedScopes == null) {
        APIManagerConfiguration configuration = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
        // Read scope whitelist from Configuration.
        List<String> whitelist = configuration.getProperty(APIConstants.ALLOWED_SCOPES);
        // If whitelist is null, default scopes will be put.
        if (whitelist == null) {
            whitelist = new ArrayList<String>();
            whitelist.add(APIConstants.OPEN_ID_SCOPE_NAME);
            whitelist.add(APIConstants.DEVICE_SCOPE_PATTERN);
        }
        allowedScopes = new HashSet<String>(whitelist);
    }
    for (String scopeTobeSkipped : allowedScopes) {
        if (scope.matches(scopeTobeSkipped)) {
            return true;
        }
    }
    return false;
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 63 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method getRESTApiGroupingExtractorImplementation.

/**
 * Read the REST API group id extractor class reference from api-manager.xml.
 *
 * @return REST API group id extractor class reference.
 */
public static String getRESTApiGroupingExtractorImplementation() {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String restApiGroupingExtractor = config.getFirstProperty(APIConstants.API_STORE_REST_API_GROUP_EXTRACTOR_IMPLEMENTATION);
    if (StringUtils.isEmpty(restApiGroupingExtractor)) {
        restApiGroupingExtractor = getGroupingExtractorImplementation();
    }
    return restApiGroupingExtractor;
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 64 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method getExternalIDPOrigin.

/**
 * Get the External IDP host name when UIs use an external IDP for SSO or other purpose
 * By default this is equal to $ref{server.base_path} (i:e https://localhost:9443)
 *
 * @return Origin string of the external IDP
 */
public static String getExternalIDPOrigin() throws APIManagementException {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String idpEndpoint = config.getFirstProperty(APIConstants.IDENTITY_PROVIDER_SERVER_URL);
    if (idpEndpoint == null) {
        return getServerURL();
    } else {
        return idpEndpoint;
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 65 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method getOAuthConfigurationFromAPIMConfig.

/**
 * This method is used to get the authorization configurations from the api manager configurations
 *
 * @param property The configuration to get from api-manager.xml
 * @return The configuration read from api-manager.xml or else null
 * @throws APIManagementException Throws if the registry resource doesn't exist
 *                                or the content cannot be parsed to JSON
 */
public static String getOAuthConfigurationFromAPIMConfig(String property) throws APIManagementException {
    // If tenant registry doesn't have the configuration, then read it from api-manager.xml
    APIManagerConfiguration apimConfig = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String oAuthConfiguration = apimConfig.getFirstProperty(APIConstants.OAUTH_CONFIGS + property);
    if (!StringUtils.isBlank(oAuthConfiguration)) {
        return oAuthConfiguration;
    }
    return null;
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Aggregations

APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)122 Test (org.junit.Test)76 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)67 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)51 HashMap (java.util.HashMap)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)36 RealmService (org.wso2.carbon.user.core.service.RealmService)33 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)31 ArrayList (java.util.ArrayList)26 API (org.wso2.carbon.apimgt.api.model.API)25 Before (org.junit.Before)24 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)24 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)24 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)23 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)23 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)22 MessageContext (org.apache.synapse.MessageContext)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)20 Cache (javax.cache.Cache)19 Map (java.util.Map)18