I very much like the DSL you have going there. Removing the Range class is also a good idea, imo.  However, I&#39;m at -1 for the use of enums. You can&#39;t extend them, and you can&#39;t anticipate everything a user would add to a class. Sure we could do it in the simple idm idea where we provide the structure, but as soon as they advance past that then they&#39;re forced to use a different API.<br>

<br><div class="gmail_quote">On Mon, Oct 29, 2012 at 7:10 AM, Pedro Igor Silva <span dir="ltr">&lt;<a href="mailto:psilva@redhat.com" target="_blank">psilva@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I liked your proposal, it is simple and clear.<br>
<br>
Considering what you did I thought in another solution. At first glance, it seems more odd. But I think it can be more intuitive for users. For example, instead of having the Param.memberOf, users may use query.role(Role) or query.group(Group) directly.<br>


<br>
        IdentityManager identityManager = // get the identity manager;<br>
<br>
        Query&lt;User&gt; query = identityManager.&lt;User&gt;createQuery();<br>
<br>
        query<br>
            .limit(100)<br>
            .offset(1)<br>
            .where()<br>
                .id(&quot;1&quot;)<br>
<br>
                .property(User.FIRST_NAME, OPERATOR.equals, &quot;John&quot;)<br>
                .property(User.EXPIRATION_DATE, OPERATOR.lessThan, new Date())<br>
<br>
                .attribute(&quot;ssn&quot;, OPERATOR.equals, &quot;SSN-123&quot;)<br>
<br>
                .role(new SimpleRole(&quot;Payroll Officer&quot;))<br>
<br>
                .group(new SimpleGroup(&quot;Superuser&quot;, &quot;Superuser&quot;, null));<br>
<br>
        List&lt;User&gt; list = query.list();<br>
<br>
        for (User user : list) {<br>
            // handle users<br>
        }<br>
<br>
I think we can avoid having a Range class/interface by using some methods on the Query interface (eg. limit and offset above). Th Query interface can be used only to configure how the query should be executed, global configuration, etc.<br>


<br>
The Where interface can be useful to provide some specific validation depending of the IdentityType and how the restrictions are configured. For example, users do not have a parent relationship.<br>
<br>
The property names (firstName, email, etc) can be a Enum for each IdentityType type (user,group and role). Each IdentityType type should specify which properties are searchable + the common properties defined by the IdentityType interface.<br>


<br>
Not sure if we need the query.reset() method ... Why not just discard the query instance and build another one ?<br>
<br>
Regards.<br>
<span class="HOEnZb"><font color="#888888">Pedro Igor<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
----- Original Message -----<br>
From: &quot;Shane Bryzak&quot; &lt;<a href="mailto:sbryzak@redhat.com">sbryzak@redhat.com</a>&gt;<br>
To: <a href="mailto:security-dev@lists.jboss.org">security-dev@lists.jboss.org</a><br>
Sent: Monday, October 29, 2012 6:38:14 AM<br>
Subject: [security-dev] IdentityManager review - queries<br>
<br>
I&#39;ve started reviewing the IdentityManager interface to see where we can<br>
improve the API.  The first area I&#39;d like to visit is the Query API, of<br>
which I&#39;ve come to the conclusion that we need to do some serious<br>
redesign - the current API is non-intuitive, too verbose and not future<br>
proof.<br>
<br>
What I&#39;d like to do is throw it all out and start again, replacing it<br>
with a new cleaner API that looks something like this:<br>
<br>
public interface IdentityManager {<br>
     // &lt;snip other methods&gt;<br>
<br>
     &lt;T extends IdentityType&gt; IdentityQuery&lt;T&gt; createQuery();<br>
}<br>
<br>
public interface IdentityQuery&lt;T extends IdentityType&gt; {<br>
     public enum Param {id, key, created, expired, enabled, firstName,<br>
lastName, email, name, parent, memberOf};<br>
<br>
     public enum Operator { equals, notEquals, greaterThan, lessThan };<br>
<br>
     IdentityQuery&lt;T&gt; reset();<br>
<br>
     IdentityQuery&lt;T&gt; setParameter(Param param, Object value);<br>
<br>
     IdentityQuery&lt;T&gt; setParameter(Param param, Operator operator,<br>
Object value);<br>
<br>
     IdentityQuery&lt;T&gt; setAttributeParameter(String attributeName, Object<br>
value);<br>
<br>
     IdentityQuery&lt;T&gt; setAttributeParameter(String attributeName,<br>
Operator operator, Object value);<br>
<br>
     IdentityQuery&lt;T&gt; setRange(Range range);<br>
<br>
     List&lt;T&gt; getResultList();<br>
}<br>
<br>
This unified API basically replaces the 4 separate existing interfaces<br>
we currently have; UserQuery, RoleQuery, GroupQuery and<br>
MembershipQuery.  I&#39;ve put together a few usage scenarios to show how it<br>
might work:<br>
<br>
1) Find users with first name &#39;John&#39;:<br>
<br>
List&lt;User&gt; users = identityManager.&lt;User&gt;createQuery()<br>
     .setParameter(Param.firstName, &quot;John&quot;)<br>
     .getResultList();<br>
<br>
2) Find all expired users:<br>
<br>
List&lt;User&gt; users = identityManager.&lt;User&gt;createQuery()<br>
     .setParameter(Param.expired, Operator.lessThan, new Date())<br>
     .getResultList();<br>
<br>
3) Find all users that are a member of the &quot;Superuser&quot; group<br>
<br>
List&lt;User&gt; users = identityManager.&lt;User&gt;createQuery()<br>
     .setParameter(Param.memberOf, identityManager.getGroup(&quot;Superuser&quot;))<br>
     .getResultList();<br>
<br>
4) Find all sub-groups of the &quot;Employees&quot; group:<br>
<br>
List&lt;Group&gt; groups = identityManager.&lt;Group&gt;createQuery()<br>
     .setParameter(Param.memberOf, identityManager.getGroup(&quot;Employees&quot;))<br>
     .getResultList();<br>
<br>
5) Find all disabled roles:<br>
<br>
List&lt;Role&gt; roles = identityManager.&lt;Role&gt;createQuery()<br>
     .setParameter(Param.enabled, false)<br>
     .getResultList();<br>
<br>
6) Find all Users, Groups and Roles that have been granted the &quot;Payroll<br>
Officer&quot; role in the &quot;Human Resources&quot; group:<br>
<br>
List&lt;IdentityType&gt; identities = identityManager.&lt;IdentityType&gt;createQuery()<br>
     .setParameter(Param.memberOf, identityManager.getGroup(&quot;Human<br>
Resources&quot;))<br>
     .setParameter(Param.memberOf, identityManager.getRole(&quot;Payroll<br>
Officer&quot;))<br>
     .getResultList();<br>
<br>
7) Find all Users that have an attribute named &quot;Citizenship&quot; with a<br>
value of &quot;Greenland&quot;:<br>
<br>
List&lt;User&gt; users = identityManager.&lt;User&gt;createQuery()<br>
     .setAttributeParameter(&quot;Citizenship&quot;, &quot;Greenland&quot;)<br>
     .getResultList();<br>
<br>
I&#39;m *pretty* certain that this API is at least as capable as what we<br>
currently have, if not more so, and IMHO provides a far simpler and more<br>
versatile design (being able to select different IdentityTypes in a<br>
single query I think is a big plus).  I&#39;d love to hear any feedback on<br>
whether you like it, hate it or can think of any improvements to the<br>
design to make it better for our developers. Also, please think<br>
especially about additional usage scenarios and whether or not there are<br>
any particular use cases which might be problematic for this API.<br>
<br>
<br>
Thanks!<br>
Shane<br>
_______________________________________________<br>
security-dev mailing list<br>
<a href="mailto:security-dev@lists.jboss.org">security-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/security-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/security-dev</a><br>
_______________________________________________<br>
security-dev mailing list<br>
<a href="mailto:security-dev@lists.jboss.org">security-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/security-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/security-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Jason Porter<br><a href="http://lightguard-jp.blogspot.com" target="_blank">http://lightguard-jp.blogspot.com</a><br><a href="http://twitter.com/lightguardjp" target="_blank">http://twitter.com/lightguardjp</a><br>

<br>Software Engineer<br>Open Source Advocate<br><br>PGP key id: 926CCFF5<br>PGP key available at: <a href="http://keyserver.net" target="_blank">keyserver.net</a>, <a href="http://pgp.mit.edu" target="_blank">pgp.mit.edu</a><br>