Search in sources :

Example 1 with ScopeDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.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.identity.oauth.scope.endpoint.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.identity.oauth.scope.endpoint.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.identity.oauth.scope.endpoint.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.identity.oauth.scope.endpoint.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

ArrayList (java.util.ArrayList)23 ScopeDTO (org.wso2.carbon.identity.oauth.dto.ScopeDTO)18 HashMap (java.util.HashMap)13 Scope (org.wso2.carbon.apimgt.api.model.Scope)11 ScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO)11 Test (org.testng.annotations.Test)8 APIScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO)8 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)8 Scope (org.wso2.carbon.identity.oauth2.bean.Scope)8 HashSet (java.util.HashSet)7 List (java.util.List)7 ScopeDTO (org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO)7 Map (java.util.Map)6 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)6 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)6 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)6 OIDCScopeClaimCacheEntry (org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry)6 Matchers.anyString (org.mockito.Matchers.anyString)5 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)4 Arrays (java.util.Arrays)4