Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaminduR committed Sep 18, 2023
1 parent cd06bbb commit 3b209f1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.api.resource</artifactId>
<version>1.2.79-SNAPSHOT</version>
<version>1.2.81-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.api.resource</artifactId>
<version>1.2.79-SNAPSHOT</version>
<version>1.2.81-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants;
import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.ErrorMessage;
import org.wso2.carbon.identity.api.server.api.resource.v1.exception.APIResourceMgtEndpointException;
import org.wso2.carbon.identity.api.server.api.resource.v1.util.APIResourceMgtEndpointUtil;
import org.wso2.carbon.identity.api.server.common.ContextLoader;
import org.wso2.carbon.identity.api.server.common.error.APIError;
import org.wso2.carbon.identity.application.common.model.APIResource;
import org.wso2.carbon.identity.application.common.model.Scope;

Expand Down Expand Up @@ -105,9 +105,9 @@ public APIResourceResponse addAPIResourceWithResourceId(APIResourceCreationModel
/**
* Get API Resources.
*
* @param before - before parameter for cursor based pagination.
* @param after - after parameter for cursor based pagination.
* @param filter - filter parameter.
* @param before before parameter for cursor based pagination.
* @param after after parameter for cursor based pagination.
* @param filter filter parameter.
* @return Response with API Resources list.
*/
public APIResourceListResponse getAPIResources(String before, String after, String filter, Integer limit) {
Expand All @@ -132,7 +132,7 @@ public APIResourceListResponse getAPIResources(String before, String after, Stri
CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
List<APIResource> apiResources = apiResourceSearchResult.getAPIResources();

if (limit != 0 && CollectionUtils.isNotEmpty(apiResources)) {
if (CollectionUtils.isNotEmpty(apiResources)) {
boolean hasMoreItems = apiResources.size() > limit;
boolean needsReverse = StringUtils.isNotBlank(before);
boolean isFirstPage = (StringUtils.isBlank(before) && StringUtils.isBlank(after)) ||
Expand Down Expand Up @@ -454,9 +454,9 @@ private PaginationLink buildPaginationLink(String url, String rel) {
*
* @param limit Limit parameter.
* @return Validated limit.
* @throws APIResourceMgtEndpointException if the limit is invalid.
* @throws APIError if the limit is invalid.
*/
private static Integer validatedLimit(Integer limit) throws APIResourceMgtEndpointException {
private static Integer validatedLimit(Integer limit) throws APIError {

limit = limit == null ? DEFAULT_LIMIT : limit;
if (limit == 0 || limit < 0) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import org.wso2.carbon.identity.api.resource.mgt.APIResourceMgtException;
import org.wso2.carbon.identity.api.server.api.resource.common.APIResourceManagementServiceHolder;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCreationModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.Error;
import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants;
import org.wso2.carbon.identity.api.server.api.resource.v1.exception.APIResourceMgtEndpointException;
import org.wso2.carbon.identity.api.server.common.ContextLoader;
import org.wso2.carbon.identity.api.server.common.error.APIError;
import org.wso2.carbon.identity.api.server.common.error.ErrorDTO;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.oauth.IdentityOAuthAdminException;

Expand Down Expand Up @@ -69,7 +69,7 @@ public static void validateAPIResource(APIResourceCreationModel apiResource) {

public static void validateScopes(List<ScopeCreationModel> scopes) {

if (scopes == null || scopes.isEmpty()) {
if (scopes == null) {
return;
}
for (ScopeCreationModel scope : scopes) {
Expand All @@ -90,8 +90,10 @@ public static void validateScopes(List<ScopeCreationModel> scopes) {
try {
List<String> registeredOIDCScopes = APIResourceManagementServiceHolder.getOAuthAdminServiceImpl()
.getRegisteredOIDCScope(ContextLoader.getTenantDomainFromContext());
if (registeredOIDCScopes.contains(scope.getName())) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_RESTRICTED_OIDC_SCOPES);
if (registeredOIDCScopes != null) {
if (registeredOIDCScopes.contains(scope.getName())) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_RESTRICTED_OIDC_SCOPES);
}
}
} catch (IdentityOAuthAdminException e) {
throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_VALIDATE_SCOPES);
Expand All @@ -109,7 +111,7 @@ public static List<String> validateAndConvertToLowerCase(List<String> attributes

List<String> validatedAttributes = new ArrayList<>();

if (attributes == null || attributes.isEmpty()) {
if (attributes == null) {
return validatedAttributes;
}

Expand All @@ -123,28 +125,28 @@ public static List<String> validateAndConvertToLowerCase(List<String> attributes
return validatedAttributes;
}

public static APIResourceMgtEndpointException handleException(Response.Status status,
APIResourceMgtEndpointConstants.ErrorMessage error) {
public static APIError handleException(Response.Status status,
APIResourceMgtEndpointConstants.ErrorMessage error) {

return new APIResourceMgtEndpointException(status, getError(error.getCode(), error.getMessage(),
return new APIError(status, getError(error.getCode(), error.getMessage(),
error.getDescription()));
}

public static APIResourceMgtEndpointException handleException(Response.Status status,
APIResourceMgtEndpointConstants.ErrorMessage error,
String data) {
public static APIError handleException(Response.Status status,
APIResourceMgtEndpointConstants.ErrorMessage error,
String data) {

return new APIResourceMgtEndpointException(status, getError(error.getCode(), error.getMessage(),
return new APIError(status, getError(error.getCode(), error.getMessage(),
String.format(error.getDescription(), data)));
}

public static APIResourceMgtEndpointException handleException(Response.Status status, String errorCode,
String message, String description) {
public static APIError handleException(Response.Status status, String errorCode,
String message, String description) {

return new APIResourceMgtEndpointException(status, getError(errorCode, message, description));
return new APIError(status, getError(errorCode, message, description));
}

public static APIResourceMgtEndpointException handleAPIResourceMgtException(APIResourceMgtException e) {
public static APIError handleAPIResourceMgtException(APIResourceMgtException e) {

Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
if (e instanceof APIResourceMgtClientException) {
Expand Down Expand Up @@ -172,9 +174,9 @@ public static APIResourceMgtEndpointException handleAPIResourceMgtException(APIR
* @param errorDescription Error description.
* @return A generic error with the specified details.
*/
public static Error getError(String errorCode, String errorMessage, String errorDescription) {
public static ErrorDTO getError(String errorCode, String errorMessage, String errorDescription) {

Error error = new Error();
ErrorDTO error = new ErrorDTO();
error.setCode(errorCode);
error.setMessage(errorMessage);
error.setDescription(errorDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,8 @@ paths:
parameters:
- $ref: '#/components/parameters/apiResourceId'
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/APIResourceResponse'
204:
description: Not Content
400:
description: Bad Request
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>identity-api-server</artifactId>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<version>1.2.79-SNAPSHOT</version>
<version>1.2.81-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down

0 comments on commit 3b209f1

Please sign in to comment.