Search in sources :

Example 51 with Client

use of org.gluu.oxauth.model.registration.Client 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 52 with Client

use of org.gluu.oxauth.model.registration.Client 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)

Example 53 with Client

use of org.gluu.oxauth.model.registration.Client in project oxAuth by GluuFederation.

the class CleanerTimerTest method umaPct_whichIsExpiredAndDeletable_MustBeRemoved.

@Test
public void umaPct_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
    final Client client = createClient();
    clientService.persist(client);
    // 1. create pct
    UmaPCT pct = umaPctService.createPct(client.getClientId());
    umaPctService.persist(pct);
    // 2. pct exists
    assertNotNull(umaPctService.getByCode(pct.getCode()));
    // 3. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 4. pct exists
    assertNotNull(umaPctService.getByCode(pct.getCode()));
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MINUTE, -10);
    pct.setExpirationDate(calendar.getTime());
    umaPctService.merge(pct);
    // 5. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 6. no pct in persistence
    assertNull(umaPctService.getByCode(pct.getCode()));
}
Also used : UmaPCT(org.gluu.oxauth.uma.authorization.UmaPCT) Client(org.gluu.oxauth.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(org.gluu.oxauth.BaseComponentTest)

Example 54 with Client

use of org.gluu.oxauth.model.registration.Client in project oxAuth by GluuFederation.

the class CleanerTimerTest method createClient.

private Client createClient(boolean deletable) throws StringEncrypter.EncryptionException {
    String clientsBaseDN = staticConfiguration.getBaseDn().getClients();
    String inum = inumService.generateClientInum();
    String generatedClientSecret = UUID.randomUUID().toString();
    final Client client = new Client();
    client.setDn("inum=" + inum + "," + clientsBaseDN);
    client.setClientName("Cleaner Timer Test");
    client.setClientId(inum);
    client.setClientSecret(clientService.encryptSecret(generatedClientSecret));
    client.setRegistrationAccessToken(HandleTokenFactory.generateHandleToken());
    client.setDeletable(deletable);
    final Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    client.setClientIdIssuedAt(calendar.getTime());
    calendar.add(Calendar.MINUTE, 10);
    client.setExpirationDate(calendar.getTime());
    return client;
}
Also used : Client(org.gluu.oxauth.model.registration.Client)

Example 55 with Client

use of org.gluu.oxauth.model.registration.Client in project oxAuth by GluuFederation.

the class CleanerTimerTest method umaRpt_whichIsExpiredAndDeletable_MustBeRemoved.

@Test
public void umaRpt_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
    final Client client = createClient();
    clientService.persist(client);
    // 1. create RPT
    final ExecutionContext executionContext = new ExecutionContext(null, null);
    executionContext.setClient(client);
    final UmaRPT rpt = umaRptService.createRPTAndPersist(executionContext, Lists.newArrayList());
    // 2. RPT exists
    assertNotNull(umaRptService.getRPTByCode(rpt.getNotHashedCode()));
    // 3. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 4. RPT exists
    assertNotNull(umaRptService.getRPTByCode(rpt.getNotHashedCode()));
    final Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MINUTE, -10);
    rpt.setExpirationDate(calendar.getTime());
    umaRptService.merge(rpt);
    // 5. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 6. no RPT in persistence
    assertNull(umaRptService.getRPTByCode(rpt.getNotHashedCode()));
}
Also used : UmaRPT(org.gluu.oxauth.uma.authorization.UmaRPT) Client(org.gluu.oxauth.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(org.gluu.oxauth.BaseComponentTest)

Aggregations

Client (org.gluu.oxauth.model.registration.Client)55 WebApplicationException (javax.ws.rs.WebApplicationException)15 Test (org.testng.annotations.Test)14 BaseComponentTest (org.gluu.oxauth.BaseComponentTest)12 InvalidJwtException (org.gluu.oxauth.model.exception.InvalidJwtException)10 OAuth2AuditLog (org.gluu.oxauth.model.audit.OAuth2AuditLog)8 JSONException (org.json.JSONException)8 Response (javax.ws.rs.core.Response)6 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)6 JSONObject (org.json.JSONObject)6 IOException (java.io.IOException)5 Date (java.util.Date)5 Jwt (org.gluu.oxauth.model.jwt.Jwt)5 SessionClient (org.gluu.oxauth.model.session.SessionClient)5 URI (java.net.URI)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 JwtAuthorizationRequest (org.gluu.oxauth.model.authorize.JwtAuthorizationRequest)4 ArrayList (java.util.ArrayList)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Claim (org.gluu.oxauth.model.authorize.Claim)3