use of org.wso2.carbon.apimgt.core.auth.dto.SCIMGroup in project carbon-apimgt by wso2.
the class DefaultIdentityProviderImpl method getRoleId.
@Override
public String getRoleId(String roleName) throws IdentityProviderException {
Response roleResponse = scimServiceStub.searchGroups(FILTER_PREFIX_ROLE + roleName);
String roleId;
if (roleResponse == null) {
String errorMessage = "Error occurred while retrieving Id of role " + roleName + ". Error : Response is null.";
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
if (roleResponse.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
String responseBody = roleResponse.body().toString();
JsonParser parser = new JsonParser();
JsonObject parsedResponseBody = (JsonObject) parser.parse(responseBody);
JsonArray role = (JsonArray) parsedResponseBody.get(RESOURCES);
JsonObject scimGroup = (JsonObject) role.get(0);
roleId = scimGroup.get(ID).getAsString();
String message = "Id " + roleId + " of role " + scimGroup.get(GROUPNAME).getAsString() + " is successfully retrieved from SCIM endpoint.";
if (log.isDebugEnabled()) {
log.debug(message);
}
} else {
String errorMessage = "Error occurred while retrieving Id of role " + roleName + ". Error : " + getErrorMessage(roleResponse);
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
return roleId;
}
use of org.wso2.carbon.apimgt.core.auth.dto.SCIMGroup in project carbon-apimgt by wso2.
the class DefaultIdentityProviderImpl method getRoleName.
@Override
public String getRoleName(String roleId) throws IdentityProviderException {
Response response = scimServiceStub.getGroup(roleId);
if (response == null) {
String errorMessage = "Error occurred while retrieving name of role with Id " + roleId + ". Error : Response is null.";
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
String displayName;
try {
if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
SCIMGroup scimGroup = (SCIMGroup) new GsonDecoder().decode(response, SCIMGroup.class);
if (scimGroup != null) {
displayName = scimGroup.getDisplayName();
String message = "Display name of role with Id " + roleId + " is successfully retrieved as " + displayName;
if (log.isDebugEnabled()) {
log.debug(message);
}
} else {
String errorMessage = "Error occurred while retrieving role name with role Id " + roleId + " from SCIM endpoint. " + "Response body is null or empty.";
log.error(errorMessage);
throw new IdentityProviderException("Error occurred while retrieving role name with role Id " + roleId + " from SCIM endpoint. " + "Response body is null or empty.", ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
} else {
String errorMessage = "Error occurred while retrieving name of role with Id " + roleId + ". Error : " + getErrorMessage(response);
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
} catch (IOException e) {
String errorMessage = "Error occurred while parsing response from SCIM endpoint.";
log.error(errorMessage);
throw new IdentityProviderException("Error occurred while parsing response from SCIM endpoint for ", e, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
return displayName;
}
Aggregations