Search in sources :

Example 1 with ScopeDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeDTO in project carbon-apimgt by wso2.

the class MappingUtil method scopeDto.

/**
 * used to convert {@link Scope} to {@link ScopeDTO}
 * @param scope scope Object
 * @param scopeBindingType type of bindings
 * @return ScopeDTO object
 */
public static ScopeDTO scopeDto(Scope scope, String scopeBindingType) {
    ScopeDTO scopeDTO = new ScopeDTO();
    scopeDTO.setName(scope.getName());
    scopeDTO.setDescription(scope.getDescription());
    Scope_bindingsDTO scopeBindingsDTO = new Scope_bindingsDTO();
    scopeBindingsDTO.setType(scopeBindingType);
    if (scope.getBindings() != null) {
        scopeBindingsDTO.setValues(scope.getBindings());
    } else {
        scopeBindingsDTO.setValues(Collections.emptyList());
    }
    scopeDTO.setBindings(scopeBindingsDTO);
    return scopeDTO;
}
Also used : Scope_bindingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.Scope_bindingsDTO) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeDTO)

Example 2 with ScopeDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeDTO in project carbon-apimgt by wso2.

the class MappingUtil method toScope.

/**
 * This method convert {@link ScopeDTO} to {@link Scope}
 * @param body scopeDto Object
 * @return scope object
 */
public static Scope toScope(ScopeDTO body) {
    Scope scope = new Scope();
    scope.setName(body.getName());
    scope.setDescription(body.getDescription());
    Scope_bindingsDTO scopeBindingsDTO = body.getBindings();
    if (scopeBindingsDTO != null) {
        scope.setBindings(scopeBindingsDTO.getValues());
    }
    return scope;
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) Scope_bindingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.Scope_bindingsDTO)

Example 3 with ScopeDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisApiIdScopesNameGet.

@Override
public Response apisApiIdScopesNameGet(String apiId, String name, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        Scope scope = apiPublisher.getScopeInformationOfApi(apiId, name);
        KeyMgtConfigurations keyManagerConfiguration = APIMConfigurationService.getInstance().getApimConfigurations().getKeyManagerConfigs();
        ScopeDTO scopeDTO = MappingUtil.scopeDto(scope, keyManagerConfiguration.getScopeBindingType());
        return Response.ok().entity(scopeDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving swagger definition 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 : Scope(org.wso2.carbon.apimgt.core.models.Scope) KeyMgtConfigurations(org.wso2.carbon.apimgt.core.configuration.models.KeyMgtConfigurations) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher)

Example 4 with ScopeDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeDTO in project carbon-apimgt by wso2.

the class AMDefaultKeyManagerImpl method updateScope.

/**
 * This method will be used to update a Scope in the authorization server.
 *
 * @param scope Scope object
 * @throws APIManagementException if an error occurs while updating the scope
 */
@Override
public void updateScope(Scope scope) throws APIManagementException {
    String scopeKey = scope.getKey();
    try {
        ScopeDTO scopeDTO = new ScopeDTO();
        scopeDTO.setDisplayName(scope.getName());
        scopeDTO.setDescription(scope.getDescription());
        if (StringUtils.isNotBlank(scope.getRoles()) && scope.getRoles().trim().split(",").length > 0) {
            scopeDTO.setBindings(Arrays.asList(scope.getRoles().trim().split(",")));
        }
        scopeClient.updateScope(scopeDTO, scope.getKey());
    } catch (KeyManagerClientException e) {
        String errorMessage = "Error occurred while updating scope: " + scopeKey;
        handleException(errorMessage, e);
    }
}
Also used : KeyManagerClientException(org.wso2.carbon.apimgt.impl.kmclient.KeyManagerClientException) ScopeDTO(org.wso2.carbon.apimgt.impl.dto.ScopeDTO)

Example 5 with ScopeDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method getAPIScopesFromScopeDTOs.

/**
 * Convert ScopeDTO List to APIScopesDTO List adding the attribute 'isShared'.
 *
 * @param scopeDTOS ScopeDTO List
 * @return APIScopeDTO List
 * @throws APIManagementException if an error occurs while converting ScopeDTOs to APIScopeDTOs
 */
private static List<APIScopeDTO> getAPIScopesFromScopeDTOs(List<ScopeDTO> scopeDTOS) throws APIManagementException {
    List<APIScopeDTO> apiScopeDTOS = new ArrayList<>();
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
    Set<String> allSharedScopeKeys = apiProvider.getAllSharedScopeKeys(tenantDomain);
    scopeDTOS.forEach(scopeDTO -> {
        APIScopeDTO apiScopeDTO = new APIScopeDTO();
        apiScopeDTO.setScope(scopeDTO);
        apiScopeDTO.setShared(allSharedScopeKeys.contains(scopeDTO.getName()) ? Boolean.TRUE : Boolean.FALSE);
        apiScopeDTOS.add(apiScopeDTO);
    });
    return apiScopeDTOS;
}
Also used : APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO) ArrayList(java.util.ArrayList) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Aggregations

Scope (org.wso2.carbon.apimgt.api.model.Scope)11 ScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO)11 ArrayList (java.util.ArrayList)10 APIScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO)8 HashMap (java.util.HashMap)7 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)6 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 Scope (org.wso2.carbon.apimgt.core.models.Scope)4 JSONObject (org.json.simple.JSONObject)3 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 APICategory (org.wso2.carbon.apimgt.api.model.APICategory)2 CORSConfiguration (org.wso2.carbon.apimgt.api.model.CORSConfiguration)2