use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO in project carbon-apimgt by wso2.
the class ScopesApiServiceImpl method getSharedScope.
/**
* Get shared scope by Id.
*
* @param scopeId UUID of the scope
* @param messageContext CXF Message Context
* @return Shared Scope DTO
* @throws APIManagementException If an error occurs while getting shared scope
*/
@Override
public Response getSharedScope(String scopeId, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
if (StringUtils.isEmpty(scopeId)) {
throw new APIManagementException("Scope Id cannot be null or empty", ExceptionCodes.SHARED_SCOPE_ID_NOT_SPECIFIED);
}
Scope scope = apiProvider.getSharedScopeByUUID(scopeId, tenantDomain);
ScopeDTO scopeDTO = SharedScopeMappingUtil.fromScopeToDTO(scope);
return Response.ok().entity(scopeDTO).build();
}
use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO in project carbon-apimgt by wso2.
the class ScopesApiServiceImpl method addSharedScope.
/**
* Add Shared Scope.
*
* @param body Scope DTO object to add
* @param messageContext CXF Message Context
* @return Created Scope as DTO
* @throws APIManagementException If an error occurs while adding shared scope.
*/
@Override
public Response addSharedScope(ScopeDTO body, MessageContext messageContext) throws APIManagementException {
String scopeName = body.getName();
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
if (StringUtils.isEmpty(scopeName)) {
throw new APIManagementException("Shared Scope Name cannot be null or empty", ExceptionCodes.SHARED_SCOPE_NAME_NOT_SPECIFIED);
}
if (StringUtils.isEmpty(body.getDisplayName())) {
throw new APIManagementException("Shared scope Display Name cannot be null or empty", ExceptionCodes.SHARED_SCOPE_DISPLAY_NAME_NOT_SPECIFIED);
}
if (apiProvider.isScopeKeyExist(scopeName, APIUtil.getTenantIdFromTenantDomain(tenantDomain))) {
throw new APIManagementException(ExceptionCodes.from(ExceptionCodes.SCOPE_ALREADY_REGISTERED, scopeName));
}
Scope scopeToAdd = SharedScopeMappingUtil.fromDTOToScope(body);
String sharedScopeId = apiProvider.addSharedScope(scopeToAdd, tenantDomain);
// Get registered shared scope
Scope createdScope = apiProvider.getSharedScopeByUUID(sharedScopeId, tenantDomain);
ScopeDTO createdScopeDTO = SharedScopeMappingUtil.fromScopeToDTO(createdScope);
String createdScopeURIString = RestApiConstants.RESOURCE_PATH_SHARED_SCOPES_SCOPE_ID.replace(RestApiConstants.SHARED_SCOPE_ID_PARAM, createdScopeDTO.getId());
URI createdScopeURI = new URI(createdScopeURIString);
return Response.created(createdScopeURI).entity(createdScopeDTO).build();
} catch (URISyntaxException e) {
throw new APIManagementException("Error while creating shared scope: " + scopeName, e);
}
}
use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method getScopeInfoDTO.
public static List<ScopeInfoDTO> getScopeInfoDTO(Set<Scope> scopes) {
List<ScopeInfoDTO> scopeDto = new ArrayList<ScopeInfoDTO>();
for (Scope scope : scopes) {
ScopeInfoDTO scopeInfoDTO = new ScopeInfoDTO();
scopeInfoDTO.setKey(scope.getKey());
scopeInfoDTO.setName(scope.getName());
scopeInfoDTO.setDescription(scope.getDescription());
if (StringUtils.isNotBlank(scope.getRoles())) {
scopeInfoDTO.setRoles(Arrays.asList(scope.getRoles().trim().split(",")));
}
scopeDto.add(scopeInfoDTO);
}
return scopeDto;
}
use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO in project carbon-apimgt by wso2.
the class SystemScopesMappingUtil method fromRoleScopeMapToRoleScopeDTOList.
/**
* Converts api scope-role mapping to RoleScopeDTO List.
*
* @param scopeRoleMapping Map of a Role Scope Mapping
* @return RoleScopeDTO list
*/
private static List<ScopeDTO> fromRoleScopeMapToRoleScopeDTOList(Map<String, String> scopeRoleMapping) throws APIManagementException {
List<ScopeDTO> scopeDTOs = new ArrayList<>(scopeRoleMapping.size());
if (portalScopeList.isEmpty()) {
synchronized (lock) {
if (portalScopeList.isEmpty()) {
portalScopeList = RestApiUtil.getScopesInfoFromAPIYamlDefinitions();
}
}
}
for (Map.Entry<String, List<String>> mapping : portalScopeList.entrySet()) {
// openid scope doesn't need a role mapping
if (APIConstants.OPEN_ID_SCOPE_NAME.equals(mapping.getKey())) {
continue;
}
if (scopeRoleMapping.containsKey(mapping.getKey())) {
ScopeDTO roleScopeDTO = new ScopeDTO();
roleScopeDTO.setName(mapping.getKey());
String roles = scopeRoleMapping.get(mapping.getKey());
List<String> roleList = new ArrayList<String>(Arrays.asList((roles.replaceAll("\\s+", "")).split(",")));
roleScopeDTO.setRoles(roleList);
roleScopeDTO.setDescription(mapping.getValue().get(0));
roleScopeDTO.setTag(mapping.getValue().get(1));
scopeDTOs.add(roleScopeDTO);
} else {
log.warn("The scope " + mapping.getKey() + " does not exist in tenant.conf");
}
}
return scopeDTOs;
}
use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method getScopesFromSwagger.
/**
* Extract scopes from the swagger.
*
* @param swagger swagger document
* @return list of scopes
* @throws APIManagementException throw if parsing exception occur
*/
private static List<ScopeDTO> getScopesFromSwagger(String swagger) throws APIManagementException {
APIDefinition apiDefinition = OASParserUtil.getOASParser(swagger);
Set<Scope> scopes = apiDefinition.getScopes(swagger);
List<ScopeDTO> scopeDTOS = new ArrayList<>();
for (Scope aScope : scopes) {
ScopeDTO scopeDTO = new ScopeDTO();
scopeDTO.setName(aScope.getKey());
scopeDTO.setDisplayName(aScope.getName());
scopeDTO.setDescription(aScope.getDescription());
String roles = aScope.getRoles();
if (roles == null || roles.isEmpty()) {
scopeDTO.setBindings(Collections.emptyList());
} else {
scopeDTO.setBindings(Arrays.asList((roles).split(",")));
}
scopeDTOS.add(scopeDTO);
}
return scopeDTOS;
}
Aggregations