Java Code Examples for org.wso2.carbon.apimgt.api.model.API#setTransports()
The following examples show how to use
org.wso2.carbon.apimgt.api.model.API#setTransports() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportConfigContextTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testTransportConfigContext() throws Exception { API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0")); api.setStatus(APIConstants.CREATED); api.setContextTemplate("/"); api.setTransports(Constants.TRANSPORT_HTTP); ConfigContext configcontext = new APIConfigContext(api); TransportConfigContext transportConfigContext = new TransportConfigContext(configcontext, api); transportConfigContext.validate(); Assert.assertTrue(Constants.TRANSPORT_HTTP.equalsIgnoreCase (transportConfigContext.getContext().get("transport").toString())); api.setTransports(Constants.TRANSPORT_HTTP + "," + Constants.TRANSPORT_HTTPS); configcontext = new APIConfigContext(api); transportConfigContext = new TransportConfigContext(configcontext, api); Assert.assertTrue(StringUtils.EMPTY.equalsIgnoreCase (transportConfigContext.getContext().get("transport").toString())); }
Example 2
Source File: SecurityConfigContextTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testSecurityConfigContext() throws Exception { API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0")); api.setStatus(APIConstants.CREATED); api.setContextTemplate("/"); api.setTransports(Constants.TRANSPORT_HTTP); api.setEndpointUTUsername("admin"); api.setEndpointUTPassword("admin123"); api.setEndpointSecured(true); api.setEndpointAuthDigest(true); ConfigContext configcontext = new APIConfigContext(api); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_SECUREVAULT_ENABLE)).thenReturn("true"); SecurityConfigContext securityConfigContext = new SecurityConfigContextWrapper(configcontext, api, apiManagerConfiguration); securityConfigContext.validate(); VelocityContext velocityContext = securityConfigContext.getContext(); Assert.assertNotNull(velocityContext.get("endpoint_security")); Map<String, EndpointSecurityModel> endpointSecurityModelMap = (Map<String, EndpointSecurityModel>) velocityContext.get("endpoint_security"); for (Map.Entry<String, EndpointSecurityModel> endpointSecurityModelEntry : endpointSecurityModelMap .entrySet()) { Assert.assertTrue("Property isEndpointSecured cannot be false.", endpointSecurityModelEntry.getValue().isEnabled()); Assert.assertTrue("Property isEndpointAuthDigest cannot be false.", endpointSecurityModelEntry.getValue().getType().contains("digest")); Assert.assertTrue("Property username does not match.", "admin".equals(endpointSecurityModelEntry.getValue().getUsername())); Assert.assertTrue("Property base64unpw does not match. ", new String(Base64.encodeBase64("admin:admin123".getBytes())) .equalsIgnoreCase(endpointSecurityModelEntry.getValue().getBase64EncodedPassword())); Assert.assertTrue("Property securevault_alias does not match.", "admin--TestAPI1.0.0".equalsIgnoreCase(endpointSecurityModelEntry.getValue().getAlias())); } Assert.assertTrue("Property isSecureVaultEnabled cannot be false. ", velocityContext.get("isSecureVaultEnabled").equals(true)); }
Example 3
Source File: SecurityConfigContextTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testSecurityConfigContextPerEndpointProductionType() throws Exception { String json = "{\"endpoint_security\":{\n" + " \"production\":{\n" + " \"enabled\":true,\n" + " \"type\":\"BASIC\",\n" + " \"username\":\"admin\",\n" + " \"password\":\"admin123#QA\"\n" + " }\n" + " }\n" + "}"; API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0")); api.setStatus(APIConstants.CREATED); api.setContextTemplate("/"); api.setTransports(Constants.TRANSPORT_HTTP); api.setEndpointConfig(json); ConfigContext configcontext = new APIConfigContext(api); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_SECUREVAULT_ENABLE)).thenReturn("true"); SecurityConfigContext securityConfigContext = new SecurityConfigContextWrapper(configcontext, api, apiManagerConfiguration); securityConfigContext.validate(); VelocityContext velocityContext = securityConfigContext.getContext(); Assert.assertNotNull(velocityContext.get("endpoint_security")); Map<String, EndpointSecurityModel> endpointSecurityModelMap = (Map<String, EndpointSecurityModel>) velocityContext.get("endpoint_security"); EndpointSecurityModel production = endpointSecurityModelMap.get("production"); Assert.assertTrue("Property enabled cannot be false.", production.isEnabled()); Assert.assertTrue("Property type cannot be other.", production.getType().equalsIgnoreCase("basic")); Assert.assertTrue("Property username does not match.", "admin".equals(production.getUsername())); Assert.assertTrue("Property base64value does not match. ", new String(Base64.encodeBase64("admin:admin123#QA".getBytes())) .equalsIgnoreCase(production.getBase64EncodedPassword())); Assert.assertTrue("Property securevault_alias does not match.", "admin--TestAPI1.0.0--production".equalsIgnoreCase(production.getAlias())); Assert.assertTrue("Property isSecureVaultEnabled cannot be false. ", velocityContext.get("isSecureVaultEnabled").equals(true)); EndpointSecurityModel sandbox = endpointSecurityModelMap.get("sandbox"); Assert.assertFalse("Property enabled cannot be true.", sandbox.isEnabled()); }
Example 4
Source File: SecurityConfigContextTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testSecurityConfigContextPerEndpointSandbox() throws Exception { String json = "{\"endpoint_security\":{\n" + " \"sandbox\":{\n" + " \"enabled\":true,\n" + " \"type\":\"DIGEST\",\n" + " \"username\":\"admin\",\n" + " \"password\":\"admin123#QA\"\n" + " }\n" + " }\n" + "}"; API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0")); api.setStatus(APIConstants.CREATED); api.setContextTemplate("/"); api.setTransports(Constants.TRANSPORT_HTTP); api.setEndpointConfig(json); ConfigContext configcontext = new APIConfigContext(api); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_SECUREVAULT_ENABLE)).thenReturn("true"); SecurityConfigContext securityConfigContext = new SecurityConfigContextWrapper(configcontext, api, apiManagerConfiguration); securityConfigContext.validate(); VelocityContext velocityContext = securityConfigContext.getContext(); Assert.assertNotNull(velocityContext.get("endpoint_security")); Map<String, EndpointSecurityModel> endpointSecurityModelMap = (Map<String, EndpointSecurityModel>) velocityContext.get("endpoint_security"); EndpointSecurityModel sandbox = endpointSecurityModelMap.get("sandbox"); Assert.assertTrue("Property enabled cannot be false.", sandbox.isEnabled()); Assert.assertTrue("Property type cannot be other.", sandbox.getType().equalsIgnoreCase("digest")); Assert.assertTrue("Property username does not match.", "admin".equals(sandbox.getUsername())); Assert.assertTrue("Property base64value does not match. ", new String(Base64.encodeBase64("admin:admin123#QA".getBytes())) .equalsIgnoreCase(sandbox.getBase64EncodedPassword())); Assert.assertTrue("Property securevault_alias does not match.", "admin--TestAPI1.0.0--sandbox".equalsIgnoreCase(sandbox.getAlias())); Assert.assertTrue("Property isSecureVaultEnabled cannot be false. ", velocityContext.get("isSecureVaultEnabled").equals(true)); EndpointSecurityModel production = endpointSecurityModelMap.get("production"); Assert.assertFalse("Property enabled cannot be true.", production.isEnabled()); }
Example 5
Source File: OAS2Parser.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * This method returns api that is attached with api extensions related to micro-gw * * @param apiDefinition String * @param api API * @param isBasepathExtractedFromSwagger boolean * @return API */ @Override public API setExtensionsToAPI(String apiDefinition, API api, boolean isBasepathExtractedFromSwagger) throws APIManagementException { Swagger swagger = getSwagger(apiDefinition); Map<String, Object> extensions = swagger.getVendorExtensions(); if (extensions == null) { return api; } //Setup Custom auth header for API String authHeader = OASParserUtil.getAuthorizationHeaderFromSwagger(extensions); if (StringUtils.isNotBlank(authHeader)) { api.setAuthorizationHeader(authHeader); } //Setup mutualSSL configuration String mutualSSL = OASParserUtil.getMutualSSLEnabledFromSwagger(extensions); if (StringUtils.isNotBlank(mutualSSL)) { String securityList = api.getApiSecurity(); if (StringUtils.isBlank(securityList)) { securityList = APIConstants.DEFAULT_API_SECURITY_OAUTH2; } if (APIConstants.OPTIONAL.equals(mutualSSL)) { securityList = securityList + "," + APIConstants.API_SECURITY_MUTUAL_SSL; } else if (APIConstants.MANDATORY.equals(mutualSSL)) { securityList = securityList + "," + APIConstants.API_SECURITY_MUTUAL_SSL_MANDATORY; } api.setApiSecurity(securityList); } //Setup CORSConfigurations CORSConfiguration corsConfiguration = OASParserUtil.getCorsConfigFromSwagger(extensions); if (corsConfiguration != null) { api.setCorsConfiguration(corsConfiguration); } //Setup Response cache enabling boolean responseCacheEnable = OASParserUtil.getResponseCacheFromSwagger(extensions); if (responseCacheEnable) { api.setResponseCache(APIConstants.ENABLED); } //Setup cache timeOut int cacheTimeOut = OASParserUtil.getCacheTimeOutFromSwagger(extensions); if (cacheTimeOut != 0) { api.setCacheTimeout(cacheTimeOut); } //Setup Transports String transports = OASParserUtil.getTransportsFromSwagger(extensions); if (StringUtils.isNotBlank(transports)) { api.setTransports(transports); } //Setup Throttlingtiers String throttleTier = OASParserUtil.getThrottleTierFromSwagger(extensions); if (StringUtils.isNotBlank(throttleTier)) { api.setApiLevelPolicy(throttleTier); } //Setup Basepath String basePath = OASParserUtil.getBasePathFromSwagger(extensions); if (StringUtils.isNotBlank(basePath) && isBasepathExtractedFromSwagger) { basePath = basePath.replace("{version}", api.getId().getVersion()); api.setContextTemplate(basePath); api.setContext(basePath); } return api; }
Example 6
Source File: OAS3Parser.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * This method returns api that is attached with api extensions related to micro-gw * * @param apiDefinition String * @param api API * @param isBasepathExtractedFromSwagger boolean * @return API */ @Override public API setExtensionsToAPI(String apiDefinition, API api, boolean isBasepathExtractedFromSwagger) throws APIManagementException { OpenAPI openAPI = getOpenAPI(apiDefinition); Map<String, Object> extensions = openAPI.getExtensions(); if (extensions == null) { return api; } //Setup Custom auth header for API String authHeader = OASParserUtil.getAuthorizationHeaderFromSwagger(extensions); if (StringUtils.isNotBlank(authHeader)) { api.setAuthorizationHeader(authHeader); } //Setup mutualSSL configuration String mutualSSL = OASParserUtil.getMutualSSLEnabledFromSwagger(extensions); if (StringUtils.isNotBlank(mutualSSL)) { String securityList = api.getApiSecurity(); if (StringUtils.isBlank(securityList)) { securityList = APIConstants.DEFAULT_API_SECURITY_OAUTH2; } if (APIConstants.OPTIONAL.equals(mutualSSL)) { securityList = securityList + "," + APIConstants.API_SECURITY_MUTUAL_SSL; } else if (APIConstants.MANDATORY.equals(mutualSSL)) { securityList = securityList + "," + APIConstants.API_SECURITY_MUTUAL_SSL_MANDATORY; } api.setApiSecurity(securityList); } //Setup CORSConfigurations CORSConfiguration corsConfiguration = OASParserUtil.getCorsConfigFromSwagger(extensions); if (corsConfiguration != null) { api.setCorsConfiguration(corsConfiguration); } //Setup Response cache enabling boolean responseCacheEnable = OASParserUtil.getResponseCacheFromSwagger(extensions); if (responseCacheEnable) { api.setResponseCache(APIConstants.ENABLED); } //Setup cache timeOut int cacheTimeOut = OASParserUtil.getCacheTimeOutFromSwagger(extensions); if (cacheTimeOut != 0) { api.setCacheTimeout(cacheTimeOut); } //Setup Transports String transports = OASParserUtil.getTransportsFromSwagger(extensions); if (StringUtils.isNotBlank(transports)) { api.setTransports(transports); } //Setup Throttlingtiers String throttleTier = OASParserUtil.getThrottleTierFromSwagger(extensions); if (StringUtils.isNotBlank(throttleTier)) { api.setApiLevelPolicy(throttleTier); } //Setup Basepath String basePath = OASParserUtil.getBasePathFromSwagger(extensions); if (StringUtils.isNotBlank(basePath) && isBasepathExtractedFromSwagger) { basePath = basePath.replace("{version}", api.getId().getVersion()); api.setContextTemplate(basePath); api.setContext(basePath); } return api; }
Example 7
Source File: APIMWSDLReaderTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
public static API getAPIForTesting() { API api = new API(new APIIdentifier("admin", "api1", "1.0.0")); api.setTransports("https"); api.setContext("/abc"); return api; }
Example 8
Source File: SecurityConfigContextTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testSecurityConfigContextPerEndpointBothType() throws Exception { String json = "{\"endpoint_security\":{\n" + " \"production\":{\n" + " \"enabled\":true,\n" + " \"type\":\"BASIC\",\n" + " \"username\":\"admin\",\n" + " \"password\":\"admin123#QA\"\n" + " },\n" + " \"sandbox\":{\n" + " \"enabled\":true,\n" + " \"type\":\"DIGEST\",\n" + " \"username\":\"admin\",\n" + " \"password\":\"admin123\"\n" + " }\n" + " }\n" + "}"; API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0")); api.setStatus(APIConstants.CREATED); api.setContextTemplate("/"); api.setTransports(Constants.TRANSPORT_HTTP); api.setEndpointConfig(json); ConfigContext configcontext = new APIConfigContext(api); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_SECUREVAULT_ENABLE)).thenReturn("true"); SecurityConfigContext securityConfigContext = new SecurityConfigContextWrapper(configcontext, api, apiManagerConfiguration); securityConfigContext.validate(); VelocityContext velocityContext = securityConfigContext.getContext(); Assert.assertNotNull(velocityContext.get("endpoint_security")); Map<String, EndpointSecurityModel> endpointSecurityModelMap = (Map<String, EndpointSecurityModel>) velocityContext.get("endpoint_security"); EndpointSecurityModel production = endpointSecurityModelMap.get("production"); Assert.assertTrue("Property enabled cannot be false.", production.isEnabled()); Assert.assertTrue("Property type cannot be other.", production.getType().equalsIgnoreCase("basic")); Assert.assertTrue("Property username does not match.", "admin".equals(production.getUsername())); Assert.assertTrue("Property base64value does not match. ", new String(Base64.encodeBase64("admin:admin123#QA".getBytes())) .equalsIgnoreCase(production.getBase64EncodedPassword())); Assert.assertTrue("Property securevault_alias does not match.", "admin--TestAPI1.0.0--production".equalsIgnoreCase(production.getAlias())); EndpointSecurityModel sandbox = endpointSecurityModelMap.get("sandbox"); Assert.assertTrue("Property enabled cannot be false.", sandbox.isEnabled()); Assert.assertTrue("Property type cannot be other.", sandbox.getType().equalsIgnoreCase("digest")); Assert.assertTrue("Property username does not match.", "admin".equals(sandbox.getUsername())); Assert.assertTrue("Property base64value does not match. ", new String(Base64.encodeBase64("admin:admin123".getBytes())) .equalsIgnoreCase(sandbox.getBase64EncodedPassword())); Assert.assertTrue("Property securevault_alias does not match.", "admin--TestAPI1.0.0--sandbox".equalsIgnoreCase(sandbox.getAlias())); Assert.assertTrue("Property isSecureVaultEnabled cannot be false. ", velocityContext.get("isSecureVaultEnabled").equals(true)); }
Example 9
Source File: SecurityConfigContextTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testSecurityConfigContextIgnoringEndpointConfig() throws Exception { String json = "{\"endpoint_security\":{\n" + " \"sandbox\":{\n" + " \"enabled\":true,\n" + " \"type\":\"DIGEST\",\n" + " \"username\":\"admin\",\n" + " \"password\":\"admin123#QA\"\n" + " }\n" + " }\n" + "}"; API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0")); api.setStatus(APIConstants.CREATED); api.setContextTemplate("/"); api.setTransports(Constants.TRANSPORT_HTTP); api.setEndpointConfig(json); api.setEndpointUTUsername("admin"); api.setEndpointUTPassword("admin123"); api.setEndpointSecured(true); api.setEndpointAuthDigest(true); ConfigContext configcontext = new APIConfigContext(api); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_SECUREVAULT_ENABLE)).thenReturn("true"); SecurityConfigContext securityConfigContext = new SecurityConfigContextWrapper(configcontext, api, apiManagerConfiguration); securityConfigContext.validate(); VelocityContext velocityContext = securityConfigContext.getContext(); Assert.assertNotNull(velocityContext.get("endpoint_security")); Map<String, EndpointSecurityModel> endpointSecurityModelMap = (Map<String, EndpointSecurityModel>) velocityContext.get("endpoint_security"); for (Map.Entry<String, EndpointSecurityModel> endpointSecurityModelEntry : endpointSecurityModelMap .entrySet()) { Assert.assertTrue("Property isEndpointSecured cannot be false.", endpointSecurityModelEntry.getValue().isEnabled()); Assert.assertTrue("Property isEndpointAuthDigest cannot be false.", endpointSecurityModelEntry.getValue().getType().contains("digest")); Assert.assertTrue("Property username does not match.", "admin".equals(endpointSecurityModelEntry.getValue().getUsername())); Assert.assertTrue("Property base64unpw does not match. ", new String(Base64.encodeBase64("admin:admin123".getBytes())) .equalsIgnoreCase(endpointSecurityModelEntry.getValue().getBase64EncodedPassword())); Assert.assertTrue("Property securevault_alias does not match.", "admin--TestAPI1.0.0".equalsIgnoreCase(endpointSecurityModelEntry.getValue().getAlias())); } Assert.assertTrue("Property isSecureVaultEnabled cannot be false. ", velocityContext.get("isSecureVaultEnabled").equals(true)); }
Example 10
Source File: WSDLSOAPOperationExtractorImplTestCase.java From carbon-apimgt with Apache License 2.0 | 4 votes |
public static API getAPIForTesting() { API api = new API(new APIIdentifier("admin", "api1", "1.0.0")); api.setTransports("https"); api.setContext("/weather"); return api; }