Search in sources :

Example 1 with AdminClientUpdatedContext

use of org.keycloak.services.clientpolicy.context.AdminClientUpdatedContext in project keycloak by keycloak.

the class ClientResource method update.

/**
 * Update the client
 * @param rep
 * @return
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response update(final ClientRepresentation rep) {
    auth.clients().requireConfigure(client);
    try {
        session.clientPolicy().triggerOnEvent(new AdminClientUpdateContext(rep, client, auth.adminAuth()));
        updateClientFromRep(rep, client, session);
        ValidationUtil.validateClient(session, client, false, r -> {
            session.getTransactionManager().setRollbackOnly();
            throw new ErrorResponseException(Errors.INVALID_INPUT, r.getAllLocalizedErrorsAsString(AdminRoot.getMessages(session, realm, auth.adminAuth().getToken().getLocale())), Response.Status.BAD_REQUEST);
        });
        session.clientPolicy().triggerOnEvent(new AdminClientUpdatedContext(rep, client, auth.adminAuth()));
        adminEvent.operation(OperationType.UPDATE).resourcePath(session.getContext().getUri()).representation(rep).success();
        return Response.noContent().build();
    } catch (ModelDuplicateException e) {
        return ErrorResponse.exists("Client already exists");
    } catch (ClientPolicyException cpe) {
        throw new ErrorResponseException(cpe.getError(), cpe.getErrorDetail(), Response.Status.BAD_REQUEST);
    }
}
Also used : AdminClientUpdateContext(org.keycloak.services.clientpolicy.context.AdminClientUpdateContext) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) ErrorResponseException(org.keycloak.services.ErrorResponseException) AdminClientUpdatedContext(org.keycloak.services.clientpolicy.context.AdminClientUpdatedContext) ClientPolicyException(org.keycloak.services.clientpolicy.ClientPolicyException) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 ModelDuplicateException (org.keycloak.models.ModelDuplicateException)1 ErrorResponseException (org.keycloak.services.ErrorResponseException)1 ClientPolicyException (org.keycloak.services.clientpolicy.ClientPolicyException)1 AdminClientUpdateContext (org.keycloak.services.clientpolicy.context.AdminClientUpdateContext)1 AdminClientUpdatedContext (org.keycloak.services.clientpolicy.context.AdminClientUpdatedContext)1