Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaminduR committed Aug 31, 2023
1 parent e621aa9 commit 5c51c9e
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<parent>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.api.resource</artifactId>
<version>1.2.68-SNAPSHOT</version>
<version>1.2.71-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.server.api.resource.common</artifactId>
<version>1.2.68-SNAPSHOT</version>
<version>1.2.71-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ public Class<?> getObjectType() {
protected APIResourceManager createInstance() throws Exception {

if (this.apiResourceManager == null) {
APIResourceManager taskOperationService = (APIResourceManager) PrivilegedCarbonContext.
apiResourceManager = (APIResourceManager) PrivilegedCarbonContext.
getThreadLocalCarbonContext().getOSGiService(APIResourceManager.class, null);
if (taskOperationService == null) {
if (apiResourceManager == null) {
throw new Exception("Unable to retrieve APIResourceManager service.");
}
this.apiResourceManager = taskOperationService;
}
return this.apiResourceManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ public Class<?> getObjectType() {
protected OAuthAdminServiceImpl createInstance() throws Exception {

if (this.oauthAdminService == null) {
OAuthAdminServiceImpl oauthAdminService = (OAuthAdminServiceImpl) PrivilegedCarbonContext
oauthAdminService = (OAuthAdminServiceImpl) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(OAuthAdminServiceImpl.class, null);

if (oauthAdminService == null) {
throw new Exception("Unable to retrieve OAuthAdminServiceImpl service.");
}
this.oauthAdminService = oauthAdminService;
}
return this.oauthAdminService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
<parent>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.api.resource</artifactId>
<version>1.2.68-SNAPSHOT</version>
<version>1.2.71-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<name>WSO2 Identity Server - Applications Rest API</name>
<description>WSO2 Identity Server - API Resource Rest API</description>
<artifactId>org.wso2.carbon.identity.api.server.api.resource.v1</artifactId>
<version>1.2.68-SNAPSHOT</version>
<version>1.2.71-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
Expand Down Expand Up @@ -110,7 +110,10 @@
<dependency>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.api.resource.common</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.application.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,14 @@
package org.wso2.carbon.identity.api.server.api.resource.v1;

import org.springframework.beans.factory.annotation.Autowired;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import java.io.InputStream;
import java.util.List;

import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCreationModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceListResponse;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourcePatchModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceResponse;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceSearchPayload;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceSearchResult;
import org.wso2.carbon.identity.api.server.api.resource.v1.Error;
import java.util.List;
import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourcesApiService;

import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import io.swagger.annotations.*;

import javax.validation.constraints.*;

@Path("/api-resources")
@Api(description = "The api-resources API")

Expand Down Expand Up @@ -212,7 +196,7 @@ public Response apiResourcesApiResourceIdScopesPut(@ApiParam(value = "ID of the
})
public Response apiResourcesApiResourceIdScopesScopeIdDelete(@ApiParam(value = "ID of the API Resource.",required=true) @PathParam("apiResourceId") String apiResourceId, @ApiParam(value = "ID of the Scope.",required=true) @PathParam("scopeId") String scopeId) {

return delegate.apiResourcesApiResourceIdScopesScopeIdDelete(apiResourceId, scopeId );
return delegate.apiResourcesApiResourceIdScopesScopeNameDelete(apiResourceId, scopeId );
}

@Valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,8 @@

package org.wso2.carbon.identity.api.server.api.resource.v1;

import org.wso2.carbon.identity.api.server.api.resource.v1.*;
import org.wso2.carbon.identity.api.server.api.resource.v1.*;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import java.io.InputStream;
import java.util.List;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCreationModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceListResponse;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourcePatchModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceResponse;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceSearchPayload;
import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceSearchResult;
import org.wso2.carbon.identity.api.server.api.resource.v1.Error;
import java.util.List;
import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel;
import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel;

import javax.ws.rs.core.Response;


Expand All @@ -51,7 +37,7 @@ public interface ApiResourcesApiService {

public Response apiResourcesApiResourceIdScopesPut(String apiResourceId, List<ScopeCreationModel> scopeCreationModel);

public Response apiResourcesApiResourceIdScopesScopeIdDelete(String apiResourceId, String scopeId);
public Response apiResourcesApiResourceIdScopesScopeNameDelete(String apiResourceId, String scopeName);

public Response getAPIResources(String before, String after, String filter, Integer limit, String requiredAttributes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
*/
public class APIResourceMgtEndpointConstants {

private APIResourceMgtEndpointConstants() {
}

public static final String API_RESOURCE_TYPE = "BUSINESS";
public static final String API_RESOURCE_MANAGEMENT_PREFIX = "API-RESOURCE-";
public static final String API_RESOURCE_PATH_COMPONENT = "/api-resources";
private static final List<String> allowedAttributeList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ public APIResource getAPIResourceById(String apiResourceID) {
APIResource apiResource = APIResourceManagementServiceHolder.getApiResourceManager()
.getAPIResourceById(apiResourceID, ContextLoader.getTenantDomainFromContext());
if (apiResource == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("API Resource not found for ID: " + apiResourceID);
}
throw APIResourceMgtEndpointUtil.handleException(Response.Status.NOT_FOUND,
APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_API_RESOURCE_NOT_FOUND, apiResourceID);
}
Expand Down Expand Up @@ -267,9 +264,6 @@ public List<Scope> getScopesByAPIId(String apiResourceId) {
APIResource apiResource = APIResourceManagementServiceHolder.getApiResourceManager()
.getAPIResourceById(apiResourceId, ContextLoader.getTenantDomainFromContext());
if (apiResource == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("API Resource not found for ID: " + apiResourceId);
}
throw APIResourceMgtEndpointUtil.handleException(Response.Status.NOT_FOUND,
APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_API_RESOURCE_NOT_FOUND, apiResourceId);
}
Expand All @@ -291,9 +285,6 @@ public void putScopesByAPIId(String apiResourceId, List<ScopeCreationModel> scop
APIResource apiResource = APIResourceManagementServiceHolder.getApiResourceManager()
.getAPIResourceById(apiResourceId, ContextLoader.getTenantDomainFromContext());
if (apiResource == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("API Resource not found for ID: " + apiResourceId);
}
throw APIResourceMgtEndpointUtil.handleException(Response.Status.NOT_FOUND,
APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_API_RESOURCE_NOT_FOUND, apiResourceId);
}
Expand All @@ -309,16 +300,16 @@ public void putScopesByAPIId(String apiResourceId, List<ScopeCreationModel> scop
* Delete scopes by the scope ID.
*
* @param apiResourceId API Resource ID.
* @param scopeId Scope ID.
* @param scopeName Scope Name.
*/
public void deleteScopeByScopeId(String apiResourceId, String scopeId) {
public void deleteScopeByScopeName(String apiResourceId, String scopeName) {

try {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting scope with ID: " + scopeId + " of API Resource ID: " + apiResourceId);
LOG.debug("Deleting scope with ID: " + scopeName + " of API Resource ID: " + apiResourceId);
}
APIResourceManagementServiceHolder.getApiResourceManager()
.deleteAPIScopeByScopeId(apiResourceId, scopeId, ContextLoader.getTenantDomainFromContext());
.deleteAPIScopeByScopeName(apiResourceId, scopeName, ContextLoader.getTenantDomainFromContext());
} catch (APIResourceMgtException e) {
throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e);
}
Expand Down Expand Up @@ -408,6 +399,7 @@ private APIResource createAPIResource(APIResourceCreationModel apIResourceCreati
apiResource.setDescription(apIResourceCreationModel.getDescription());
apiResource.setScopes(createScopes(apIResourceCreationModel.getScopes()));
apiResource.setRequiresAuthorization(apIResourceCreationModel.getRequiresAuthorization());
apiResource.setType(APIResourceMgtEndpointConstants.API_RESOURCE_TYPE);
APIResourceMgtEndpointUtil.validateAPIResource(apiResource);
return apiResource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public Response apiResourcesApiResourceIdScopesPut(String apiResourceId,
}

@Override
public Response apiResourcesApiResourceIdScopesScopeIdDelete(String apiResourceId, String scopeId) {
public Response apiResourcesApiResourceIdScopesScopeNameDelete(String apiResourceId, String scopeName) {

serverAPIResourceManagementService.deleteScopeByScopeId(apiResourceId, scopeId);
serverAPIResourceManagementService.deleteScopeByScopeName(apiResourceId, scopeName);
return Response.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ public static void validateScopes(List<Scope> scopes) {
* @return List of validated attributes.
*/
public static List<String> validateAndConvertToLowerCase(List<String> attributes) {

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

if (attributes != null && !attributes.isEmpty()) {
for (String attribute : attributes) {
String lowerCaseAttribute = attribute.toLowerCase(Locale.ENGLISH);
if (!APIResourceMgtEndpointConstants.ALLOWED_SEARCH_ATTRIBUTES.contains(lowerCaseAttribute)) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_INVALID_SEARCH_ATTRIBUTE);
} else {
validatedAttributes.add(lowerCaseAttribute);
}
if (attributes == null || attributes.isEmpty()) {
return validatedAttributes;
}

for (String attribute : attributes) {
String lowerCaseAttribute = attribute.toLowerCase(Locale.ENGLISH);
if (!APIResourceMgtEndpointConstants.ALLOWED_SEARCH_ATTRIBUTES.contains(lowerCaseAttribute)) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_INVALID_SEARCH_ATTRIBUTE);
}
validatedAttributes.add(lowerCaseAttribute);
}
return validatedAttributes;
}
Expand Down
Loading

0 comments on commit 5c51c9e

Please sign in to comment.