<html><head></head><body><div>Ah, that simple. Please take a look at the PR.</div><div><br></div><div>Note: in RealmTest::assertRealm, while comparing initial vs. created realm, &nbsp;we have to check for inclusion of attributes, not equality (of attribute maps). This is because the JPA realm impl adds a lot of attributes itself, and they're now returned by the endpoint.</div><div><br></div><div>Dmitry</div><div><br></div><div>В Ср, 17/08/2016 в 09:44 +0200, Stian Thorgersen пишет:</div><blockquote type="cite"><div dir="ltr">Take a look at ClientAdapter/ClientEntity. The ClientEntity for Mongo just returns the list, while the ClientAdapter does the rest.</div><div class="gmail_extra"><br><div class="gmail_quote">On 16 August 2016 at 21:06, Dmitry Telegin <span dir="ltr">&lt;<a href="mailto:mitya@cargosoft.ru" target="_blank">mitya@cargosoft.ru</a>&gt;</span> wrote:<br><blockquote type="cite"><div><div>Hi,</div><div><br></div><div>I've started implementing attributes for Mongo. I've begun with adding attribute methods to&nbsp;org.keycloak.models.<wbr>entities.RealmEntity (base class for MongoRealmEntity), but ended up with the following:</div><div><br></div><pre>java.lang.<wbr>IllegalArgumentException: Invalid accessor method, must have zero arguments if starts with 'get'. Method: public java.lang.String org.keycloak.models.entities.<wbr>RealmEntity.getAttribute(java.<wbr>lang.String)</pre><pre><span>        </span>at org.keycloak.models.utils.<wbr>reflection.MethodPropertyImpl.<wbr>&lt;init&gt;(MethodPropertyImpl.<wbr>java:53)</pre><pre><span>        </span>at org.keycloak.models.utils.<wbr>reflection.Properties.<wbr>createProperty(Properties.<wbr>java:44)</pre><pre><span>        </span>at org.keycloak.models.utils.<wbr>reflection.PropertyQuery.<wbr>getResultList(PropertyQuery.<wbr>java:168)</pre><pre><span>        </span>at org.keycloak.models.utils.<wbr>reflection.PropertyQuery.<wbr>getWritableResultList(<wbr>PropertyQuery.java:140)</pre><pre><span>        </span>at org.keycloak.connections.<wbr>mongo.impl.MongoStoreImpl.<wbr>getEntityInfo(MongoStoreImpl.<wbr>java:433)</pre><pre><span>        </span>at org.keycloak.connections.<wbr>mongo.impl.MongoStoreImpl.&lt;<wbr>init&gt;(MongoStoreImpl.java:101)</pre><pre><span>        </span>at org.keycloak.connections.<wbr>mongo.<wbr>DefaultMongoConnectionFactoryP<wbr>rovider.lazyInit(<wbr>DefaultMongoConnectionFactoryP<wbr>rovider.java:156)</pre><div><br></div><div>Seems like KeyCloak's query system doesn't like entities with pseudo-getter methods. Any suggestions?</div><div><br></div><div>Dmitry</div><div><div class="h5"><div><br></div><blockquote type="cite"><div dir="ltr">Sounds like you're on the right track. You'd need to implement support for Mongo as well though as we can't accept it otherwise.<div><br></div><div>With regards to tests I'd add to&nbsp;org.keycloak.testsuite.<wbr>admin.realm.RealmTest which would also make sure attributes work correctly when added through the admin endpoints.<br><div class="gmail_extra"><br><div class="gmail_quote">On 13 August 2016 at 16:47, Dmitry Telegin <span dir="ltr">&lt;<a href="mailto:mitya@cargosoft.ru" target="_blank">mitya@cargosoft.ru</a>&gt;</span> wrote:<br><blockquote type="cite"><div><div>Hi,</div><div><br></div><div>(As Stian is on vacation now, I'd appreciate if someone other helps me with this feature.)</div><div><br></div><div>Please take a look&nbsp;<a href="https://github.com/keycloak/keycloak/compare/2.1.0.Final...cargosoft:KEYCLOAK-3327" target="_blank">https://github.com/keyclo<wbr>ak/keycloak/compare/2.1.0.<wbr>Final...cargosoft:KEYCLOAK-332<wbr>7</a></div><div><br></div><div>(it has been branched off 2.1.0.Final for the ease of testing, I'll rebase it onto master if needed)</div><div><br></div><div>o.k.models.RealmModel: added methods (borrowed signatures from jpa.RealmAdapter)</div><div>o.k.models.jpa.RealmAdapter: added @Override annotations</div><div><span title="model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java">o.k.models.mongo.keycloak.adap<wbr>ters.RealmAdapter: added stubs (throwing&nbsp;</span>UnsupportedOperation<wbr>Exception)</div><div><span title="model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java"><a href="http://o.k.models.cache.infinispan.Re">o.k.models.cache.infinispan.Re</a><wbr>almAdapter: added attributes caching logic</span></div><div><span title="model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java">o.k.</span>models.cache.infinispan.en<wbr>tities.CachedRealm: added attributes cache (as Map&lt;String, String&gt;)</div><div><br></div><div>As for tests, I'm afraid I'll need some guidance. org.keycloak.testsuite.model.M<wbr>odelTest seems appropriate for that; but it will need support for attributes in RealmRepresentation and RealmManager. Is this the right direction?</div><div><br></div><div>Dmitry</div><div><div><div><br></div><blockquote type="cite"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 18 July 2016 at 22:35, Dmitry Telegin <span dir="ltr">&lt;<a href="mailto:mitya@cargosoft.ru" target="_blank">mitya@cargosoft.ru</a>&gt;</span> wrote:<br><blockquote type="cite"><div><div>Stian,</div><div><br></div><div>Here we go:&nbsp;<a href="https://issues.jboss.org/browse/KEYCLOAK-3327" target="_blank">https://issues.jboss.org/b<wbr>rowse/KEYCLOAK-3327</a></div><div><br></div><div>If the fix is somewhat trivial (i.e. a matter of adding fields and getters/setters) I think I could work on a PR as well.</div></div><br></blockquote><div><br></div><div>As the attributes are already available in the underlying entities it's just a matter of exposing through RealmModel and add tests for it.</div><div>&nbsp;</div><blockquote type="cite"><div><div><br></div><div>BTW, does this mean that all the custom entities provided via Entity SPI are not by default cache-enabled (and won't be synchronized between the nodes in clustered environment)?</div><div>If so, will it be easy to cache-enable them? Is this just a matter of providing Infinispan adapters similar to existing ones for Realm/User/Role/Client etc.?</div></div><br></blockquote><div><br></div><div>There's no caching for custom entities. I'd recommend using Hibernate 2nd level cache for it as it's rather tricky to create a custom one. We have our custom one because we need to support Mongo as well as users from different sources (user federation and identity brokering).</div><div>&nbsp;</div><blockquote type="cite"><div><div><br></div><div>Ideally, I'd like to see a current domain-extension example augmented with Infinispan cache functionality. I've got some ideas on a detailed walkthrough tutorial for building complete, full-featured KeyCloak extensions (it's a big topic I'll elaborate on a bit later); I think Infinispan-enabled entities could be covered there, too.</div></div><br></blockquote><div><br></div><div>No chance we're adding cache for custom entities. It's just to hard to get right. For custom entities you should use Hibernate 2nd level cache.</div><div>&nbsp;</div><blockquote type="cite"><div><div><br></div><div>Regards,</div><div>Dmitry</div><div><br></div><div>В Пн, 18/07/2016 в 07:39 +0200, Stian Thorgersen пишет:</div><div><div><blockquote type="cite"><div dir="ltr">Forgot that attributes are not exposed through RealmModel. You can't access the JPA RealmAdapter directly as you'll break the cache functionality. You can create a JIRA to request attributes added to RealmModel though.</div><div class="gmail_extra"><br><div class="gmail_quote">On 15 July 2016 at 20:28, Mitya <span dir="ltr">&lt;<a href="mailto:mitya@cargosoft.ru" target="_blank">mitya@cargosoft.ru</a>&gt;</span> wrote:<br><blockquote type="cite"><div><div>Stian,</div><div><br></div><div>In my provider, session.getContext().getRealm(<wbr>) returns an instance of&nbsp;org.keycloak.models.cache.i<wbr>nfinispan.RealmAdapter. But in order to be able to manage attributes, we need an org.keycloak.models.jpa.RealmA<wbr>dapter. What's the best way to obtain it?</div><div><br></div><div>I've yet come up with the following:</div><div><br></div><div>RealmModel realm = session.getContext().getRealm(<wbr>);</div><div>RealmAdapter adapter = (RealmAdapter) session.getProvider(RealmProvi<wbr>der.class).getRealm(realm.<wbr>getId());</div><div><div><div><br></div><div><br></div><blockquote type="cite"><div dir="ltr">Realm attributes should be perfect for that</div><div class="gmail_extra"><br><div class="gmail_quote">On 12 July 2016 at 13:42, Mitya <span dir="ltr">&lt;<a href="mailto:mitya@cargosoft.ru" target="_blank">mitya@cargosoft.ru</a>&gt;</span> wrote:<br><blockquote type="cite"><div><div>Hi,</div><div><br></div><div>I'm developing a KeyCloak extension, and I want some custom (per-realm) parameters to be tuned via the GUI form. Speaking of the storage mechanism for my settings, are realm attributes suitable for that? or should I create a dedicated custom entity instead?</div><div><br></div><div>Thx,</div><div>Mitya</div></div><br>______________________________<wbr>_________________<br>
keycloak-dev mailing list<br>
<a href="mailto:keycloak-dev@lists.jboss.org" target="_blank">keycloak-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailma<wbr>n/listinfo/keycloak-dev</a><br></blockquote></div><br></div>
</blockquote></div></div></div><br></blockquote></div><br></div>
</blockquote></div></div></div><br></blockquote></div><br></div></div>
</blockquote></div></div></div><br></blockquote></div><br></div></div></div>
</blockquote></div></div></div><br></blockquote></div><br></div>
</blockquote></body></html>