Search in sources :

Example 1 with ScopeListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.

the class SystemScopesApiServiceImpl method systemScopesGet.

public Response systemScopesGet(MessageContext messageContext) {
    try {
        Map<String, String> scopeRoleMapping = APIUtil.getRESTAPIScopesForTenantWithoutRoleMappings(MultitenantUtils.getTenantDomain(RestApiCommonUtil.getLoggedInUsername()));
        ScopeListDTO scopeListDTO = SystemScopesMappingUtil.fromScopeListToScopeListDTO(scopeRoleMapping);
        return Response.ok().entity(scopeListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error when getting the list of scopes-role mapping.";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : ScopeListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeListDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 2 with ScopeListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.

the class SystemScopesApiServiceImpl method updateRolesForScope.

public Response updateRolesForScope(ScopeListDTO body, MessageContext messageContext) throws APIManagementException {
    JSONObject newScopeRoleJson = SystemScopesMappingUtil.createJsonObjectOfScopeMapping(body);
    APIUtil.updateTenantConfOfRoleScopeMapping(newScopeRoleJson, RestApiCommonUtil.getLoggedInUsername());
    Map<String, String> scopeRoleMapping = APIUtil.getRESTAPIScopesForTenantWithoutRoleMappings(MultitenantUtils.getTenantDomain(RestApiCommonUtil.getLoggedInUsername()));
    ScopeListDTO scopeListDTO = SystemScopesMappingUtil.fromScopeListToScopeListDTO(scopeRoleMapping);
    return Response.ok().entity(scopeListDTO).build();
}
Also used : JSONObject(org.json.simple.JSONObject) ScopeListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeListDTO)

Example 3 with ScopeListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisApiIdScopesGet.

@Override
public Response apisApiIdScopesGet(String apiId, String ifNoneMatch, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        Map<String, String> scopeSet = apiPublisher.getScopesForApi(apiId);
        ScopeListDTO scopeListDTO = MappingUtil.toScopeListDto(scopeSet);
        return Response.ok().entity(scopeListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving scopes of API : " + apiId;
        HashMap<String, String> paramList = new HashMap<String, String>();
        paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : ScopeListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeListDTO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher)

Example 4 with ScopeListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.

the class TestMappingUtilTestCase method testScopeMappingUtil.

@Test
public void testScopeMappingUtil() {
    Map<String, String> scopeMap = new HashMap<>();
    scopeMap.put("apim:api-read", "read apis");
    ScopeListDTO scopeListDTO = MappingUtil.toScopeListDto(scopeMap);
    Assert.assertEquals(scopeListDTO.getCount().intValue(), 1);
}
Also used : ScopeListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeListDTO) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 5 with ScopeListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.

the class MappingUtil method toScopeListDto.

/**
 * This method used to convert scope map
 *
 * @param scopeMap map of scopes
 * @return ScopeListDTO object
 */
public static ScopeListDTO toScopeListDto(Map<String, String> scopeMap) {
    ScopeListDTO scopeListDTO = new ScopeListDTO();
    scopeMap.forEach((name, description) -> {
        scopeListDTO.addListItem(new ScopeList_listDTO().name(name).description(description));
    });
    scopeListDTO.setCount(scopeMap.size());
    return scopeListDTO;
}
Also used : ScopeListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeListDTO) ScopeList_listDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeList_listDTO)

Aggregations

ScopeListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeListDTO)3 ScopeListDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeListDTO)3 HashMap (java.util.HashMap)2 JSONObject (org.json.simple.JSONObject)2 ScopeListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO)2 JSONArray (org.json.JSONArray)1 Test (org.testng.annotations.Test)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 Scope (org.wso2.carbon.apimgt.api.model.Scope)1 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 ScopeDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeDTO)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1 ScopeList_listDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeList_listDTO)1 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)1 ScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO)1