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);
}
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;
}
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();
}
}
}
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);
}
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);
}
Aggregations