In eXo Platform, when a new user is registered, the membership: member:/platform/users will be automatically granted to him/her. See Predefined users, groups and memberships to futher understand the membership concept.
With the extension mechanism provided by eXo Platform, you can set another auto-membership for users.
It is assumed that you want to auto-assign 2 memberships: member:/platform/users and member:platform/web-contributors to any registered user, do as follows:
Create a file named organization-configuration.xml
under custom-extension.war!/WEB-INF/conf/organization
.
See the sample content of complete configuration in the platform-extension.war!/WEB-INF/conf/organization/organization-configuration.xml
file.
Add the following plugin for the new user event listener in custom-extension.war!/WEB-INF/conf/organization/organization-configuration.xml
:
<component-plugin>
<name>new.user.event.listener</name>
<set-method>addListenerPlugin</set-method>
<type>org.exoplatform.services.organization.impl.NewUserEventListener</type>
<description>this listener assign group and membership to a new created user</description>
<init-params>
...
</init-params>
</component-plugin>
Add the NewUserConfig
object, which holds the value of group and membership, in custom-extension.war!/WEB-INF/conf/organization/organization-configuration.xml
:
<object type="org.exoplatform.services.organization.impl.NewUserConfig">
<field name="group">
<collection type="java.util.ArrayList">
<value>
<object type="org.exoplatform.services.organization.impl.NewUserConfig$JoinGroup">
<field name="groupId"><string>/platform/users</string></field>
<field name="membership"><string>member</string></field>
</object>
</value>
<value>
<object type="org.exoplatform.services.organization.impl.NewUserConfig$JoinGroup">
<field name="groupId"><string>/platform/web-contributors</string></field>
<field name="membership"><string>member</string></field>
</object>
</value>
</collection>
</field>
</object>
Restart the server.
Create a new user, for example "katie", without assigning her to any group.
When invoking the createUser
method, you must set the broadcast
parameter to true
:
userHandler.createUser(newUser, true);
Then, userHandler
will broadcast an event
to org.exoplatform.services.organization.impl.NewUserEventListener
which will assign the created user to
the /platform/users and /platform/web-contributors groups
with the member membership type.
Check the membership for the newly created user by selecting → → . Next, click corresponding to your newly created user (for example, "katie"), then select User Membership. You will see that 2 memberships are auto-assigned to "katie".
You can modify the attributes and add the name of a special user that does not use the default membership. Here is an example of this specific case:
<field name="ignoredUser">
<collection type="java.util.HashSet">
<value>
<string>newuser</string>
</value>
</collection>
</field>