use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.
the class EtcdSupportTestCase method start.
@BeforeClass
public void start() throws Exception {
String label = "etcdLabel";
String project = "etcdProject";
// get mock APIM Instance
MockAPIPublisher pub = MockAPIPublisher.getInstance();
API api = new API();
api.setName("PizzaShackAPI");
api.setContext("/pizzashack");
api.setProdEndpoint(getMockServiceURLHttp("/echo/prod"));
api.setSandEndpoint(getMockServiceURLHttp("/echo/sand"));
api.setVersion("1.0.0");
api.setProvider("admin");
// Register API with label
pub.addApi(label, api);
// Define application info
ApplicationDTO application = new ApplicationDTO();
application.setName("jwtApp");
application.setTier("Unlimited");
application.setId((int) (Math.random() * 1000));
// Register a production token with key validation info
KeyValidationInfo info = new KeyValidationInfo();
info.setApi(api);
info.setApplication(application);
info.setAuthorized(true);
info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
info.setSubscriptionTier("Unlimited");
jwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
jwtTokenSand = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_SANDBOX, 3600);
encodeValuesToBase64();
prepareConfigValues();
prepareCLIParameters();
initializeEtcdServer();
String[] args = { etcdUrlParameter, etcdUsernameParameter, etcdPasswordParameter, pizzaShackProdParameter, pizzaShackSandParameter, etcdTimerParameter, etcdBasePathParameter };
super.init(project, new String[] { "serviceDiscovery/etcd_test.yaml" }, args);
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.
the class CookieAuthTestCase method start.
@BeforeClass
public void start() throws Exception {
String label = "apimTestLabel";
String project = "apimTestProject";
// get mock APIM Instance
MockAPIPublisher pub = MockAPIPublisher.getInstance();
API api = new API();
api.setName("PizzaShackAPI");
api.setContext("/pizzashack");
api.setProdEndpoint(getMockServiceURLHttp("/echo/prod"));
api.setSandEndpoint(getMockServiceURLHttp("/echo/sand"));
api.setVersion("1.0.0");
api.setProvider("admin");
// Register API with label
pub.addApi(label, api);
// Define application info
ApplicationDTO application = new ApplicationDTO();
application.setName("jwtApp");
application.setTier("Unlimited");
application.setId((int) (Math.random() * 1000));
// Register a production token with key validation info
KeyValidationInfo info = new KeyValidationInfo();
info.setApi(api);
info.setApplication(application);
info.setAuthorized(true);
info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
info.setSubscriptionTier("Unlimited");
// Register a production token with key validation info
prodToken = pub.getAndRegisterAccessToken(info);
// Register a sandbox token with key validation info
KeyValidationInfo infoSand = new KeyValidationInfo();
infoSand.setApi(api);
infoSand.setApplication(application);
infoSand.setAuthorized(true);
infoSand.setKeyType(TestConstant.KEY_TYPE_SANDBOX);
infoSand.setSubscriptionTier("Unlimited");
sandToken = pub.getAndRegisterAccessToken(infoSand);
jwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
jwtTokenSand = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_SANDBOX, 3600);
expiringJwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 1);
String configPath = "confs/default-test-config.conf";
String cookie;
if (Utils.getOSName().toLowerCase().contains("windows")) {
cookie = "--Cookie=\"" + jwtTokenProd + "\"";
} else {
cookie = "--Cookie=" + jwtTokenProd;
}
String[] args = { cookie };
super.init(label, project, args, configPath);
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.
the class ScopesTestCase method start.
@BeforeClass
public void start() throws Exception {
String project = "scopesProject";
// Define application info
ApplicationDTO application = new ApplicationDTO();
application.setName("jwtApp");
application.setTier("Unlimited");
application.setId((int) (Math.random() * 1000));
jwtTokenProd = TokenUtil.getBasicJWT(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
Map<String, String> claimMap = new HashMap<>();
claimMap.put("scope", "write:pets");
jwtTokenProdWithScopes = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, claimMap);
claimMap.put("scope", "write:petsNew");
jwtTokenProdWithSingleScope = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, claimMap);
claimMap.put("scope", "write:petsNew read:pets");
jwtTokenProdWithMultipleScope = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, claimMap);
basicAuthToken = generateBasicAuthToken("generalUser1", "password");
basicAuthTokenWithSingleScope = generateBasicAuthToken("generalUser2", "password");
basicAuthTokenWithMultipleScopes = generateBasicAuthToken("generalUser3", "password");
basicAuthTokenWithScopes = generateBasicAuthToken("generalUser4", "password");
// generate apis with CLI and start the micro gateway server
super.init(project, new String[] { "common_api.yaml", "security/disable_security.yaml" });
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.
the class JWTGenerationTestCase method start.
@BeforeClass
public void start() throws Exception {
String project = "jwtGeneratorProject";
// Define application info
ApplicationDTO application = new ApplicationDTO();
application.setName("jwtApp");
application.setTier("Unlimited");
application.setId((int) (Math.random() * 1000));
// Create map with custom claims
Map<String, String> customClaims = new HashMap<>();
customClaims.put("claim1", "testValue1");
customClaims.put("claim2", "testValue2");
jwtTokenProd = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, customClaims);
// Create map with backendJwt claim
Map<String, String> jwtClaim = new HashMap<>();
jwtClaim.put("backendJwt", jwtTokenProd);
jwtWithBackendJwtClaim = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, jwtClaim);
// generate apis with CLI and start the micro gateway server
super.init(project, new String[] { "jwtGeneration/jwt_generation.yaml", "mgw-JwtGenerator.jar" }, null, "confs/jwt-generator-test-config.conf");
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.
the class JWTRevocationSupportTestCase method start.
@BeforeClass
public void start() throws Exception {
initializeEtcdServer();
String configPath = "";
String label = "apimTestLabel";
String project = "apimTestProject";
// get mock APIM Instance
MockAPIPublisher pub = MockAPIPublisher.getInstance();
API api = new API();
api.setName("PizzaShackAPI");
api.setContext("/pizzashack");
api.setProdEndpoint(getMockServiceURLHttp("/echo/prod"));
api.setSandEndpoint(getMockServiceURLHttp("/echo/sand"));
api.setVersion("1.0.0");
api.setProvider("admin");
// Register API with label
pub.addApi(label, api);
// Define application info
ApplicationDTO application = new ApplicationDTO();
application.setName("jwtApp");
application.setTier("Unlimited");
application.setId((int) (Math.random() * 1000));
// Register a production token with key validation info
KeyValidationInfo info = new KeyValidationInfo();
info.setApi(api);
info.setApplication(application);
info.setAuthorized(true);
info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
info.setSubscriptionTier("Unlimited");
// Generate the relevant JWT tokens
jwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
// Extract the JWT token
int firstDotSeparatorIndex = jwtTokenProd.indexOf('.');
int secondSeparatorIndex = jwtTokenProd.indexOf('.', firstDotSeparatorIndex + 1);
String JWTToken = jwtTokenProd.substring(firstDotSeparatorIndex + 1, secondSeparatorIndex);
byte[] decodedJwt = Base64.decodeBase64(JWTToken.getBytes());
JSONObject jsonObject = new JSONObject(new String(decodedJwt));
jti = jsonObject.get("jti").toString();
// prepareConfigValues();
// uncomment to run this test case only
// Initialize the JMS message broker
// broker = new EmbeddedBroker();
// startMessageBroker();
configPath = "confs/default-test-config.conf";
super.init(label, project, configPath);
// Send Extracted JTI to the jwtRevocation Topic
publishMessage();
}
Aggregations