Search in sources :

Example 21 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class AccessPolicyRepositoryTest method delete.

@Test
public void delete() throws TechnicalException {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setName("accessPolicyName");
    AccessPolicy apCreated = repository.create(accessPolicy).blockingGet();
    // fetch resource_set
    TestObserver<Void> testObserver = repository.delete(apCreated.getId()).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertNoValues();
}
Also used : AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 22 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class AccessPolicyRepositoryTest method testFindByResources.

@Test
public void testFindByResources() throws TechnicalException {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setName("accessPolicyName");
    accessPolicy.setDomain(DOMAIN_ID);
    accessPolicy.setResource(RESOURCE_ID);
    repository.create(accessPolicy).blockingGet();
    AccessPolicy accessPolicy2 = new AccessPolicy();
    accessPolicy2.setName("accessPolicyName");
    accessPolicy2.setDomain(DOMAIN_ID);
    accessPolicy2.setResource(RESOURCE_ID + "2");
    repository.create(accessPolicy2).blockingGet();
    AccessPolicy accessPolicy3 = new AccessPolicy();
    accessPolicy3.setName("accessPolicyName");
    accessPolicy3.setDomain(DOMAIN_ID + "-other");
    accessPolicy3.setResource(RESOURCE_ID + "-other");
    repository.create(accessPolicy3).blockingGet();
    TestObserver<List<AccessPolicy>> testObserver = repository.findByResources(Arrays.asList(RESOURCE_ID, RESOURCE_ID + "2")).toList().test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(accessPolicies -> accessPolicies.size() == 2);
}
Also used : List(java.util.List) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 23 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class AccessPolicyRepositoryTest method findByDomain_Paging.

@Test
public void findByDomain_Paging() throws Exception {
    final int totalCount = 10;
    final String DOMAIN10 = DOMAIN_ID + "-10";
    for (int i = 0; i < totalCount; i++) {
        AccessPolicy accessPolicy = new AccessPolicy();
        accessPolicy.setName("accessPolicyName" + i);
        accessPolicy.setDomain(DOMAIN10);
        accessPolicy.setCreatedAt(new Date());
        accessPolicy.setUpdatedAt(new Date());
        repository.create(accessPolicy).blockingGet();
        Thread.sleep(100l);
    }
    AccessPolicy accessPolicyOtherDomain = new AccessPolicy();
    accessPolicyOtherDomain.setName("accessPolicyName");
    accessPolicyOtherDomain.setDomain(DOMAIN_ID + "-other");
    repository.create(accessPolicyOtherDomain).blockingGet();
    // list all in one page
    TestObserver<Page<AccessPolicy>> testObserver = repository.findByDomain(DOMAIN10, 0, totalCount + 1).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(p -> p.getTotalCount() == totalCount);
    testObserver.assertValue(p -> p.getCurrentPage() == 0);
    testObserver.assertValue(p -> p.getData().size() == totalCount);
    testObserver = repository.findByDomain(DOMAIN10, 0, totalCount / 2).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(p -> p.getTotalCount() == totalCount);
    testObserver.assertValue(p -> p.getCurrentPage() == 0);
    testObserver.assertValue(p -> p.getData().size() == totalCount / 2);
    // ordered by updated_at desc so last are returned first
    testObserver.assertValue(p -> p.getData().stream().map(AccessPolicy::getName).filter(name -> name.matches("accessPolicyName[56789]")).count() == totalCount / 2);
    testObserver = repository.findByDomain(DOMAIN10, 1, totalCount / 2).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(p -> p.getTotalCount() == totalCount);
    testObserver.assertValue(p -> p.getCurrentPage() == 1);
    testObserver.assertValue(p -> p.getData().size() == totalCount / 2);
    // ordered by updated_at desc so first are returned last
    testObserver.assertValue(p -> p.getData().stream().map(AccessPolicy::getName).filter(name -> name.matches("accessPolicyName[01234]")).count() == totalCount / 2);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Page(io.gravitee.am.model.common.Page) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) TechnicalException(io.gravitee.am.repository.exceptions.TechnicalException) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest) AccessPolicyType(io.gravitee.am.model.uma.policy.AccessPolicyType) Page(io.gravitee.am.model.common.Page) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Date(java.util.Date) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 24 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class AccessPolicyRepositoryTest method findByDomain.

@Test
public void findByDomain() throws TechnicalException {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setName("accessPolicyName");
    final String DOMAIN_SINGLE = DOMAIN_ID + "single";
    accessPolicy.setDomain(DOMAIN_SINGLE);
    repository.create(accessPolicy).blockingGet();
    AccessPolicy accessPolicyOtherDomain = new AccessPolicy();
    accessPolicyOtherDomain.setName("accessPolicyName");
    accessPolicyOtherDomain.setDomain(DOMAIN_ID + "-other");
    repository.create(accessPolicyOtherDomain).blockingGet();
    TestObserver<Page<AccessPolicy>> testObserver = repository.findByDomain(DOMAIN_SINGLE, 0, 20).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(p -> p.getTotalCount() == 1);
}
Also used : Page(io.gravitee.am.model.common.Page) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 25 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class AccessPolicyRepositoryTest method testFindById.

@Test
public void testFindById() throws TechnicalException {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setName("accessPolicyName");
    accessPolicy.setCondition("Condition");
    accessPolicy.setCreatedAt(new Date());
    accessPolicy.setUpdatedAt(new Date());
    accessPolicy.setDescription("description");
    accessPolicy.setDomain(DOMAIN_ID);
    accessPolicy.setEnabled(true);
    accessPolicy.setOrder(Integer.MAX_VALUE);
    accessPolicy.setResource("resource");
    accessPolicy.setType(AccessPolicyType.GROOVY);
    AccessPolicy apCreated = repository.create(accessPolicy).blockingGet();
    TestObserver<AccessPolicy> testObserver = repository.findById(apCreated.getId()).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(ap -> ap.getName().equals(accessPolicy.getName()));
    testObserver.assertValue(ap -> ap.getCondition().equals(accessPolicy.getCondition()));
    testObserver.assertValue(ap -> ap.getDescription().equals(accessPolicy.getDescription()));
    testObserver.assertValue(ap -> ap.getDomain().equals(accessPolicy.getDomain()));
    testObserver.assertValue(ap -> ap.getId().equals(apCreated.getId()));
    testObserver.assertValue(ap -> ap.getResource().equals(accessPolicy.getResource()));
    testObserver.assertValue(ap -> ap.getType().equals(accessPolicy.getType()));
    testObserver.assertValue(ap -> ap.getOrder() == accessPolicy.getOrder());
}
Also used : AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Date(java.util.Date) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Aggregations

AccessPolicy (io.gravitee.am.model.uma.policy.AccessPolicy)25 Test (org.junit.Test)19 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)7 JWT (io.gravitee.am.common.jwt.JWT)3 Client (io.gravitee.am.model.oidc.Client)3 List (java.util.List)3 Token (io.gravitee.am.gateway.handler.oauth2.service.token.Token)2 AccessToken (io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken)2 Page (io.gravitee.am.model.common.Page)2 Resource (io.gravitee.am.model.uma.Resource)2 AccessPolicyType (io.gravitee.am.model.uma.policy.AccessPolicyType)2 NewResource (io.gravitee.am.service.model.NewResource)2 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)2 JsonObject (io.vertx.core.json.JsonObject)2 Date (java.util.Date)2 InvalidRequestException (io.gravitee.am.common.exception.oauth2.InvalidRequestException)1 OAuth2Request (io.gravitee.am.gateway.handler.oauth2.service.request.OAuth2Request)1 PolicyChainException (io.gravitee.am.gateway.policy.PolicyChainException)1 AccessPolicyCondition (io.gravitee.am.model.uma.policy.AccessPolicyCondition)1 TechnicalException (io.gravitee.am.repository.exceptions.TechnicalException)1