Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNPORTAL-2899 Support * wildcard membership type
Browse files Browse the repository at this point in the history
  • Loading branch information
trongtt committed Oct 23, 2013
1 parent fdc4c8a commit b7ba8ed
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 393 deletions.
7 changes: 0 additions & 7 deletions component/identity/pom.xml
Expand Up @@ -75,19 +75,12 @@
<artifactId>picketlink-idm-cache</artifactId>
</dependency>

<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>exo.portal.component.test.core</artifactId>
<scope>test</scope>
</dependency>



</dependencies>

<build>
Expand Down
Expand Up @@ -32,9 +32,10 @@
import org.exoplatform.services.organization.Group;
import org.exoplatform.services.organization.GroupEventListener;
import org.exoplatform.services.organization.GroupHandler;
import org.exoplatform.services.organization.MembershipTypeHandler;
import org.gatein.common.logging.LogLevel;
import org.picketlink.idm.api.Attribute;
import org.picketlink.idm.api.IdentitySession;
import org.picketlink.idm.api.Role;
import org.picketlink.idm.impl.api.SimpleAttribute;

/*
Expand Down Expand Up @@ -91,8 +92,6 @@ public void addChild(Group parent, Group child, boolean broadcast) throws Except

org.picketlink.idm.api.Group parentGroup = null;

String childPLGroupName = getPLIDMGroupName(child.getGroupName());

if (parent != null) {

String parentPLGroupName = getPLIDMGroupName(parent.getGroupName());
Expand Down Expand Up @@ -201,7 +200,7 @@ public Group removeGroup(Group group, boolean broadcast) throws Exception {
.findAssociatedGroups(jbidGroup, null, false, false);

// not possible to disassociate only one child...
Set dummySet = new HashSet();
Set<org.picketlink.idm.api.Group> dummySet = new HashSet<org.picketlink.idm.api.Group>();
dummySet.add(jbidGroup);

for (org.picketlink.idm.api.Group parent : parents) {
Expand All @@ -225,12 +224,12 @@ public Group removeGroup(Group group, boolean broadcast) throws Exception {
return group;
}

public Collection findGroupByMembership(String userName, String membershipType) throws Exception {
public Collection<Group> findGroupByMembership(String userName, String membershipType) throws Exception {
if (log.isTraceEnabled()) {
Tools.logMethodIn(log, LogLevel.TRACE, "findGroupsByMembership", new Object[] { "userName", membershipType });
}

Collection<org.picketlink.idm.api.Role> allRoles = new HashSet();
Collection<Role> allRoles = new HashSet<Role>();

try {
orgService.flush();
Expand All @@ -252,7 +251,64 @@ public Collection findGroupByMembership(String userName, String membershipType)
}

if (mmm.isAssociationMapped() && mmm.getAssociationMapping().equals(membershipType)) {
Collection<org.picketlink.idm.api.Group> groups = new HashSet();
Collection<org.picketlink.idm.api.Group> groups = new HashSet<org.picketlink.idm.api.Group>();

try {
orgService.flush();

groups = getIdentitySession().getRelationshipManager().findAssociatedGroups(userName, null);
} catch (Exception e) {
handleException("Identity operation error: ", e);
}

for (org.picketlink.idm.api.Group group : groups) {
exoGroups.add(convertGroup(group));
}

}

// UI has hardcoded casts to List
Collection<Group> result = new LinkedList<Group>(exoGroups);

if (log.isTraceEnabled()) {
Tools.logMethodOut(log, LogLevel.TRACE, "findGroupByMembership", result);
}

return result;
}


@Override
public Collection<Group> resolveGroupByMembership(String userName, String membershipType) throws Exception {
if (log.isTraceEnabled()) {
Tools.logMethodIn(log, LogLevel.TRACE, "findGroupsByMembership", new Object[] { "userName", membershipType });
}

Collection<Role> roles = new HashSet<Role>();

try {
orgService.flush();

roles.addAll(getIdentitySession().getRoleManager().findRoles(userName, membershipType));

roles.addAll(getIdentitySession().getRoleManager().findRoles(userName, MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
} catch (Exception e) {
handleException("Identity operation error: ", e);
}

Set<Group> exoGroups = new HashSet<Group>();

MembershipDAOImpl mmm = (MembershipDAOImpl) orgService.getMembershipHandler();

for (org.picketlink.idm.api.Role role : roles) {
Group exoGroup = convertGroup(role.getGroup());
if (mmm.isCreateMembership(role.getRoleType().getName(), exoGroup.getId())) {
exoGroups.add(exoGroup);
}
}

if (mmm.isAssociationMapped() && mmm.getAssociationMapping().equals(membershipType)) {
Collection<org.picketlink.idm.api.Group> groups = new HashSet<org.picketlink.idm.api.Group>();

try {
orgService.flush();
Expand All @@ -269,7 +325,7 @@ public Collection findGroupByMembership(String userName, String membershipType)
}

// UI has hardcoded casts to List
Collection result = new LinkedList<Group>(exoGroups);
Collection<Group> result = new LinkedList<Group>(exoGroups);

if (log.isTraceEnabled()) {
Tools.logMethodOut(log, LogLevel.TRACE, "findGroupByMembership", result);
Expand Down Expand Up @@ -304,7 +360,7 @@ public Group findGroupById(String groupId) throws Exception {

}

public Collection findGroups(Group parent) throws Exception {
public Collection<Group> findGroups(Group parent) throws Exception {
if (log.isTraceEnabled()) {
Tools.logMethodIn(log, LogLevel.TRACE, "findGroups", new Object[] { "parent", parent });
}
Expand All @@ -330,8 +386,6 @@ public Collection findGroups(Group parent) throws Exception {
return Collections.emptyList();
}

String parentId = parent == null ? null : parent.getParentId();

Set<org.picketlink.idm.api.Group> plGroups = new HashSet<org.picketlink.idm.api.Group>();

try {
Expand Down Expand Up @@ -396,7 +450,7 @@ public Collection findGroups(Group parent) throws Exception {

}

public Collection findGroupsOfUser(String user) throws Exception {
public Collection<Group> findGroupsOfUser(String user) throws Exception {

if (log.isTraceEnabled()) {
Tools.logMethodIn(log, LogLevel.TRACE, "findGroupsOfUser", new Object[] { "user", user });
Expand All @@ -422,7 +476,7 @@ public Collection findGroupsOfUser(String user) throws Exception {
return Collections.emptyList();
}

Collection<org.picketlink.idm.api.Group> allGroups = new HashSet();
Collection<org.picketlink.idm.api.Group> allGroups = new HashSet<org.picketlink.idm.api.Group>();

try {
orgService.flush();
Expand All @@ -448,7 +502,7 @@ public Collection findGroupsOfUser(String user) throws Exception {
return exoGroups;
}

public Collection getAllGroups() throws Exception {
public Collection<Group> getAllGroups() throws Exception {
if (log.isTraceEnabled()) {
Tools.logMethodIn(log, LogLevel.TRACE, "getAllGroups", null);
}
Expand Down Expand Up @@ -490,7 +544,7 @@ public Collection getAllGroups() throws Exception {
}

// UI has hardcoded casts to List
Collection result = new LinkedList<Group>(exoGroups);
Collection<Group> result = new LinkedList<Group>(exoGroups);

if (log.isTraceEnabled()) {
Tools.logMethodOut(log, LogLevel.TRACE, "getAllGroups", result);
Expand Down Expand Up @@ -529,7 +583,7 @@ protected Group convertGroup(org.picketlink.idm.api.Group jbidGroup) throws Exce
Tools.logMethodIn(log, LogLevel.TRACE, "convertGroup", new Object[] { "jbidGroup", jbidGroup });
}

Map<String, Attribute> attrs = new HashMap();
Map<String, Attribute> attrs = new HashMap<String, Attribute>();

try {
orgService.flush();
Expand Down Expand Up @@ -616,7 +670,7 @@ private String getGroupId(org.picketlink.idm.api.Group jbidGroup, List<org.picke
processed = new LinkedList<org.picketlink.idm.api.Group>();
}

Collection<org.picketlink.idm.api.Group> parents = new HashSet();
Collection<org.picketlink.idm.api.Group> parents = new HashSet<org.picketlink.idm.api.Group>();

String gtnGroupName = getGtnGroupName(jbidGroup.getName());

Expand Down Expand Up @@ -844,5 +898,4 @@ public String getPLIDMGroupName(String gtnGroupName) {
public String getGtnGroupName(String plidmGroupName) {
return orgService.getConfiguration().getGtnGroupName(plidmGroupName);
}

}
Expand Up @@ -34,7 +34,6 @@
import org.exoplatform.services.organization.MembershipTypeHandler;
import org.exoplatform.services.organization.impl.MembershipTypeImpl;
import org.gatein.common.logging.LogLevel;
import org.picketlink.idm.api.IdentitySession;
import org.picketlink.idm.api.RoleType;

/*
Expand Down Expand Up @@ -183,7 +182,7 @@ public MembershipType removeMembershipType(String name, boolean broadcast) throw

}

public Collection findMembershipTypes() throws Exception {
public Collection<MembershipType> findMembershipTypes() throws Exception {
if (log.isTraceEnabled()) {
Tools.logMethodIn(log, LogLevel.TRACE, "findMembershipTypes", null);
}
Expand All @@ -201,7 +200,11 @@ public Collection findMembershipTypes() throws Exception {
for (RoleType rt : rts) {
MembershipType mt = new MembershipTypeImpl(rt.getName(), null, null);
populateMembershipType(mt);
mts.add(mt);
if (mt.getName().equals("*")) {
mts.add(0, mt);
} else {
mts.add(mt);
}
}

if (log.isTraceEnabled()) {
Expand Down
Expand Up @@ -26,6 +26,7 @@
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.exoplatform.commons.utils.PageList;
Expand Down Expand Up @@ -332,6 +333,14 @@ public void testGroup() throws Exception {
groupHandler_.removeGroup(groupParent, true);
assertEquals("Expect ParentGroup is removed:", null, groupHandler_.findGroupById(groupParent.getId()));
assertEquals("Expect all child group is removed: ", 0, groupHandler_.findGroups(groupParent).size());

Collection<Group> groups = groupHandler_.findGroupByMembership("demo", "member");
assertNotNull(groups);
assertEquals(1, groups.size());

groups = groupHandler_.resolveGroupByMembership("demo", "member");
assertNotNull(groups);
assertEquals(2, groups.size());
}

@Test
Expand All @@ -358,20 +367,21 @@ public void testMembershipType() throws Exception {
mtHandler_.createMembershipType(mt, true);

/*
* find all membership type Expect result: 3 membershipType: "testmembership", "anothertype" and "member"(default
* find all membership type Expect result: 4 membershipType: "testmembership", "anothertype", "member" and "*" (default
* membership type, it is created at startup time)
*/
assertEquals("Expect 3 membership in collection: ", 3, mtHandler_.findMembershipTypes().size());
assertEquals("Expect 4 membership in collection: ", 4, mtHandler_.findMembershipTypes().size());
assertEquals("The * should be the first one in collection: ", MembershipTypeHandler.ANY_MEMBERSHIP_TYPE, mtHandler_.findMembershipTypes().iterator().next().getName());

/* remove "testmembership" */
mtHandler_.removeMembershipType(testType, true);
assertEquals("Membership type has been removed:", null, mtHandler_.findMembershipType(testType));
assertEquals("Expect 2 membership in collection(1 is default): ", 2, mtHandler_.findMembershipTypes().size());
assertEquals("Expect 2 membership in collection(1 is default): ", 3, mtHandler_.findMembershipTypes().size());

/* remove "anothertype" */
mtHandler_.removeMembershipType("anothertype", true);
assertEquals("Membership type has been removed:", null, mtHandler_.findMembershipType("anothertype"));
assertEquals("Expect 1 membership in collection(default type): ", 1, mtHandler_.findMembershipTypes().size());
assertEquals("Expect 1 membership in collection(default type): ", 2, mtHandler_.findMembershipTypes().size());
/* All membershipType was removed(except default membership) */
}

Expand Down
Expand Up @@ -189,6 +189,16 @@
<object type="org.exoplatform.services.organization.OrganizationConfig">
<field name="membershipType">
<collection type="java.util.ArrayList">
<value>
<object type="org.exoplatform.services.organization.OrganizationConfig$MembershipType">
<field name="type">
<string>*</string>
</field>
<field name="description">
<string>Any membership type</string>
</field>
</object>
</value>
<value>
<object type="org.exoplatform.services.organization.OrganizationConfig$MembershipType">
<field name="type">
Expand All @@ -212,12 +222,24 @@
<field name="parentId">
<string></string>
</field>
<!--<field name="type"><string>hierachy</string></field>-->
<field name="description">
<string>the /users group</string>
</field>
</object>
</value>
<value>
<object type="org.exoplatform.services.organization.OrganizationConfig$Group">
<field name="name">
<string>administrators</string>
</field>
<field name="parentId">
<string></string>
</field>
<field name="description">
<string>the /administrators group</string>
</field>
</object>
</value>
</collection>
</field>

Expand All @@ -241,7 +263,7 @@
<string>demo@localhost</string>
</field>
<field name="groups">
<string>member:/users</string>
<string>member:/users, *:/administrators</string>
</field>
</object>
</value>
Expand Down
Expand Up @@ -241,7 +241,7 @@ public List<String> getMakableNavigations(String remoteUser, boolean withSite) t
if (remoteUser.equals(userACL_.getSuperUser())) {
groups = orgService_.getGroupHandler().getAllGroups();
} else {
groups = orgService_.getGroupHandler().findGroupByMembership(remoteUser, userACL_.getMakableMT());
groups = orgService_.getGroupHandler().resolveGroupByMembership(remoteUser, userACL_.getMakableMT());
}

//
Expand Down
5 changes: 5 additions & 0 deletions component/web/api/pom.xml
Expand Up @@ -48,5 +48,10 @@
<artifactId>exo.portal.component.test.core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.exoplatform.tool</groupId>
<artifactId>exo.tool.framework.junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

0 comments on commit b7ba8ed

Please sign in to comment.