Search in sources :

Example 11 with AccessController

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

the class TestAccessController method testIsValidOfBlackByServiceName.

@Test
public void testIsValidOfBlackByServiceName() {
    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", "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.black.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.black.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)

Example 12 with AccessController

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

the class TestAccessController method testIsValidOfBlackByProperties.

@Test
public void testIsValidOfBlackByProperties() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "tag");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.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)

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