liferay login programmatically - liferay

I'm trying to create a custom login portlet for liferay because I also need to do some other things such as logging. However the problem I've stumbled on is that the portal-impl.jar seems to be shielded off so I can't use the loginutil class.
Now I don't want to modify how the actual login works so this is quite a bummer.
I've read something about being able to use something like ext(the explanation was quite vague) but that didn't seem like the cleanest solution.
I've got some experience at developing portlets, but I'm new at developing for liferay.

creating an "ext plugin", as it is called, is the best way to solve your problem.
This part of the documentation should be your first step.
First, you should identify in the portal.properties the properties to modify : be it another autologin in the pipeline, or an action triggered by the login action. I often use the first one for custom SSO actions, and the latter for auditing purposes.
Then create an ext plugin with your custom class (extending loginutil, for example) and create embed the portal-ext.properties needed to reference it.
That way, you should be able to have a clean package to deploy and undeploy ; customizing the jsps of the login portlet can also be done.
Arnaud

Why do you want to use the LoginUtil class?
If you really just want to add logging to the login you can maybe just create a post-login hook. This hook will intercept each user login so you can do your custom logic such as adding some logging with the user's information.
The advantage of this approach is that your code is completely separated from Liferay.

Related

How are Liferay Remote Services accessed from an application that's not a portlet?

When a user logs into the Liferay Portal I want to show a visualization of the list of files that they have access to. This visualization would be done using Javascript, but preferably not inside a portlet, but just being run on the Portal homepage.
I was looking into some of the JSON web service examples, but I was a bit confused on how to invoke some of the Liferay remote services to access the document files from an application that doesn't extend the Liferay portlet class.
Is this possible to do this from outside a portlet or would I need to implement something using URL parameters as referred in one of the Liferay examples? I don't know there is something I'm not understanding here.
EDIT: I want to implement these remote service requests for the visualization inside of a custom theme that I am using. Yet, due to Olaf's recommendation, I will look to see if implementing my visualization and service requests inside of a portlet would be a better solution to my needs.
Yes, it's possible. I'm not sure what you mean with "not inside a portlet, but just being run on the portal homepage" - typically everything that's displayed on the UI is encapsulated within a portlet (well, or within the theme - but for maintainability reasons I'd keep it out of the theme)
You'll need the p_auth token - how to obtain it is part of the documentation that you link (or the surrounding chapters)
If you run into specific problems, please edit your question and list them (and your code). Currently your question reads "Is this possible...?" and the answer to this is "Yes".

Liferay: Page to portlet mapping

I have a requirement in liferay portal to allow user to add some specific portlets on a particular page. Same can be done in 2 ways:
This will require some custom code to be plugged in add panel code
create a custom portlet which will be present on left hand
side of page and allows portlet to be added and dragged on page.
On add of portlet it checks if the page can have this portlet and accordingly remove it
The question I have is which of these 2 approaches shall be used, and how?
Note: I was unable to find much about this on google as well
I believe Liferay permission system is strong enough to express what you need.
The portlet list shown in "Add more portlets" menu can be customized through a Regular Role. See How to customize which portlets to show in “Add more portlets” menu for detailed info.
To restrict the options for a single page (or several pages), modify its permissions, so that only the new Regular Role is be able to update it.
Based on your comment to Tomáš Piňos's answer, my suggestion would be to create a custom portlet that uses Liferay's API and enables you to do just this: On the page where it's available, use it to enable/disable the portlets you'd like to be there by use of Liferay's API. You'll find quite a lot of sample when you're looking for the old sevencogs example (that sadly does not compile any more, but in general the API has only changed marginally). The most up to date resources with further links to the ancient code are these 2 blog articles.
About your third option (as you ask in the comments): Yes, it's possible: You can override Liferay's Services as well as react to model changes. This means that you could add your own check on updates. However, I'd feel it inappropriate to offer the option to add any portlet only to prohibit it whenever a user indeed uses the offered option. That's why I didn't include this option in my initial answer.

Using Liferay for an already developed project

First of all, let me tell you what I am or my company is intended to do. We have already developed a project using Java, JSP and Servlet. We want it to integrate with Liferay so that we can change logo, css, images, themes or any other UI related component at run time using Liferay admin panel. But backend should be what we have developed.
In short, the UI of our project is controlled by Liferay, but control of data displayed on UI or submitted from UI should be from our developed backend code.
Now I have a few questions regarding above said approach of fulfilling the requirement:
What we are trying to do is possible?
Is this approach recommendable for what we intended to do?
Or do we need to develop our project from scratch to fit into Liferay? Like developing portlets and deploying in Liferay or other approach that has been given in Liferay documentation.
What about database integration? We have around 15 columns/fields in user table in database of our project which is completely different from that of Liferay's user table.
Liferay is a very new for us. We have checked the documentation section of Liferay but still few things like above said requirements and its implementation is not clear. Also, we would like to know in what scenarios/requirements Liferay is useful.
Ok let me try to answer your question point-wise and I would answer your last question first, which should automatically clear other questions:
Q. Also, we would like to know in what scenarios/requirements Liferay is useful.
This can have a very wide answer, but I have made it shorter for you:
If your site is content heavy and not data heavy then go for Portal
If you plan to use only a single web-application in a portal then I would suggest standalone custom developed web-application is much better.
I agree liferay portal will give you lot of things out-of-box like Single Sign-on, authorization, authentication, friendly-url and page creation and also lot of applications like Blogs, Wikis, Document library, some social networking apps etc. But think about it, do you really need all this? if not, then this is overkill
Here are some really nice links to better understand a portal's usage:
When to use a portal
Why to use portal technology
liferay tag wiki: It has nice description as to what is liferay and it also contains relevant links to Admin guide which will tell you what all functionalities liferay has and how you can manage it.
So still if you find your other questions unanswered, read-on ...
Q1. What we are trying to do is possible?
Nope. Portlet technology is different from Servlet technology. Liferay (or anyother portal) does not provide a way (atleast a simple one) to integrate servlets that would render pages inside a portal. For eg: Since with servlet you define URL mappings for a particular servlets before-hand in a web.xml but in a portal the URLs are generated by the Portlet Container. So portals work with portlets and not Servlets.
Q2. Is this approach recommendable for what we intended to do?
Nope. As I already explained in Q1.
Q3. Or do we need to develop our project from scratch to fit into Liferay? Like developing portlets and deploying in Liferay or other approach that has been given in Liferay documentation.
If you want to go the liferay way then Yes.
If you want to build applications that talk to your custom tables then portlets are the way to go.
Q4. What about database integration? We have around 15 columns/fields in user table in database of our project which is completely different from that of Liferay's user table.
If you go with Liferay. In this scenario you can create a combination of liferay-hook & portlet (may be using service-builder) to customize liferay's User creation mechanism and there by store data in both Liferay's User table and your custom tables.
Liferay's permission system is really fine-grained so you can also benefit from this system and put permission even on the data level.
In conclusion I would say:
Everything boils down to what your requirements are and what resources you have. And sometimes what future requirements you can have.
Note: All the terms used in this answer which are specific to liferay (like service-builder, hook etc) are explained in the liferay tag wiki.
Hope this helps. If you would like to know anything specific I would gladly update my answer.

Unable to add a custom attribute to User model in Liferay

I have a task at hand where I need to add an attribute (Home Page) to user model without making changes in liferay source code i.e. modifying the service.xml and regenerating the service.
I searched a lot on this but nothing seems to work. Used hook to override the create account page and all. Does anyone has step by step solution for this?
Only the steps will do as I just need guidance on this.
Thanks
Mohit
I think you should be able to add custom attributes just by using the control panel.
This link should give you an idea.

SharePoint Custom Web Part With Active Directory

I am currently working on a custom SharePoint web part (WSS 3.0, not MOSS) that will pull in information for all of the users in Active Directory to build an up to date employee directory. This web part shows things like phone number, address, and other similar fields. The issue that I am having is that, by default, the SharePoint web site on IIS is running as the user IUSR_. This user does not have access to Active Directory, so I am unable to retrieve any user information.
To get around this for testing I have hard coded the credentials for a test user which I added just for this purpose. This, obviously, is not ideal. If anyone removes this user or if they ever change the password then the web part will break and they will have no way to fix it (they have no in-house developers to take it over once I am finished here). To fix this problem, I would like to make the Username/Password custom properties on the web part so I can pass those to Active Directory to retrieve the information I need. The issue I am having with this is that the password is stored in plain text so anyone can read it. I would like it to display as ******** or something similar. Is there a way to make a custom property on a web part a password type?
If this isn't possible, can anyone recommend another way to accomplish what I am trying to do? At this time I cannot change the user that the SharePoint website runs as. Although, if I cannot find any other solutions I will try again to persuade them.
Thanks in advance!
We use a service account for that. That service account is solely used for that. Something like DOMAIN\SPS_AD_READ_CUSTOMER
In our documentation that we deliver when putting the application in production that account is put in the list of stuff that is needed to make the webpart run. If the webpart ever fails, the ITPro can go to the chapter and check if everything is still ok.
It's not ideal, but I don't really know another way on how to fix it.
I would go with custom Editor Part, then set up a control of TextBox with property TextBoxMode set to Password, then override methods from type EditorPart - SynchChanges() and ApplyChanges() to set and retrieve values.
tip: override method CreateEditorParts of a WebPart type to start with.

Resources