use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdScopesPost.
@Test
public void testApisApiIdScopesPost() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String apiId = UUID.randomUUID().toString();
Scope scope = new Scope("api_view", "api view");
Mockito.doNothing().when(apiPublisher).addScopeToTheApi(apiId, scope);
Response response = apisApiService.apisApiIdScopesPost(apiId, MappingUtil.scopeDto(scope, "role"), null, null, getRequest());
assertEquals(response.getStatus(), 201);
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdSwaggerPut.
/**
* Updates the swagger defnition of an API
*
* @param apiId UUID of API
* @param apiDefinition updated swagger defintion
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return Updated swagger definition
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdSwaggerPut(String apiId, String apiDefinition, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
String existingFingerprint = apisApiIdSwaggerGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
KeyMgtConfigurations keyManagerConfiguration = APIMConfigurationService.getInstance().getApimConfigurations().getKeyManagerConfigs();
Map<String, String> scopes = new APIDefinitionFromSwagger20().getScopesFromSecurityDefinition(apiDefinition);
for (String scopeName : scopes.keySet()) {
if (scopeName.contains(keyManagerConfiguration.getProductRestApiScopesKeyWord())) {
String message = "scope name couldn't have the restricted keyword " + keyManagerConfiguration.getProductRestApiScopesKeyWord();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(message, 900313L, message);
return Response.status(Response.Status.PRECONDITION_FAILED).entity(errorDTO).build();
}
}
apiPublisher.saveSwagger20Definition(apiId, apiDefinition);
String apiSwagger = apiPublisher.getApiSwaggerDefinition(apiId);
String newFingerprint = apisApiIdSwaggerGetFingerprint(apiId, null, null, request);
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(apiSwagger).build();
} catch (APIManagementException e) {
String errorMessage = "Error while put swagger for API : " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdScopesNameGet.
@Override
public Response apisApiIdScopesNameGet(String apiId, String name, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
Scope scope = apiPublisher.getScopeInformationOfApi(apiId, name);
KeyMgtConfigurations keyManagerConfiguration = APIMConfigurationService.getInstance().getApimConfigurations().getKeyManagerConfigs();
ScopeDTO scopeDTO = MappingUtil.scopeDto(scope, keyManagerConfiguration.getScopeBindingType());
return Response.ok().entity(scopeDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving swagger definition of API : " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.
the class DefaultScopeRegistrationImpl method updateScope.
@Override
public boolean updateScope(Scope scope) throws KeyManagementException {
ScopeInfo scopeInfo = getScopeInfo(scope);
Response response = scopeRegistrationServiceStub.updateScope(scopeInfo, scope.getName());
if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
return true;
} else {
throw new KeyManagementException("Scope update failed", ExceptionCodes.INTERNAL_ERROR);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.
the class WSO2ISScopeRegistrationImpl method getScopeInfoForUpdate.
private ScopeInfo getScopeInfoForUpdate(Scope scope) {
ScopeInfo scopeInfo = new ScopeInfo();
scopeInfo.setDisplayName(scope.getName());
scopeInfo.setDescription(scope.getDescription());
scopeInfo.setBindings(scope.getBindings());
return scopeInfo;
}
Aggregations