broschb
broschb

Reputation: 5006

liferay enable organization or community by role

I am working on a new liferay implementation. I have all of my users in an external system, and have used the external env. to authenticate through my own authentication system. I also store roles in this same system. I have been able to successfully pass these to liferay so that all of my users roles are available in liferay.

I would like to create an organization or community that is associated with a role. For example if I have a role called 'myusers' in my external system, I would like to tie that role to an organization or community in liferay. Then when a user logged in to liferay with that role, they would be able to be part of that organization or community. Is this possible in liferay? I know it's kind of backwards to the normal flow in liferay of adding roles to users and then adding user to a community or organization.

Upvotes: 0

Views: 2271

Answers (2)

Yasser
Yasser

Reputation: 575

You can modify the below code to check if the user belongs to a role and then add him to the appropriate organization.

To add a user to all Organizations:

public final static void addAllOrganizationstoUser(long userId) throws SystemException, PortalException {
    // gets all organizations
    List<Organization> organizations = OrganizationLocalServiceUtil.getOrganizations(ALL_POS, ALL_POS);
    long[] users = new long[]{userId};
    // register user to orgs
    for (Organization organization : organizations) {
      UserLocalServiceUtil.addOrganizationUsers(organization.getOrganizationId(), users);
    }
}

Upvotes: 1

broschb
broschb

Reputation: 5006

What I ended up doing was using the expando functionality built into liferay. Doing this I allow for entering a list of roles that should map to that organization. This allows me to look at the roles of my users when they login and determine what organizations they should be a member of. I then programatically add/remove the users from the organizations based upon the roles defined in the expando attribute and the roles assigned to the user.

Upvotes: 0

Related Questions