Search in sources :

Example 41 with APIAdminImpl

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

the class ApplicationsApiServiceImpl method applicationsGet.

@Override
public Response applicationsGet(String user, Integer limit, Integer offset, String accept, String applicationName, String tenantDomain, String sortBy, String sortOrder, MessageContext messageContext) {
    // To store the initial value of the user (specially if it is null or empty)
    String givenUser = user;
    // if no username provided user associated with access token will be used
    if (user == null || StringUtils.isEmpty(user)) {
        user = RestApiCommonUtil.getLoggedInUsername();
        givenUser = StringUtils.EMPTY;
    }
    limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
    offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
    sortOrder = sortOrder != null ? sortOrder : RestApiConstants.DEFAULT_SORT_ORDER;
    sortBy = getApplicationsSortByField(sortBy);
    applicationName = applicationName != null ? applicationName : StringUtils.EMPTY;
    ApplicationListDTO applicationListDTO;
    try {
        Application[] allMatchedApps;
        boolean migrationMode = Boolean.getBoolean(RestApiConstants.MIGRATION_MODE);
        int allApplicationsCount = 0;
        if (!migrationMode) {
            // normal non-migration flow
            if (!MultitenantUtils.getTenantDomain(user).equals(RestApiCommonUtil.getLoggedInUserTenantDomain())) {
                String errorMsg = "User " + user + " is not available for the current tenant domain";
                log.error(errorMsg);
                return Response.status(Response.Status.FORBIDDEN).entity(errorMsg).build();
            }
            APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(user);
            // If no user is passed, get the applications for the tenant (not only for the user)
            APIAdmin apiAdmin = new APIAdminImpl();
            int tenantId = APIUtil.getTenantId(user);
            allMatchedApps = apiAdmin.getApplicationsWithPagination(user, givenUser, tenantId, limit, offset, applicationName, sortBy, sortOrder);
            allApplicationsCount = apiAdmin.getApplicationsCount(tenantId, givenUser, applicationName);
        } else {
            // flow at migration process
            if (StringUtils.isEmpty(tenantDomain)) {
                tenantDomain = MultitenantUtils.getTenantDomain(user);
            }
            RestApiUtil.handleMigrationSpecificPermissionViolations(tenantDomain, RestApiCommonUtil.getLoggedInUsername());
            APIAdmin apiAdmin = new APIAdminImpl();
            allMatchedApps = apiAdmin.getAllApplicationsOfTenantForMigration(tenantDomain);
        }
        applicationListDTO = ApplicationMappingUtil.fromApplicationsToDTO(allMatchedApps);
        ApplicationMappingUtil.setPaginationParams(applicationListDTO, limit, offset, allApplicationsCount);
        return Response.ok().entity(applicationListDTO).build();
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while retrieving applications of the user " + user, e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) Application(org.wso2.carbon.apimgt.api.model.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationListDTO)

Example 42 with APIAdminImpl

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

the class KeyManagersApiServiceImpl method keyManagersGet.

public Response keyManagersGet(MessageContext messageContext) throws APIManagementException {
    String organization = RestApiUtil.getOrganization(messageContext);
    APIAdmin apiAdmin = new APIAdminImpl();
    List<KeyManagerConfigurationDTO> keyManagerConfigurationsByOrganization = apiAdmin.getKeyManagerConfigurationsByOrganization(organization);
    KeyManagerListDTO keyManagerListDTO = KeyManagerMappingUtil.toKeyManagerListDTO(keyManagerConfigurationsByOrganization);
    return Response.ok().entity(keyManagerListDTO).build();
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) KeyManagerListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerListDTO) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 43 with APIAdminImpl

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

the class KeyManagersApiServiceImpl method keyManagersKeyManagerIdDelete.

public Response keyManagersKeyManagerIdDelete(String keyManagerId, MessageContext messageContext) throws APIManagementException {
    String organization = RestApiUtil.getOrganization(messageContext);
    APIAdmin apiAdmin = new APIAdminImpl();
    KeyManagerConfigurationDTO keyManagerConfigurationDTO = apiAdmin.getKeyManagerConfigurationById(organization, keyManagerId);
    if (keyManagerConfigurationDTO != null) {
        apiAdmin.deleteKeyManagerConfigurationById(organization, keyManagerConfigurationDTO);
        APIUtil.logAuditMessage(APIConstants.AuditLogConstants.KEY_MANAGER, new Gson().toJson(keyManagerConfigurationDTO), APIConstants.AuditLogConstants.DELETED, RestApiCommonUtil.getLoggedInUsername());
        return Response.ok().build();
    } else {
        throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND);
    }
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Gson(com.google.gson.Gson) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 44 with APIAdminImpl

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

the class KeyManagersApiServiceImpl method keyManagersPost.

public Response keyManagersPost(KeyManagerDTO body, MessageContext messageContext) throws APIManagementException {
    String organization = RestApiUtil.getOrganization(messageContext);
    APIAdmin apiAdmin = new APIAdminImpl();
    try {
        KeyManagerConfigurationDTO keyManagerConfigurationDTO = KeyManagerMappingUtil.toKeyManagerConfigurationDTO(organization, body);
        KeyManagerConfigurationDTO createdKeyManagerConfiguration = apiAdmin.addKeyManagerConfiguration(keyManagerConfigurationDTO);
        APIUtil.logAuditMessage(APIConstants.AuditLogConstants.KEY_MANAGER, new Gson().toJson(keyManagerConfigurationDTO), APIConstants.AuditLogConstants.CREATED, RestApiCommonUtil.getLoggedInUsername());
        URI location = new URI(RestApiConstants.KEY_MANAGERS + "/" + createdKeyManagerConfiguration.getUuid());
        return Response.created(location).entity(KeyManagerMappingUtil.toKeyManagerDTO(createdKeyManagerConfiguration)).build();
    } catch (URISyntaxException e) {
        String error = "Error while Creating Key Manager configuration in organization " + organization;
        throw new APIManagementException(error, e, ExceptionCodes.INTERNAL_ERROR);
    }
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Gson(com.google.gson.Gson) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 45 with APIAdminImpl

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

the class TenantConfigSchemaApiServiceImpl method exportTenantConfigSchema.

public Response exportTenantConfigSchema(MessageContext messageContext) throws APIManagementException {
    APIAdmin apiAdmin = new APIAdminImpl();
    String tenantConfig = apiAdmin.getTenantConfigSchema(RestApiCommonUtil.getLoggedInUserTenantDomain());
    return Response.ok().entity(tenantConfig).header(RestApiConstants.HEADER_CONTENT_TYPE, RestApiConstants.APPLICATION_JSON).build();
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Aggregations

APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)46 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)31 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 BeforeTest (org.testng.annotations.BeforeTest)8 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)8 APIUtil (org.wso2.carbon.apimgt.impl.utils.APIUtil)6 ArrayList (java.util.ArrayList)5 Schema (org.everit.json.schema.Schema)5 File (java.io.File)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 BotDetectionData (org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)4 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)4 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)4 GlobalPolicy (org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy)4 Policy (org.wso2.carbon.apimgt.api.model.policy.Policy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)4 Gson (com.google.gson.Gson)3