use of org.wso2.carbon.apimgt.api.APIAdmin 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;
}
use of org.wso2.carbon.apimgt.api.APIAdmin 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();
}
use of org.wso2.carbon.apimgt.api.APIAdmin 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);
}
}
use of org.wso2.carbon.apimgt.api.APIAdmin 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);
}
}
use of org.wso2.carbon.apimgt.api.APIAdmin 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();
}
Aggregations