static OIDCClientRepresentationExtended toExternalResponse(KeycloakSession session, ClientRepresentation client, URI uri ) { String softStatement = client.getAttributes().get("software_statement"); OIDCClientRepresentation clientRep = DescriptionConverter.toExternalResponse(session, client, uri); OIDCClientRepresentationExtended response = new OIDCClientRepresentationExtended(); ObjectMapper mapper = new ObjectMapper(); try { String clientRepStr = mapper.writeValueAsString(clientRep); response = mapper.readValue(clientRepStr, OIDCClientRepresentationExtended.class); response.setSoftwareStatement(softStatement); return response; } catch (IOException e) { ServicesLogger.LOGGER.warn( "Failed to convert ClientRepresentation to OIDCClientRepresentationExtended. Exception: {}", e.getMessage(), e ); } return response; }
@PUT @Path("{clientId}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateOIDC(@PathParam("clientId") String clientId, OIDCClientRepresentationExtended clientOIDC) { try { ClientRepresentation client = DescriptionConverterExt.toInternal(session, clientOIDC); OIDCClientRegistrationContext oidcContext = new OIDCClientRegistrationContext(session, client, this, clientOIDC); client = update(clientId, oidcContext); ClientModel clientModel = session.getContext().getRealm().getClientByClientId(client.getClientId()); updatePairwiseSubMappers(clientModel, SubjectType.parse(clientOIDC.getSubjectType()), clientOIDC.getSectorIdentifierUri()); updateClientRepWithProtocolMappers(clientModel, client); URI uri = session.getContext().getUri().getAbsolutePathBuilder().path(client.getClientId()).build(); OIDCClientRepresentationExtended clientOIDCResponse = DescriptionConverterExt.toExternalResponse(session, client, uri); return Response.ok(clientOIDCResponse).build(); } catch (ClientRegistrationException cre) { ServicesLogger.LOGGER.clientRegistrationException(cre.getMessage()); throw new ErrorResponseException(ErrorCodes.INVALID_CLIENT_METADATA, "Client metadata invalid", Response.Status.BAD_REQUEST); } }
return Response.created(uri).entity(clientOIDCResponse).build(); } catch (ClientRegistrationException cre) { ServicesLogger.LOGGER.clientRegistrationException(cre.getMessage()); throw new ErrorResponseException(ErrorCodes.INVALID_CLIENT_METADATA, "Client metadata invalid", Response.Status.BAD_REQUEST);