[keycloak-user] How to create the same client (same id) for multiple realms programmatically

Marek Posolda mposolda at redhat.com
Tue May 31 08:17:27 EDT 2016


Yeah, I am sorry to misuse this thread :-) It just came to my mind when 
Haim mentioned, that exception is not thrown in his code, even if 
creation of client model obviously failed.

Marek

On 30/05/16 20:24, Stian Thorgersen wrote:
> +1 Not the correct thread for it though ;)
>
> On 30 May 2016 at 11:57, Marek Posolda <mposolda at redhat.com 
> <mailto:mposolda at redhat.com>> wrote:
>
>     Maybe someone already mentions it before. IMO the returning
>     "Response" from the create methods on admin client is one of the
>     biggest limitation of current admin-client. For example if we
>     change ClientResources method:
>
>     @POST @Consumes(MediaType.APPLICATION_JSON)
>     public Response create(ClientRepresentation clientRepresentation);
>
>     to something like:
>
>     @POST @Consumes(MediaType.APPLICATION_JSON)
>     @Produces(MediaType.APPLICATION_JSON)
>     public ClientRepresentation create(ClientRepresentation clientRepresentation);
>
>
>
>     then the advantages will be:
>     - You won't need to parse the ID of newly created client from the
>     URI location and call additional GET request to retrieve newly
>     created client (You usually want newly created client when you are
>     creating it)
>     - In case the error happened, the exception will be thrown on
>     client-side too. With the "Response" object, the exception is not
>     thrown on client-side but you are supposed to manually check the
>     status code. This may be confusing for users, who are not so
>     familiar with the admin client. When exception is thrown on
>     client-side, it's crystal clear that something bad happened and
>     client wasn't successfully created on server side.
>
>     Are there any disadvantages? The only one I see is, that POST
>     responses from server will need to return the representation of
>     created object, but that's maybe rather advantage (as you don't
>     need to call additional GET request, which in 95% of cases you need).
>
>     Marek
>
>
>     On 30/05/16 08:04, Stian Thorgersen wrote:
>>     What's the status code for the response? It should be 409.
>>
>>     On 27 May 2016 at 09:02, Haim Vana <haimv at perfectomobile.com
>>     <mailto:haimv at perfectomobile.com>> wrote:
>>
>>         There is an exception in the server log, but it is not
>>         thrown, so I am not getting it in my code.
>>
>>
>>
>>         -------- Original message --------
>>         From: Stian Thorgersen <sthorger at redhat.com
>>         <mailto:sthorger at redhat.com>>
>>         Date: 5/27/16 09:24 (GMT+02:00)
>>         To: Haim Vana <haimv at perfectomobile.com
>>         <mailto:haimv at perfectomobile.com>>
>>         Cc: Marek Posolda <mposolda at redhat.com
>>         <mailto:mposolda at redhat.com>>, keycloak-user at lists.jboss.org
>>         <mailto:keycloak-user at lists.jboss.org>
>>         Subject: Re: [keycloak-user] How to create the same client
>>         (same id) for multiple realms programmatically
>>
>>         Do you not get a error when trying to create it the second
>>         time with the same id? If not please create a jira.
>>
>>         On 26 May 2016 at 20:20, Haim Vana <haimv at perfectomobile.com
>>         <mailto:haimv at perfectomobile.com>> wrote:
>>
>>             Thanks for your reply.
>>
>>             My problem was that I have used setId instead of setClientId.
>>
>>             *From:*Marek Posolda [mailto:mposolda at redhat.com
>>             <mailto:mposolda at redhat.com>]
>>             *Sent:* Thursday, May 26, 2016 4:16 PM
>>             *To:* Haim Vana <haimv at perfectomobile.com
>>             <mailto:haimv at perfectomobile.com>>;
>>             keycloak-user at lists.jboss.org
>>             <mailto:keycloak-user at lists.jboss.org>
>>             *Subject:* Re: [keycloak-user] How to create the same
>>             client (same id) for multiple realms programmatically
>>
>>             You can use for example:
>>
>>             RealmResource realm1 = *adminClient*.realms().realm(*"realm1"*);
>>
>>             RealmResource realm2 = *adminClient*.realms().realm(*"realm2"*);
>>
>>             realm1.clients().create(clientRepresentation);
>>
>>             realm2.clients().create(clientRepresentation);
>>
>>
>>             For update you can take a look at some of our tests,
>>             which are updating client. For example this one :
>>             https://github.com/mposolda/keycloak/blob/master/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ClientTest.java#L183
>>
>>             Note that you need to know client Id (this is different
>>             thant clientId). The easiest is to set it manually in
>>             representation before you create client (via client.setId
>>             ) like it's done in this test.
>>
>>             Marek
>>
>>             On 26/05/16 14:54, Haim Vana wrote:
>>
>>                 Any idea regarding the below ?
>>
>>                 As a workaround how can I update existing client
>>                 programmatically ? I couldn't find it in the admin API.
>>
>>                 Thanks again,
>>
>>                 Haim.
>>
>>                 *From:*Haim Vana
>>                 *Sent:* Thursday, May 26, 2016 2:17 PM
>>                 *To:* keycloak-user at lists.jboss.org
>>                 <mailto:keycloak-user at lists.jboss.org>
>>                 *Subject:* How to create the same client (same id)
>>                 for multiple realms programmatically
>>
>>                 Hi,
>>
>>                 I am trying to create the same client for many
>>                 realms, however it creates it only once, probably
>>                 because they have the same id, however in UI I am
>>                 able to create it.
>>
>>                 Any idea how I can create the same client for
>>                 different realms programmatically with the same id ?
>>
>>                 This is my code sample:
>>
>>                 ClientRepresentation clientRepresentation = *new *ClientRepresentation();
>>
>>                 clientRepresentation.setId(clientId); // Same
>>                 clientId for all reamls
>>
>>                 realm.clients().create(clientRepresentation); //
>>                 Client is created only for first realm
>>
>>                 Any advice will be appreciated,
>>
>>                 Haim.
>>
>>                 The information contained in this message is
>>                 proprietary to the sender, protected from disclosure,
>>                 and may be privileged. The information is intended to
>>                 be conveyed only to the designated recipient(s) of
>>                 the message. If the reader of this message is not the
>>                 intended recipient, you are hereby notified that any
>>                 dissemination, use, distribution or copying of this
>>                 communication is strictly prohibited and may be
>>                 unlawful. If you have received this communication in
>>                 error, please notify us immediately by replying to
>>                 the message and deleting it from your computer. Thank
>>                 you.
>>
>>
>>                 _______________________________________________
>>
>>                 keycloak-user mailing list
>>
>>                 keycloak-user at lists.jboss.org
>>                 <mailto:keycloak-user at lists.jboss.org>
>>
>>                 https://lists.jboss.org/mailman/listinfo/keycloak-user
>>
>>             The information contained in this message is proprietary
>>             to the sender, protected from disclosure, and may be
>>             privileged. The information is intended to be conveyed
>>             only to the designated recipient(s) of the message. If
>>             the reader of this message is not the intended recipient,
>>             you are hereby notified that any dissemination, use,
>>             distribution or copying of this communication is strictly
>>             prohibited and may be unlawful. If you have received this
>>             communication in error, please notify us immediately by
>>             replying to the message and deleting it from your
>>             computer. Thank you.
>>
>>             _______________________________________________
>>             keycloak-user mailing list
>>             keycloak-user at lists.jboss.org
>>             <mailto:keycloak-user at lists.jboss.org>
>>             https://lists.jboss.org/mailman/listinfo/keycloak-user
>>
>>
>>         The information contained in this message is proprietary to
>>         the sender, protected from disclosure, and may be privileged.
>>         The information is intended to be conveyed only to the
>>         designated recipient(s) of the message. If the reader of this
>>         message is not the intended recipient, you are hereby
>>         notified that any dissemination, use, distribution or copying
>>         of this communication is strictly prohibited and may be
>>         unlawful. If you have received this communication in error,
>>         please notify us immediately by replying to the message and
>>         deleting it from your computer. Thank you.
>>
>>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160531/d0504037/attachment-0001.html 


More information about the keycloak-user mailing list