use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeDTO in project carbon-apimgt by wso2.
the class AMDefaultKeyManagerImpl method registerScope.
/**
* This method will be used to register a Scope in the authorization server.
*
* @param scope Scope to register
* @throws APIManagementException if there is an error while registering a new scope.
*/
@Override
public void registerScope(Scope scope) throws APIManagementException {
String scopeKey = scope.getKey();
ScopeDTO scopeDTO = new ScopeDTO();
scopeDTO.setName(scopeKey);
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(",")));
}
try (Response response = scopeClient.registerScope(scopeDTO)) {
if (response.status() != HttpStatus.SC_CREATED) {
String responseString = readHttpResponseAsString(response.body());
throw new APIManagementException("Error occurred while registering scope: " + scopeKey + ". Error" + " Status: " + response.status() + " . Error Response: " + responseString);
}
} catch (KeyManagerClientException e) {
handleException("Cannot register scope : " + scopeKey, e);
}
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeDTO in project carbon-apimgt by wso2.
the class AMDefaultKeyManagerImpl method fromDTOToScope.
/**
* Get Scope object from ScopeDTO response received from authorization server.
*
* @param scopeDTO ScopeDTO response
* @return Scope model object
*/
private Scope fromDTOToScope(ScopeDTO scopeDTO) {
Scope scope = new Scope();
scope.setName(scopeDTO.getDisplayName());
scope.setKey(scopeDTO.getName());
scope.setDescription(scopeDTO.getDescription());
scope.setRoles((scopeDTO.getBindings() != null && !scopeDTO.getBindings().isEmpty()) ? String.join(",", scopeDTO.getBindings()) : StringUtils.EMPTY);
return scope;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.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.apimgt.rest.api.admin.v1.dto.ScopeDTO in project carbon-apimgt by wso2.
the class SystemScopesMappingUtil method createJsonObjectOfScopeMapping.
/**
* Extract scope and roles and create JSONObject
*
* @param body body of a Role Scope Mapping
* @return JSONObject role scope mapping data
*/
public static JSONObject createJsonObjectOfScopeMapping(ScopeListDTO body) throws APIManagementException {
JSONObject responseJson = new JSONObject();
JSONArray scopeJson = new JSONArray();
for (ScopeDTO scope : body.getList()) {
JSONObject scopeRoleJson = new JSONObject();
String roles = scope.getRoles().toString().replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "");
if (!roles.isEmpty()) {
scopeRoleJson.put("Name", scope.getName());
scopeRoleJson.put("Roles", roles);
scopeJson.put(scopeRoleJson);
}
}
responseJson.put("Scope", scopeJson);
return responseJson;
}
Aggregations