Search in sources :

Example 6 with AccessController

use of org.apache.servicecomb.authentication.provider.AccessController in project java-chassis by ServiceComb.

the class TestAccessController method testIsValidOfBlackAndWhiteByServiceName.

@Test
public void testIsValidOfBlackAndWhiteByServiceName() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "*hacker");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    service.setServiceName("trustCustomer");
    Assert.assertTrue(controller.isAllowed(service));
    service.setServiceName("trustCustomerhacker");
    Assert.assertTrue(!controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 7 with AccessController

use of org.apache.servicecomb.authentication.provider.AccessController in project java-chassis by ServiceComb.

the class TestAccessController method testIsValidOfBlackAndWhiteByServiceNameAndVersion.

@Test
public void testIsValidOfBlackAndWhiteByServiceNameAndVersion() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "version");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "0.0.1");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    service.setServiceName("trustCustomer");
    service.setVersion("0.0.1");
    Assert.assertTrue(!controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 8 with AccessController

use of org.apache.servicecomb.authentication.provider.AccessController in project incubator-servicecomb-java-chassis by apache.

the class TestAccessController method testIsValidOfBlackAndWhiteByServiceName.

@Test
public void testIsValidOfBlackAndWhiteByServiceName() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "*hacker");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    service.setServiceName("trustCustomer");
    Assert.assertTrue(controller.isAllowed(service));
    service.setServiceName("trustCustomerhacker");
    Assert.assertTrue(!controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 9 with AccessController

use of org.apache.servicecomb.authentication.provider.AccessController in project incubator-servicecomb-java-chassis by apache.

the class TestAccessController method testIsValidOfWhiteByProperties.

@Test
public void testIsValidOfWhiteByProperties() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "tag");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "test");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    Map<String, String> map = new HashMap<>();
    map.put("tag", "test");
    service.setProperties(map);
    Assert.assertTrue(controller.isAllowed(service));
    map.put("tag", "testa");
    service.setProperties(map);
    Assert.assertTrue(!controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with AccessController

use of org.apache.servicecomb.authentication.provider.AccessController in project incubator-servicecomb-java-chassis by apache.

the class TestAccessController method testIsValidOfWhiteByServiceName.

@Test
public void testIsValidOfWhiteByServiceName() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    service.setServiceName("trustCustomer");
    Assert.assertTrue(controller.isAllowed(service));
    service.setServiceName("nottrustCustomer");
    Assert.assertTrue(!controller.isAllowed(service));
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "*trust");
    service.setServiceName("Customer_trust");
    Assert.assertTrue(controller.isAllowed(service));
    service.setServiceName("Customer_trust_not");
    Assert.assertTrue(!controller.isAllowed(service));
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust");
    service.setServiceName("trust");
    Assert.assertTrue(controller.isAllowed(service));
    service.setServiceName("Customer_trust");
    Assert.assertTrue(!controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Aggregations

AccessController (org.apache.servicecomb.authentication.provider.AccessController)12 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)12 Test (org.junit.Test)12 HashMap (java.util.HashMap)4