Search in sources :

Example 11 with UmaResource

use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxAuth by GluuFederation.

the class UmaResourceService method getResourceById.

public UmaResource getResourceById(String id) {
    prepareBranch();
    try {
        final String key = getDnForResource(id);
        final UmaResource resource = cacheService.getWithPut(key, () -> ldapEntryManager.find(UmaResource.class, key), RESOURCE_CACHE_EXPIRATION_IN_SECONDS);
        if (resource != null) {
            return resource;
        }
    } catch (Exception e) {
        log.error("Failed to find resource set with id: " + id, e);
    }
    log.error("Failed to find resource set with id: " + id);
    throw errorResponseFactory.createWebApplicationException(Response.Status.NOT_FOUND, UmaErrorResponseType.NOT_FOUND, "Failed to find resource set with id: " + id);
}
Also used : UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource)

Example 12 with UmaResource

use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxAuth by GluuFederation.

the class UmaResourceServiceTest method umaResource_independentFromDeletableFlag_shouldBeSearchable.

@Test
public void umaResource_independentFromDeletableFlag_shouldBeSearchable() throws StringEncrypter.EncryptionException {
    final Client client = createClient();
    clientService.persist(client);
    // 1. create resource
    UmaResource resource = new UmaResource();
    resource.setName("Test resource");
    resource.setScopes(Lists.newArrayList("view"));
    resource.setId(UUID.randomUUID().toString());
    resource.setDn(umaResourceService.getDnForResource(resource.getId()));
    resource.setDeletable(false);
    final Calendar calendar = Calendar.getInstance();
    resource.setCreationDate(calendar.getTime());
    umaResourceService.addResource(resource);
    // 2. resource exists
    assertNotNull(umaResourceService.getResourceById(resource.getId()));
    // 4. resource exists
    assertNotNull(umaResourceService.getResourceById(resource.getId()));
    calendar.add(Calendar.MINUTE, -10);
    resource.setExpirationDate(calendar.getTime());
    resource.setDeletable(true);
    umaResourceService.updateResource(resource, true);
    // resource exists
    assertNotNull(umaResourceService.getResourceById(resource.getId()));
    // remove it
    umaResourceService.remove(resource);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) Client(org.gluu.oxauth.model.registration.Client) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) Test(org.testng.annotations.Test) BaseComponentTest(org.gluu.oxauth.BaseComponentTest)

Example 13 with UmaResource

use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxAuth by GluuFederation.

the class CleanerTimerTest method umaResource_whichIsExpiredAndDeletable_MustBeRemoved.

@Test
public void umaResource_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
    final Client client = createClient();
    clientService.persist(client);
    // 1. create resource
    UmaResource resource = new UmaResource();
    resource.setName("Test resource");
    resource.setScopes(Lists.newArrayList("view"));
    resource.setId(UUID.randomUUID().toString());
    resource.setDn(umaResourceService.getDnForResource(resource.getId()));
    final Calendar calendar = Calendar.getInstance();
    resource.setCreationDate(calendar.getTime());
    umaResourceService.addResource(resource);
    // 2. resource exists
    assertNotNull(umaResourceService.getResourceById(resource.getId()));
    // 3. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 4. resource exists
    assertNotNull(umaResourceService.getResourceById(resource.getId()));
    calendar.add(Calendar.MINUTE, -10);
    resource.setExpirationDate(calendar.getTime());
    umaResourceService.updateResource(resource, true);
    // 5. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 6. no resource in persistence
    try {
        umaResourceService.getResourceById(resource.getId());
        throw new AssertionError("Test failed, no 404 exception");
    } catch (WebApplicationException e) {
        // we expect WebApplicationException 404 here
        assertEquals(404, e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Client(org.gluu.oxauth.model.registration.Client) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) Test(org.testng.annotations.Test) BaseComponentTest(org.gluu.oxauth.BaseComponentTest)

Aggregations

UmaResource (org.gluu.oxauth.model.uma.persistence.UmaResource)13 Operation (io.swagger.v3.oas.annotations.Operation)6 ArrayList (java.util.ArrayList)6 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)6 OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)5 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)4 Scope (org.oxauth.persistence.model.Scope)4 BaseComponentTest (org.gluu.oxauth.BaseComponentTest)2 Client (org.gluu.oxauth.model.registration.Client)2 Test (org.testng.annotations.Test)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DisplayNameEntry (org.gluu.model.DisplayNameEntry)1 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)1 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)1 Filter (org.gluu.search.filter.Filter)1