Search in sources :

Example 6 with Feature

use of org.wso2.carbon.apimgt.rest.api.configurations.models.Feature in project carbon-apimgt by wso2.

the class ServiceReferenceHolderTestCase method testGetAvailableFeatures.

@Test
public void testGetAvailableFeatures() throws ConfigurationException {
    // //Happy Path
    ServiceReferenceHolder instance = ServiceReferenceHolder.getInstance();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    instance.setConfigProvider(configProvider);
    Map configs = new HashMap<>();
    configs.put(ConfigurationAPIConstants.ENABLED, true);
    Mockito.when(configProvider.getConfigurationObject(Mockito.anyString())).thenReturn(configs);
    Map<String, Feature> featureList = instance.getAvailableFeatures();
    Assert.assertNotNull(featureList);
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Feature(org.wso2.carbon.apimgt.rest.api.configurations.models.Feature) Test(org.testng.annotations.Test)

Example 7 with Feature

use of org.wso2.carbon.apimgt.rest.api.configurations.models.Feature in project product-iots by wso2.

the class PolicyOperations method createPasscodePolicy.

public static boolean createPasscodePolicy(String policyName, String deviceType) {
    HashMap<String, String> headers = new HashMap<String, String>();
    String policyEndpoint = EMMQSGConfig.getInstance().getEmmHost() + "/api/device-mgt/v1.0/policies";
    // Set the policy payload
    JSONObject policyData = new JSONObject();
    policyData.put("policyName", policyName);
    policyData.put("description", "Passcode Policy");
    policyData.put("compliance", "enforce");
    policyData.put("ownershipType", "ANY");
    policyData.put("active", false);
    JSONObject profile = new JSONObject();
    profile.put("profileName", "passcode");
    profile.put("deviceType", deviceType);
    JSONArray featureList = new JSONArray();
    JSONObject feature = new JSONObject();
    feature.put("featureCode", "PASSCODE_POLICY");
    feature.put("deviceType", deviceType);
    JSONObject featureContent = new JSONObject();
    featureContent.put("allowSimple", false);
    featureContent.put("requireAlphanumeric", true);
    featureContent.put("minLength", "5");
    featureContent.put("minComplexChars", "2");
    featureContent.put("maxPINAgeInDays", 7);
    featureContent.put("pinHistory", 7);
    featureContent.put("maxFailedAttempts", null);
    feature.put("content", featureContent);
    featureList.add(feature);
    profile.put("profileFeaturesList", featureList);
    JSONArray roles = new JSONArray();
    roles.add(Constants.EMM_USER_ROLE);
    policyData.put("profile", profile);
    policyData.put("roles", roles);
    // Set the headers
    headers.put(Constants.Header.CONTENT_TYPE, Constants.ContentType.APPLICATION_JSON);
    HTTPResponse httpResponse = HTTPInvoker.sendHTTPPostWithOAuthSecurity(policyEndpoint, policyData.toJSONString(), headers);
    if (httpResponse.getResponseCode() == Constants.HTTPStatus.CREATED) {
        return true;
    }
    return false;
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) JSONArray(org.json.simple.JSONArray)

Example 8 with Feature

use of org.wso2.carbon.apimgt.rest.api.configurations.models.Feature in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method updateAuditApi.

/**
 * Update API Definition before retrieving Security Audit Report
 * @param apiDefinition API Definition of API
 * @param apiToken API Token to access Security Audit
 * @param auditUuid Respective UUID of API in Security Audit
 * @param baseUrl Base URL to communicate with Security Audit
 * @param isDebugEnabled Boolean whether debug is enabled
 * @throws IOException In the event of any problems with the request
 * @throws APIManagementException In the event of unexpected response
 */
private void updateAuditApi(String apiDefinition, String apiToken, String auditUuid, String baseUrl, boolean isDebugEnabled) throws IOException, APIManagementException {
    // Set the property to be attached in the body of the request
    // Attach API Definition to property called specfile to be sent in the request
    JSONObject jsonBody = new JSONObject();
    jsonBody.put("specfile", Base64Utils.encode(apiDefinition.getBytes(StandardCharsets.UTF_8)));
    // Logic for HTTP Request
    String putUrl = baseUrl + "/" + auditUuid;
    URL updateApiUrl = new URL(putUrl);
    try (CloseableHttpClient httpClient = (CloseableHttpClient) APIUtil.getHttpClient(updateApiUrl.getPort(), updateApiUrl.getProtocol())) {
        HttpPut httpPut = new HttpPut(putUrl);
        // Set the header properties of the request
        httpPut.setHeader(APIConstants.HEADER_ACCEPT, APIConstants.APPLICATION_JSON_MEDIA_TYPE);
        httpPut.setHeader(APIConstants.HEADER_CONTENT_TYPE, APIConstants.APPLICATION_JSON_MEDIA_TYPE);
        httpPut.setHeader(APIConstants.HEADER_API_TOKEN, apiToken);
        httpPut.setHeader(APIConstants.HEADER_USER_AGENT, APIConstants.USER_AGENT_APIM);
        httpPut.setEntity(new StringEntity(jsonBody.toJSONString()));
        // Code block for processing the response
        try (CloseableHttpResponse response = httpClient.execute(httpPut)) {
            if (isDebugEnabled) {
                log.debug("HTTP status " + response.getStatusLine().getStatusCode());
            }
            if (!(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)) {
                throw new APIManagementException("Error while sending data to the API Security Audit Feature. Found http status " + response.getStatusLine());
            }
        } finally {
            httpPut.releaseConnection();
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) StringEntity(org.apache.http.entity.StringEntity) JSONObject(org.json.simple.JSONObject) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) URL(java.net.URL) HttpPut(org.apache.http.client.methods.HttpPut)

Example 9 with Feature

use of org.wso2.carbon.apimgt.rest.api.configurations.models.Feature in project carbon-apimgt by wso2.

the class APIUtil method isStoreForumEnabled.

/**
 * return whether store forum feature is enabled
 *
 * @return true or false indicating enable or not
 */
public static boolean isStoreForumEnabled() {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String forumEnabled = config.getFirstProperty(APIConstants.API_STORE_FORUM_ENABLED);
    if (forumEnabled == null) {
        return true;
    }
    return Boolean.parseBoolean(forumEnabled);
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 10 with Feature

use of org.wso2.carbon.apimgt.rest.api.configurations.models.Feature in project carbon-apimgt by wso2.

the class APIUtil method isMapExistingAuthAppsEnabled.

/**
 * Used to check whether Provisioning Out-of-Band OAuth Clients feature is enabled
 *
 * @return true if feature is enabled
 */
public static boolean isMapExistingAuthAppsEnabled() {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String mappingEnabled = config.getFirstProperty(APIConstants.API_STORE_MAP_EXISTING_AUTH_APPS);
    if (mappingEnabled == null) {
        return false;
    }
    return Boolean.parseBoolean(mappingEnabled);
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Aggregations

HashMap (java.util.HashMap)3 JSONObject (org.json.simple.JSONObject)3 Feature (org.wso2.carbon.apimgt.rest.api.configurations.models.Feature)3 Map (java.util.Map)2 Test (org.testng.annotations.Test)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)2 ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OMException (org.apache.axiom.om.OMException)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPut (org.apache.http.client.methods.HttpPut)1 StringEntity (org.apache.http.entity.StringEntity)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 JSONArray (org.json.simple.JSONArray)1 ParseException (org.json.simple.parser.ParseException)1