问题
In the web application I'm working,
- I've created an organization site which can be accessed by
group/game/home
. - I've made this default landing page after login. By putting this value in the portal-ext.properties file
default.landing.page.path=/group/games/home
- I've also set these two properties to make sure the user is redirected to the default landing page after successfully login.
layout.show.portlet.access.denied=false auth.login.url=/web/guest/login
Now, when I add a new user to the application, the user is created successfully.
But, since the user is not added to the organization, it doesn't have right to access the default landing page.
I have to manually login through admin panel and go to control panel > User and Organisation and then Update Association.
Can someone please help me understand if this can be done at the time of user creation? Is it doable?
NOTE
I'm using Liferay 6.2, Ankit P's suggestion worked for me.
If anyone is using earlier version, Please refer to Prakash K's suggestion.
回答1:
You can set this association by default from UI starting from Liferay v6.2+.
- Login as administrator and navigate to
- Control Panel → Portal Settings → Users (Under Configuration) → Select Default User Associations
- Add your desired Organization Name and Save.
This setting will automatically associate Users to that particular organization when Users are created.
You can also tick the Apply to Existing Users
checkbox to update the association for Users already created in database, the User in this case associated when the User logs in to the system first time after this setting.
Hope it helps !
回答2:
Note: The following solution is for Liferay 6.1 and for later versions like Liferay 6.2 you directly have a configuration option as explained by Ankit P in his answer
Is it doable?
No and Yes.
It cannot be done through configuration alone, but can be achieved with some development effort.
There are various ways to achieve this. The simplest I can think of is with a ModelListener hook, following is a short tutorial:
- Create a hook project.
Define the following in your
liferay-hook.xml
:<hook> <portal-properties>portal.properties</portal-properties> </hook>
Create a
portal.properties
file in your src folder and add the following:value.object.listener.com.liferay.portal.model.User=com.my.hook.listeners.MyCustomUserListener
Create the class
MyCustomUserListener
class by extendingBaseModelListener<User>
:public class MyCustomUserListener extends BaseModelListener<User> { @Override public void onAfterCreate(User model) throws ModelListenerException { // Your code to associate the user with an Organization // sample code is as follows: long userId = model.getUserId(); // since the method adds multiple users at one go to the Organization long[] userIds = new long[] {userId}; UserLocalServiceUtil.addOrganizationUsers(organizationId, userIds); } }
Build and deploy.
- Now whenever a User is created, the
onAfterCreate
method would be called.
But what will you do for Users who are already created?
- You can either create a one-time process (through a portlet or as an UpgradeProcess in the above hook) to associate all the User to the Organization.
- Or else you can create a Custom Action hook (with login post event), which will be called after the User has successfully logged-in and will associate the user to the Organization.
- Here is a good tutorial in the developer guide for this.
Hope this helps.
回答3:
After adding user to Liferay. You can use below code to add user to Organization
UserLocalServiceUtil.addOrganizationUser(organizationId,userId);
OrganizationLocalServiceUtil.updateOrganization(organization, true);
来源:https://stackoverflow.com/questions/22643733/giving-access-to-organization-pages-to-new-user