Search in sources :

Example 11 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

the class UmaResourceServiceTest 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 : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Client(io.jans.as.common.model.registration.Client)

Example 12 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

the class CacheGrantManual method testClient.

private static Client testClient() {
    Client client = new Client();
    client.setClientId(UUID.randomUUID().toString());
    return client;
}
Also used : MemcachedClient(net.spy.memcached.MemcachedClient) Client(io.jans.as.common.model.registration.Client)

Example 13 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

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(io.jans.as.server.uma.authorization.UmaPCT) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Client(io.jans.as.common.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(io.jans.as.server.BaseComponentTest)

Example 14 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

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 : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) UmaPermission(io.jans.as.model.uma.persistence.UmaPermission) Client(io.jans.as.common.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(io.jans.as.server.BaseComponentTest)

Example 15 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

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 : ExecutionContext(io.jans.as.server.model.common.ExecutionContext) UmaRPT(io.jans.as.server.uma.authorization.UmaRPT) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Client(io.jans.as.common.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(io.jans.as.server.BaseComponentTest)

Aggregations

Client (io.jans.as.common.model.registration.Client)70 WebApplicationException (javax.ws.rs.WebApplicationException)20 InvalidJwtException (io.jans.as.model.exception.InvalidJwtException)12 JSONObject (org.json.JSONObject)12 Test (org.testng.annotations.Test)12 User (io.jans.as.common.model.common.User)11 BaseComponentTest (io.jans.as.server.BaseComponentTest)10 Calendar (java.util.Calendar)10 GregorianCalendar (java.util.GregorianCalendar)10 IOException (java.io.IOException)9 OAuth2AuditLog (io.jans.as.server.model.audit.OAuth2AuditLog)8 AuthorizationGrant (io.jans.as.server.model.common.AuthorizationGrant)8 ExecutionContext (io.jans.as.server.model.common.ExecutionContext)8 JSONException (org.json.JSONException)8 Jwt (io.jans.as.model.jwt.Jwt)7 Response (javax.ws.rs.core.Response)7 SessionClient (io.jans.as.server.model.session.SessionClient)6 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)6 ServletException (javax.servlet.ServletException)6 SignatureAlgorithm (io.jans.as.model.crypto.signature.SignatureAlgorithm)5