From jboss-identity-commits at lists.jboss.org Sat May 9 17:32:34 2009 Content-Type: multipart/mixed; boundary="===============6178353889641472628==" MIME-Version: 1.0 From: jboss-identity-commits at lists.jboss.org To: jboss-identity-commits at lists.jboss.org Subject: [jboss-identity-commits] JBoss Identity SVN: r488 - in idm/trunk: idm-core/src/main/java/org/jboss/identity/idm/impl/api/query and 4 other directories. Date: Sat, 09 May 2009 17:28:54 -0400 Message-ID: --===============6178353889641472628== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: bdaw Date: 2009-05-09 17:28:54 -0400 (Sat, 09 May 2009) New Revision: 488 Modified: idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/Identit= ySearchCriteriaImpl.java idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/query/A= bstractQueryExecutor.java idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/query/G= roupQueryExecutorImpl.java idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/query/U= serQueryExecutorImpl.java idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/session= /managers/RelationshipManagerImpl.java idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/AP= ILDAPTestCase.java idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/AP= ITestCase.java idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/Re= lationshipManagerTest.java idm/trunk/integration/jboss5/pom.xml idm/trunk/integration/jboss5/src/main/resources/assembly.xml Log: cascade search impl for findAssociatedUsers and findAssociatedGroups Modified: idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/= IdentitySearchCriteriaImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/Identi= tySearchCriteriaImpl.java 2009-05-09 15:10:05 UTC (rev 487) +++ idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/Identi= tySearchCriteriaImpl.java 2009-05-09 21:28:54 UTC (rev 488) @@ -25,10 +25,24 @@ import org.jboss.identity.idm.api.IdentitySearchCriteria; import org.jboss.identity.idm.api.SortOrder; import org.jboss.identity.idm.api.UnsupportedCriterium; +import org.jboss.identity.idm.api.IdentityType; +import org.jboss.identity.idm.api.Attribute; +import org.jboss.identity.idm.api.User; +import org.jboss.identity.idm.api.Group; +import org.jboss.identity.idm.api.IdentitySession; import org.jboss.identity.idm.spi.search.IdentityObjectSearchCriteria; +import org.jboss.identity.idm.impl.helper.Tools; = import java.util.Map; import java.util.HashMap; +import java.util.List; +import java.util.Collection; +import java.util.Set; +import java.util.HashSet; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; = /** * @author Boleslaw D= awidowicz @@ -239,4 +253,247 @@ result =3D 31 * result + (filter !=3D null ? filter.hashCode() : 0); return result; } + + + // Static helper methods: + + + + public static List applyCriteria(IdentitySe= ssion identitySession, + IdentityOb= jectSearchCriteria criteria, + List ty= pes) throws Exception + { + + + // First pass - filters + + if(criteria.isFiltered()) + { + if (criteria.getFilter() !=3D null) + { + filterByIdFilter(types, criteria.getFilter()); + } + + if (criteria.getValues() !=3D null && criteria.getValues().size()= > 0) + { + filterByAttributesValues(identitySession, types, criteria.getV= alues()); + } + + } + + // Second pass - sort + + if (criteria.isSorted()) + { + if (criteria.getSortAttributeName() !=3D null) + { + sortByAttributeName(identitySession, types, criteria.getSortA= ttributeName(), criteria.isAscending()); + } + else + { + sortByName(types, criteria.isAscending()); + } + } + + List results =3D types; + + // Third pass - cut the page + + if (criteria.isPaged()) + { + results =3D cutPageFromResults(results, criteria); + } + + return results; + } + + //TODO: quick impl. should be reviewed + private static void filterByAttributesValues(IdentitySession identitySe= ssion, + Collection types, + Map attr= s) throws Exception + { + Set toRemove =3D new HashSet(); + + for (IdentityType type : types) + { + //TODO: AttributeManager should have .getAttributes(type, names) = to improve and not obtain everything + Map presentAttrs =3D identitySession.getAttrib= utesManager().getAttributes(type); + + for (Map.Entry entry : attrs.entrySet()) + { + if (presentAttrs.containsKey(entry.getKey())) + { + Set given =3D new HashSet(Arrays.asList(ent= ry.getValue())); + Attribute attr =3D presentAttrs.get(entry.getKey()); + + Collection present =3D null; + + if (attr !=3D null) + { + present =3D attr.getValues(); + } + else + { + present =3D Collections.emptySet(); + } + + for (String s : given) + { + if (!present.contains(s)) + { + toRemove.add(type); + break; + } + } + + } + else + { + toRemove.add(type); + break; + + } + } + } + + for (IdentityType type : toRemove) + { + types.remove(type); + } + + } + + //TODO: quick impl. should be reviewed + private static void filterByIdFilter(List types= , String filter) throws Exception + { + Set toRemove =3D new HashSet(); + + String regex =3D Tools.wildcardToRegex(filter); + + + for (IdentityType type : types) + { + String id =3D null; + + if (type instanceof User) + { + id =3D type.getId(); + } + else if (type instanceof Group) + { + id =3D ((Group)type).getName(); + } + else + { + // shouldn't happen + throw new IllegalStateException(); + } + + if (!id.matches(regex)) + { + toRemove.add(type); + } + } + + for (IdentityType type : toRemove) + { + types.remove(type); + } + + } + + private static void sortByName(List objects= , final boolean ascending) + { + Collections.sort(objects, new Comparator(){ + public int compare(T o1, T o2) + { + if (o1 instanceof User && o2 instanceof User) + { + if (ascending) + { + return o1.getId().compareTo(o2.getId()); + } + else + { + return o2.getId().compareTo(o1.getId()); + } + } + else + { + Group g1 =3D (Group)o1; + Group g2 =3D (Group)o2; + + if (ascending) + { + return g1.getName().compareTo(g2.getName()); + } + else + { + return g2.getName().compareTo(g1.getName()); + } + + } + } + }); + } + + private static void sortByAttributeName(Identi= tySession identitySession, + List objects, + String= attributeName, final boolean ascending) + throws Exception + { + + //TODO: Check if attribute has "text" type and delegate to name sort= if not + + // Pre fetch attributes + final Map attributes =3D new HashMap(); + + for (T object : objects) + { + Attribute attr =3D identitySession.getAttributesManager().getAttr= ibute(object, attributeName); + + if (attr !=3D null && attr.getValue() !=3D null) + { + attributes.put(object, attr.getValue().toString()); + } + else + { + attributes.put(object, ""); + } + } + + + + Collections.sort(objects, new Comparator(){ + public int compare(T o1, T o2) + { + String a1 =3D attributes.get(o1); + String a2 =3D attributes.get(o2); + + if (ascending) + { + return a1.compareTo(a2); + } + else + { + return a2.compareTo(a1); + } + } + }); + } + + //TODO: dummy and inefficient... + private static List cutPageFromResults(List= objects, + Iden= tityObjectSearchCriteria criteria) + { + List results =3D new LinkedList(); + for (int i =3D criteria.getFirstResult(); i < criteria.getFirstResul= t() + criteria.getMaxResults(); i++) + { + if (i < objects.size()) + { + results.add(objects.get(i)); + } + } + return results; + } } Modified: idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/= query/AbstractQueryExecutor.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/query/= AbstractQueryExecutor.java 2009-05-09 15:10:05 UTC (rev 487) +++ idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/query/= AbstractQueryExecutor.java 2009-05-09 21:28:54 UTC (rev 488) @@ -84,51 +84,8 @@ } = = - protected List applyCriteria(IdentityObject= SearchCriteria criteria, List types) throws Exception - { = - // First pass - filters = - if(criteria.isFiltered()) - { - if (criteria.getFilter() !=3D null) - { - filterByIdFilter(types, criteria.getFilter()); - } - - if (criteria.getValues() !=3D null && criteria.getValues().size()= > 0) - { - filterByAttributesValues(types, criteria.getValues()); - } - - } - - // Second pass - sort - - if (criteria.isSorted()) - { - if (criteria.getSortAttributeName() !=3D null) - { - sortByAttributeName(types, criteria.getSortAttributeName(), c= riteria.isAscending()); - } - else - { - sortByName(types, criteria.isAscending()); - } - } - - List results =3D types; - - // Third pass - cut the page - - if (criteria.isPaged()) - { - results =3D cutPageFromResults(results, criteria); - } - - return results; - } - protected List applyCriteriaRoles(IdentityObjectSearchCriteria cr= iteria, List roles) { //TODO: No criteria in RoleQueryBuilder for now... @@ -136,188 +93,5 @@ return roles; } = - //TODO: quick impl. should be reviewed - private void filterByAttributesValues(Collection types, Map attrs) throws Exception - { - Set toRemove =3D new HashSet(); - - for (IdentityType type : types) - { - //TODO: AttributeManager should have .getAttributes(type, names) = to improve and not obtain everything - Map presentAttrs =3D identitySession.getAttrib= utesManager().getAttributes(type); - - for (Map.Entry entry : attrs.entrySet()) - { - if (presentAttrs.containsKey(entry.getKey())) - { - Set given =3D new HashSet(Arrays.asList(ent= ry.getValue())); - Attribute attr =3D presentAttrs.get(entry.getKey()); - - Collection present =3D null; - - if (attr !=3D null) - { - present =3D attr.getValues(); - } - else - { - present =3D Collections.emptySet(); - } - = - for (String s : given) - { - if (!present.contains(s)) - { - toRemove.add(type); - break; - } - } - - } - else - { - toRemove.add(type); - break; - - } - } - } - - for (IdentityType type : toRemove) - { - types.remove(type); - } - - } - - //TODO: quick impl. should be reviewed - private void filterByIdFilter(List types, Strin= g filter) throws Exception - { - Set toRemove =3D new HashSet(); - - String regex =3D Tools.wildcardToRegex(filter); - = - - for (IdentityType type : types) - { - String id =3D null; - - if (type instanceof User) - { - id =3D type.getId(); - } - else if (type instanceof Group) - { - id =3D ((Group)type).getName(); - } - else - { - // shouldn't happen - throw new IllegalStateException(); - } - - if (!id.matches(regex)) - { - toRemove.add(type); - } - } - - for (IdentityType type : toRemove) - { - types.remove(type); - } - - } - - private void sortByName(List objects, final= boolean ascending) - { - Collections.sort(objects, new Comparator(){ - public int compare(T o1, T o2) - { - if (o1 instanceof User && o2 instanceof User) - { - if (ascending) - { - return o1.getId().compareTo(o2.getId()); - } - else - { - return o2.getId().compareTo(o1.getId()); - } - } - else - { - Group g1 =3D (Group)o1; - Group g2 =3D (Group)o2; - - if (ascending) - { - return g1.getName().compareTo(g2.getName()); - } - else - { - return g2.getName().compareTo(g1.getName()); - } - - } - } - }); - } - - private void sortByAttributeName(List objec= ts, String attributeName, final boolean ascending) = - throws Exception - { - - //TODO: Check if attribute has "text" type and delegate to name sort= if not - - // Pre fetch attributes - final Map attributes =3D new HashMap(); - - for (T object : objects) - { - Attribute attr =3D identitySession.getAttributesManager().getAttr= ibute(object, attributeName); - - if (attr !=3D null && attr.getValue() !=3D null) - { - attributes.put(object, attr.getValue().toString()); - } - else - { - attributes.put(object, ""); - } - } - - = - - Collections.sort(objects, new Comparator(){ - public int compare(T o1, T o2) - { - String a1 =3D attributes.get(o1); - String a2 =3D attributes.get(o2); - - if (ascending) - { - return a1.compareTo(a2); - } - else - { - return a2.compareTo(a1); - } - } - }); - } - - //TODO: dummy and inefficient... - private List cutPageFromResults(List obj= ects, IdentityObjectSearchCriteria criteria) - { - List results =3D new LinkedList(); - for (int i =3D criteria.getFirstResult(); i < criteria.getFirstResul= t() + criteria.getMaxResults(); i++) - { - if (i < objects.size()) - { - results.add(objects.get(i)); - } - } - return results; - } + = } Modified: idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/= query/GroupQueryExecutorImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/query/= GroupQueryExecutorImpl.java 2009-05-09 15:10:05 UTC (rev 487) +++ idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/query/= GroupQueryExecutorImpl.java 2009-05-09 21:28:54 UTC (rev 488) @@ -27,6 +27,7 @@ import org.jboss.identity.idm.api.IdentitySession; import org.jboss.identity.idm.api.query.QueryException; import org.jboss.identity.idm.impl.NotYetImplementedException; +import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl; = import java.util.Collection; import java.util.List; @@ -163,7 +164,7 @@ { = mainResults.add(uniqueResult); - applyCriteria(q.searchCriteria, mainResults); + IdentitySearchCriteriaImpl.applyCriteria(identitySession, q.se= archCriteria, mainResults); return mainResults; } else if (q.groupId =3D=3D null && @@ -318,7 +319,7 @@ } } = - applyCriteria(q.searchCriteria, mainResults); + IdentitySearchCriteriaImpl.applyCriteria(identitySession, q.searc= hCriteria, mainResults); } catch (Exception e) { Modified: idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/= query/UserQueryExecutorImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/query/= UserQueryExecutorImpl.java 2009-05-09 15:10:05 UTC (rev 487) +++ idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/query/= UserQueryExecutorImpl.java 2009-05-09 21:28:54 UTC (rev 488) @@ -27,6 +27,7 @@ import org.jboss.identity.idm.api.IdentitySession; import org.jboss.identity.idm.api.query.QueryException; import org.jboss.identity.idm.impl.NotYetImplementedException; +import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl; = import java.util.Collection; import java.util.List; @@ -111,7 +112,7 @@ resultsRelatedGroups.size() =3D=3D 0) { resultsMain.add(uniqueUser); - resultsMain =3D applyCriteria(q.searchCriteria, resultsMain); + resultsMain =3D IdentitySearchCriteriaImpl.applyCriteria(ident= itySession, q.searchCriteria, resultsMain); return resultsMain; } else if (q.userId =3D=3D null && @@ -203,7 +204,7 @@ // As results were merged criteria need to be applied separately if (resultsMain.size() > 0) { - resultsMain =3D applyCriteria(q.searchCriteria, resultsMain); + resultsMain =3D IdentitySearchCriteriaImpl.applyCriteria(ident= itySession, q.searchCriteria, resultsMain); } = } Modified: idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/= session/managers/RelationshipManagerImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/sessio= n/managers/RelationshipManagerImpl.java 2009-05-09 15:10:05 UTC (rev 487) +++ idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/sessio= n/managers/RelationshipManagerImpl.java 2009-05-09 21:28:54 UTC (rev 488) @@ -38,6 +38,7 @@ import org.jboss.identity.idm.spi.store.IdentityObjectSearchCriteriaType; import org.jboss.identity.idm.impl.NotYetImplementedException; import org.jboss.identity.idm.impl.api.session.managers.AbstractManager; +import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl; = import java.util.Collection; import java.util.Iterator; @@ -467,6 +468,28 @@ return true; } = + private Collection findAssociatedGroupsCascaded(Collection previous, Group group, String groupType, boolean parent, IdentitySearchCr= iteria criteria) throws IdentityException + { + Collection results =3D findAssociatedGroups(group, groupType,= parent, false, criteria); + + List newResults =3D new LinkedList(); + + + // For each result make recursive call unless it is already in previ= ous results + for (Group result : results) + { + if (!previous.contains(result)) + { + newResults.add(result); + previous.add(result); + newResults.addAll(findAssociatedGroupsCascaded(previous, resul= t, groupType, parent, criteria)); + } + } + + return newResults; + + } + public Collection findAssociatedGroups(Group group, String group= Type, boolean parent, boolean cascade, IdentitySearchCriteria criteria) thr= ows IdentityException { = @@ -477,17 +500,36 @@ = IdentityObjectType iot =3D groupType !=3D null ? getIdentityObjectTy= pe(groupType) : null; = - //TODO Handle cascade + + if (cascade) { - throw new NotYetImplementedException("Support for 'cascade' argum= ent is not yet implemented. Please use 'false' value for now"); + Set prev =3D new HashSet(); + prev.add(group); + identities =3D (List)findAssociatedGroupsCascaded(prev, gr= oup, groupType, parent, criteria); + + try + { + //TODO: don't perform when only one repository call was made = + if (criteria !=3D null) + { + IdentitySearchCriteriaImpl.applyCriteria(identitySession, c= onvertSearchControls(criteria), identities); + } + } + catch (Exception e) + { + throw new IdentityException("Failed to apply criteria", e); + } + + return identities; } = Collection ios =3D getRepository().findIdentityObjec= t(getInvocationContext(), createIdentityObject(group), MEMBER, parent, conv= ertSearchControls(criteria)); = for (IdentityObject io : ios) { - if (iot =3D=3D null || io.getIdentityType().getName().equals(iot.= getName())) + if ((iot =3D=3D null && !io.getIdentityType().getName().equals(ge= tUserObjectType().getName())) || + (iot !=3D null && io.getIdentityType().getName().equals(iot.ge= tName()))) { identities.add(createGroup(io)); } @@ -599,10 +641,37 @@ = List identities =3D new LinkedList(); = - //TODO Handle cascade if (cascade) { - throw new NotYetImplementedException("Support for 'cascade' argum= ent is not yet implemented. Please use 'false' value for now"); + // Do non cascaded call + + identities.addAll(findAssociatedUsers(group, false, criteria)); + + // Find all associated groups (cascaded) + Collection groups =3D findAssociatedGroups(group, null, tr= ue, true, criteria); + + + for (Group asociatedGroup : groups) + { + identities.addAll(findAssociatedUsers(asociatedGroup, false, c= riteria)); + } + + try + { + + //TODO: don't perform when only one repository call was made = + if (criteria !=3D null) + { + IdentitySearchCriteriaImpl.applyCriteria(identitySession, c= onvertSearchControls(criteria), identities); + } + } + catch (Exception e) + { + throw new IdentityException("Failed to apply criteria", e); + } + + return identities; + } = Collection ios =3D getRepository().findIdentityObjec= t(getInvocationContext(), createIdentityObject(group), MEMBER, true, conver= tSearchControls(criteria)); Modified: idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl= /api/APILDAPTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/A= PILDAPTestCase.java 2009-05-09 15:10:05 UTC (rev 487) +++ idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/A= PILDAPTestCase.java 2009-05-09 21:28:54 UTC (rev 488) @@ -109,6 +109,12 @@ } = @Test + public void testRelationshipManagerCascade() throws Exception + { + relationshipManagerTest.testCascade(getRealmName()); + } + + @Test public void testRelationshipManagerMergedRoleAssociations() throws Exce= ption { relationshipManagerTest.testMergedRoleAssociations(getRealmName()); Modified: idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl= /api/APITestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/A= PITestCase.java 2009-05-09 15:10:05 UTC (rev 487) +++ idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/A= PITestCase.java 2009-05-09 21:28:54 UTC (rev 488) @@ -106,6 +106,12 @@ } = @Test + public void testRelationshipManagerCascade() throws Exception + { + relationshipManagerTest.testCascade(getRealmName()); + } + + @Test public void testRelationshipManagerMergedRoleAssociations() throws Exce= ption { relationshipManagerTest.testMergedRoleAssociations(getRealmName()); Modified: idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl= /api/RelationshipManagerTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/R= elationshipManagerTest.java 2009-05-09 15:10:05 UTC (rev 487) +++ idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/R= elationshipManagerTest.java 2009-05-09 21:28:54 UTC (rev 488) @@ -29,6 +29,7 @@ import org.jboss.identity.idm.api.IdentitySearchCriteria; = import java.util.Arrays; +import java.util.Collection; = import junit.framework.Assert; = @@ -312,6 +313,73 @@ = } = + public void testCascade(String realmName) throws Exception + { + + IdentitySessionFactory factory =3D ctx.getIdentitySessionFactory(); + + IdentitySession session =3D factory.createIdentitySession(realmName); + + ctx.begin(); + + // Create stuff + User user1 =3D session.getPersistenceManager().createUser("user1"); + User user2 =3D session.getPersistenceManager().createUser("user2"); + User user3 =3D session.getPersistenceManager().createUser("user3"); + User user4 =3D session.getPersistenceManager().createUser("user4"); + User user5 =3D session.getPersistenceManager().createUser("user5"); + User user6 =3D session.getPersistenceManager().createUser("user6"); + User user7 =3D session.getPersistenceManager().createUser("user7"); + + Group group1 =3D session.getPersistenceManager().createGroup("group1= ", ORGANIZATION); + Group group2 =3D session.getPersistenceManager().createGroup("group2= ", ORGANIZATION); + Group group3 =3D session.getPersistenceManager().createGroup("group3= ", ORGANIZATION); + Group group4 =3D session.getPersistenceManager().createGroup("group4= ", ORGANIZATION); + Group group5 =3D session.getPersistenceManager().createGroup("group5= ", ORGANIZATION); + + + // Create looped associations + session.getRelationshipManager().associateGroups(group1, group2); + session.getRelationshipManager().associateGroups(group1, group3); + session.getRelationshipManager().associateGroups(group2, group4); + session.getRelationshipManager().associateGroups(group2, group5); + session.getRelationshipManager().associateGroups(group3, group1); + + // Assign users + session.getRelationshipManager().associateUser(group1, user1); + session.getRelationshipManager().associateUser(group2, user2); + session.getRelationshipManager().associateUser(group3, user3); + session.getRelationshipManager().associateUser(group5, user4); + session.getRelationshipManager().associateUser(group5, user5); + + + // Make sure that algorithm doesn't go in a loop + Collection results =3D session.getRelationshipManager(). + findAssociatedGroups(group1, ORGANIZATION, true, true); + + assertEquals(4, results.size()); + assertFalse(results.contains(group1)); + assertTrue(results.contains(group2)); + assertTrue(results.contains(group3)); + assertTrue(results.contains(group4)); + assertTrue(results.contains(group5)); + + + // And get all users associated in a tree + Collection results2 =3D session.getRelationshipManager(). + findAssociatedUsers(group1, true); + + assertEquals(5, results2.size()); + assertFalse(results2.contains(user6)); + assertFalse(results2.contains(user7)); + assertTrue(results2.contains(user1)); + assertTrue(results2.contains(user2)); + assertTrue(results2.contains(user3)); + assertTrue(results2.contains(user4)); + assertTrue(results2.contains(user5)); + + } + public void testMergedRoleAssociations(String realmName) throws Excepti= on { IdentitySessionFactory factory =3D ctx.getIdentitySessionFactory(); Modified: idm/trunk/integration/jboss5/pom.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/integration/jboss5/pom.xml 2009-05-09 15:10:05 UTC (rev 487) +++ idm/trunk/integration/jboss5/pom.xml 2009-05-09 21:28:54 UTC (rev 488) @@ -24,10 +24,25 @@ = org.jboss.identity - idm + idm-core ${version} + org.jboss.identity + idm-hibernate + ${version} + + + org.jboss.identity + idm-ldap + ${version} + + + org.jboss.identity + idm-cache + ${version} + + org.jboss.jbossas jboss-as-system-jmx ${jboss.version} Modified: idm/trunk/integration/jboss5/src/main/resources/assembly.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- idm/trunk/integration/jboss5/src/main/resources/assembly.xml 2009-05-09= 15:10:05 UTC (rev 487) +++ idm/trunk/integration/jboss5/src/main/resources/assembly.xml 2009-05-09= 21:28:54 UTC (rev 488) @@ -22,7 +22,10 @@ / org.jboss.identity.integration:idm-jboss5 - org.jboss.identity:idm + org.jboss.identity:idm-cache + org.jboss.identity:idm-ldap + org.jboss.identity:idm-hibernate + org.jboss.identity:idm-core org.jboss.identity:idm-api org.jboss.identity:idm-common org.jboss.identity:idm-spi --===============6178353889641472628==--