Search in sources :

Example 66 with Client

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

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 : 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)

Example 67 with Client

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

the class CleanerTimerTest method client_whichIsNotExpiredAndDeletable_MustNotBeRemoved.

@Test
public void client_whichIsNotExpiredAndDeletable_MustNotBeRemoved() throws StringEncrypter.EncryptionException {
    // 1. create client
    final Client client = createClient(true);
    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()));
}
Also used : Client(io.jans.as.common.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(io.jans.as.server.BaseComponentTest)

Example 68 with Client

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

the class ClientsResource method updateClient.

@PUT
@ProtectedApi(scopes = { ApiAccessConstants.OPENID_CLIENTS_WRITE_ACCESS })
public Response updateClient(@Valid Client client) throws EncryptionException {
    if (logger.isDebugEnabled()) {
        logger.debug("Client details to be updated - client:{}", escapeLog(client));
    }
    String inum = client.getClientId();
    checkNotNull(inum, AttributeNames.INUM);
    checkNotNull(client.getClientName(), AttributeNames.DISPLAY_NAME);
    Client existingClient = clientService.getClientByInum(inum);
    checkResourceNotNull(existingClient, OPENID_CONNECT_CLIENT);
    client.setClientId(existingClient.getClientId());
    client.setBaseDn(clientService.getDnForClient(inum));
    client.setDeletable(client.getExpirationDate() != null);
    if (client.getClientSecret() != null) {
        client.setClientSecret(encryptionService.encrypt(client.getClientSecret()));
    }
    clientService.updateClient(client);
    Client result = clientService.getClientByInum(existingClient.getClientId());
    result.setClientSecret(encryptionService.decrypt(client.getClientSecret()));
    return Response.ok(result).build();
}
Also used : Client(io.jans.as.common.model.registration.Client) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 69 with Client

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

the class ClientsResource method deleteClient.

@DELETE
@Path(ApiConstants.INUM_PATH)
@ProtectedApi(scopes = { ApiAccessConstants.OPENID_CLIENTS_DELETE_ACCESS })
public Response deleteClient(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    if (logger.isDebugEnabled()) {
        logger.debug("Client to be deleted - inum:{} ", escapeLog(inum));
    }
    Client client = clientService.getClientByInum(inum);
    checkResourceNotNull(client, OPENID_CONNECT_CLIENT);
    clientService.removeClient(client);
    return Response.noContent().build();
}
Also used : Client(io.jans.as.common.model.registration.Client) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 70 with Client

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

the class DemoResource method getClient.

@GET
@Path(Constants.CLIENT + Constants.INUM_PATH)
public Response getClient(@PathParam(Constants.INUM) @NotNull String inum) {
    log.debug("\n DemoResource::getClient() - log = " + log + " ,inum = " + inum + "\n\n");
    Client client = utils.getClient(inum);
    log.debug(" DemoResource::getClient() - client = " + client + "\n\n");
    return Response.ok(client).build();
}
Also used : Client(io.jans.as.common.model.registration.Client)

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