Search in sources :

Example 1 with SCIMGroup

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;
}
Also used : Response(feign.Response) JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) IdentityProviderException(org.wso2.carbon.apimgt.core.exception.IdentityProviderException) JsonParser(com.google.gson.JsonParser)

Example 2 with SCIMGroup

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;
}
Also used : Response(feign.Response) SCIMGroup(org.wso2.carbon.apimgt.core.auth.dto.SCIMGroup) GsonDecoder(feign.gson.GsonDecoder) IOException(java.io.IOException) IdentityProviderException(org.wso2.carbon.apimgt.core.exception.IdentityProviderException)

Aggregations

Response (feign.Response)2 IdentityProviderException (org.wso2.carbon.apimgt.core.exception.IdentityProviderException)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 GsonDecoder (feign.gson.GsonDecoder)1 IOException (java.io.IOException)1 SCIMGroup (org.wso2.carbon.apimgt.core.auth.dto.SCIMGroup)1