use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RoleAliasListDTO in project carbon-apimgt by wso2.
the class SystemScopesApiServiceImpl method systemScopesRoleAliasesPut.
@Override
public Response systemScopesRoleAliasesPut(RoleAliasListDTO body, MessageContext messageContext) throws APIManagementException {
RoleAliasListDTO roleAliasListDTO = new RoleAliasListDTO();
JSONObject newRoleMappingJson = SystemScopesMappingUtil.createJsonObjectOfRoleMapping(body);
String username = RestApiCommonUtil.getLoggedInUsername();
String tenantDomain = MultitenantUtils.getTenantDomain(username);
APIUtil.updateTenantConfRoleAliasMapping(newRoleMappingJson, username);
JSONObject tenantConfig = APIUtil.getTenantConfig(tenantDomain);
JSONObject roleMapping = (JSONObject) tenantConfig.get(APIConstants.REST_API_ROLE_MAPPINGS_CONFIG);
if (roleMapping != null) {
roleAliasListDTO = SystemScopesMappingUtil.fromRoleAliasListToRoleAliasListDTO(SystemScopesMappingUtil.createMapOfRoleMapping((roleMapping)));
}
return Response.ok().entity(roleAliasListDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RoleAliasListDTO in project carbon-apimgt by wso2.
the class SystemScopesApiServiceImpl method systemScopesRoleAliasesGet.
@Override
public Response systemScopesRoleAliasesGet(MessageContext messageContext) throws APIManagementException {
String tenantDomain = MultitenantUtils.getTenantDomain(RestApiCommonUtil.getLoggedInUsername());
JSONObject tenantConfig = APIUtil.getTenantConfig(tenantDomain);
JSONObject roleMapping = (JSONObject) tenantConfig.get(APIConstants.REST_API_ROLE_MAPPINGS_CONFIG);
RoleAliasListDTO roleAliasListDTO = new RoleAliasListDTO();
if (roleMapping != null) {
roleAliasListDTO = SystemScopesMappingUtil.fromRoleAliasListToRoleAliasListDTO(SystemScopesMappingUtil.createMapOfRoleMapping(roleMapping));
}
return Response.ok().entity(roleAliasListDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RoleAliasListDTO in project carbon-apimgt by wso2.
the class SystemScopesMappingUtil method fromRoleAliasListToRoleAliasListDTO.
/**
* Convert list of role alias mapping to RoleAliasListDTO
*
* @param roleMapping Map of a Role Alias Mapping
* @return RoleAliasListDTO list containing role scope mapping data
*/
public static RoleAliasListDTO fromRoleAliasListToRoleAliasListDTO(Map<String, List<String>> roleMapping) {
RoleAliasListDTO roleAliasListDTO = new RoleAliasListDTO();
roleAliasListDTO.setCount(roleMapping.size());
roleAliasListDTO.setList(fromRoleAliasObjectToRoleAliasDTOList(roleMapping));
return roleAliasListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RoleAliasListDTO in project carbon-apimgt by wso2.
the class SystemScopesMappingUtil method createJsonObjectOfRoleMapping.
/**
* Extract roles and aliases and create JSONObject
*
* @param body RoleAliasListDTO as request body
* @return JSONObject role-alias data
*/
public static JSONObject createJsonObjectOfRoleMapping(RoleAliasListDTO body) {
JSONObject roleJson = new JSONObject();
for (RoleAliasDTO roleAlias : body.getList()) {
String aliases = roleAlias.getAliases().toString().replaceAll("\\[", "").replaceAll("\\]", "");
roleJson.put(roleAlias.getRole(), aliases);
}
return roleJson;
}
Aggregations