Search in sources :

Example 11 with Client

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

the class CleanerTimerTest method client_whichIsExpiredAndDeletable_MustBeRemoved.

// disabled temporarily. It works perfectly locally but fails on jenkins. Reason is unclear.
@Test(enabled = false)
public void client_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
    // 1. create client
    final Client client = createClient(true);
    final Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    client.setClientIdIssuedAt(calendar.getTime());
    calendar.add(Calendar.MONTH, -1);
    client.setExpirationDate(calendar.getTime());
    clientService.persist(client);
    // 2. client is in persistence
    assertNotNull(clientService.getClient(client.getClientId()));
    // 3. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 4. no client in persistence
    assertNull(clientService.getClient(client.getClientId()));
}
Also used : Client(org.gluu.oxauth.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(org.gluu.oxauth.BaseComponentTest)

Example 12 with Client

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

the class CleanerTimerTest method u2fDevice_whichIsExpiredAndDeletable_MustBeRemoved.

@Test
public void u2fDevice_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
    final Client client = createClient();
    clientService.persist(client);
    // 1. create device
    String userInum = "";
    String appId = "https://testapp.com";
    final DeviceRegistration device = new DeviceRegistration();
    device.setStatus(DeviceRegistrationStatus.ACTIVE);
    device.setApplication(appId);
    device.setId(String.valueOf(System.currentTimeMillis()));
    device.setDn(deviceRegistrationService.getDnForU2fDevice(userInum, device.getId()));
    deviceRegistrationService.addOneStepDeviceRegistration(device);
    // 2. device exists
    assertNotNull(deviceRegistrationService.findUserDeviceRegistration(userInum, device.getId()));
    // 3. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 4. device exists
    assertNotNull(deviceRegistrationService.findUserDeviceRegistration(userInum, device.getId()));
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MINUTE, -10);
    device.setExpirationDate(calendar.getTime());
    deviceRegistrationService.merge(device);
    // 5. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 6. no device in persistence
    try {
        deviceRegistrationService.findUserDeviceRegistration(userInum, device.getId());
        throw new AssertionError("No exception, expected EntryPersistenceException on find.");
    } catch (EntryPersistenceException e) {
    // ignore
    }
}
Also used : EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) DeviceRegistration(org.gluu.oxauth.model.fido.u2f.DeviceRegistration) Client(org.gluu.oxauth.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(org.gluu.oxauth.BaseComponentTest)

Example 13 with Client

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

the class CleanerTimerTest method u2fRequest_whichIsExpiredAndDeletable_MustBeRemoved.

@Test
public void u2fRequest_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
    final Client client = createClient();
    clientService.persist(client);
    // 1. create token
    String userInum = "";
    String appId = "https://testapp.com";
    final RequestMessageLdap request = u2fRegistrationService.storeRegisterRequestMessage(u2fRegistrationService.builRegisterRequestMessage(appId, userInum), userInum, userInum);
    // 2. request exists
    assertNotNull(u2fRegistrationService.getRegisterRequestMessage(request.getId()));
    // 3. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 4. request exists
    assertNotNull(u2fRegistrationService.getRegisterRequestMessage(request.getId()));
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MINUTE, -10);
    request.setExpirationDate(calendar.getTime());
    u2fRegistrationService.merge(request);
    // 5. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 6. no request in persistence
    try {
        u2fRegistrationService.getRegisterRequestMessage(request.getId());
        throw new AssertionError("No exception, expected EntryPersistenceException on find request.");
    } catch (EntryPersistenceException e) {
    // ignore
    }
}
Also used : EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) Client(org.gluu.oxauth.model.registration.Client) RequestMessageLdap(org.gluu.oxauth.model.fido.u2f.RequestMessageLdap) Test(org.testng.annotations.Test) BaseComponentTest(org.gluu.oxauth.BaseComponentTest)

Example 14 with Client

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

the class CleanerTimerTest method umaPermission_whichIsExpiredAndDeletable_MustBeRemoved.

@Test
public void umaPermission_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
    final Client client = createClient();
    clientService.persist(client);
    final String ticket = UUID.randomUUID().toString();
    // 1. create permission
    UmaPermission permission = new UmaPermission();
    permission.setTicket(ticket);
    permission.setConfigurationCode(UUID.randomUUID().toString());
    permission.setResourceId(UUID.randomUUID().toString());
    umaPermissionService.addPermission(permission, client.getDn());
    // 2. permission exists
    assertNotNull(umaPermissionService.getPermissionsByTicket(ticket).get(0));
    // 3. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 4. permission exists
    assertNotNull(umaPermissionService.getPermissionsByTicket(ticket).get(0));
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MINUTE, -10);
    permission.setExpirationDate(calendar.getTime());
    umaPermissionService.merge(permission);
    // 5. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 6. no permission in persistence
    final List<UmaPermission> permissionsByTicket = umaPermissionService.getPermissionsByTicket(ticket);
    assertTrue(permissionsByTicket.isEmpty());
}
Also used : UmaPermission(org.gluu.oxauth.model.uma.persistence.UmaPermission) Client(org.gluu.oxauth.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(org.gluu.oxauth.BaseComponentTest)

Example 15 with Client

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

the class CleanerTimerTest method client_whichIsExpiredAndNotDeletable_MustNotBeRemoved.

@Test
public void client_whichIsExpiredAndNotDeletable_MustNotBeRemoved() throws StringEncrypter.EncryptionException {
    // 1. create client
    final Client client = createClient(false);
    try {
        final Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
        client.setClientIdIssuedAt(calendar.getTime());
        calendar.add(Calendar.HOUR, -1);
        client.setExpirationDate(calendar.getTime());
        clientService.persist(client);
        // 2. client is in persistence
        assertNotNull(clientService.getClient(client.getClientId()));
        // 3. clean up
        cleanerTimer.processImpl();
        cacheService.clear();
        // 4. client is in persistence (not removed)
        assertNotNull(clientService.getClient(client.getClientId()));
    } finally {
        // make it available for cleaner
        client.setDeletable(true);
        clientService.merge(client);
    }
}
Also used : 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