use of org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration 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.carbon.apimgt.api.model.KeyManagerConfiguration 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.carbon.apimgt.api.model.KeyManagerConfiguration in project carbon-apimgt by wso2.
the class ScopeRegistrationServiceStubFactoryTest method testGetScopeRegistrationForWso2Is.
@Test
public void testGetScopeRegistrationForWso2Is() throws Exception {
KeyMgtConfigurations keyManagerConfiguration = new KeyMgtConfigurations();
keyManagerConfiguration.setKeyManagerImplClass(WSO2ISKeyManagerImpl.class.getCanonicalName());
ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
APIMConfigurations apimConfigurations = new APIMConfigurations();
apimConfigurations.setKeyManagerConfigs(keyManagerConfiguration);
Mockito.when(configProvider.getConfigurationObject(APIMConfigurations.class)).thenReturn(apimConfigurations);
ServiceReferenceHolder.getInstance().setConfigProvider(configProvider);
ScopeRegistration scopeRegistration = ScopeRegistrationServiceStubFactory.getScopeRegistration();
Assert.assertTrue(scopeRegistration instanceof WSO2ISScopeRegistrationImpl);
}
use of org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration in project carbon-apimgt by wso2.
the class AbstractKeyManagerTestCase method testCanHandleTokenWithConfigurationJWTAndOpaueDisableOne.
@Test
public void testCanHandleTokenWithConfigurationJWTAndOpaueDisableOne() throws APIManagementException {
KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
keyManagerConfiguration.addParameter(APIConstants.KeyManager.TOKEN_FORMAT_STRING, "[{\"enable\": true,\"type\": \"JWT\",\"value\": {\"body\": {\"iss\": \"https://localhost:9443\"}}}," + "{\"enable\": false,\"type\": \"REFERENCE\",\"value\": " + "\"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0" + "-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}\"}]");
KeyManager keyManager = new ModelKeyManagerForTest();
keyManager.loadConfiguration(keyManagerConfiguration);
assertTrue(keyManager.canHandleToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" + ".eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo5NDQzIiwiaWF0IjoxNTkwMTM0NzIyLCJleHAiOjE2MjE2NzA3MjAsImF1ZC" + "I6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJFbWFpbCI6ImJlZUBleGFtcGxlLmNvb" + "SJ9.HIxL7_WqeLPkxYdROAwRyL0YEY1YNJRfLghsaHEc7C4"));
assertFalse(keyManager.canHandleToken(UUID.randomUUID().toString()));
}
use of org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration in project carbon-apimgt by wso2.
the class AbstractKeyManagerTestCase method testCanHandleTokenWithConfigurationJWTMultipleClaim.
@Test
public void testCanHandleTokenWithConfigurationJWTMultipleClaim() throws APIManagementException {
KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
keyManagerConfiguration.addParameter(APIConstants.KeyManager.TOKEN_FORMAT_STRING, "[{\"enable\": true,\"type\": \"JWT\",\"value\": {\"body\": {\"iss\": \"https://localhost:9443\"," + "\"domain\": \"abc.com\"}}}]");
KeyManager keyManager = new ModelKeyManagerForTest();
keyManager.loadConfiguration(keyManagerConfiguration);
assertTrue(keyManager.canHandleToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo5NDQ0IiwiaWF0IjoxN" + "TkwMTM0NzIyLCJleHAiOjE2MjE2NzA3MjAsImF1ZCI6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRAZXhhbX" + "BsZS5jb20iLCJkb21haW4iOiJhYmMuY29tIn0.pHI2MUhvdGjcOj2yJ-05cHMwtx5kanMhO71m0wFhjic"));
assertFalse(keyManager.canHandleToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" + ".eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo5NDQzIiwiaWF0IjoxNTkwMTM0NzIyLCJleHAiOjE2MjE2NzA3MjAsImF1ZC" + "I6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJFbWFpbCI6ImJlZUBleGFtcGxlLmNvb" + "SJ9.HIxL7_WqeLPkxYdROAwRyL0YEY1YNJRfLghsaHEc7C4"));
}
Aggregations