Login Portlet Hook, class not found PwdEncryptor - liferay

I create a hook for login portlet.
I have problem with this line of code:
String encPwd = PwdEncryptor.encrypt(password, user.getPassword());
The class PwdEncryptor not found and package com.liferay.portal.security.pwd does not exist
I use a Liferay 6.0.6 plugin to create a hook and i read this:
Developing a CAS (Custom Authentication System)
and:
https://www.liferay.com/es/community/forums/-/message_boards/message/14773767
PwdEncryptor is in portal-impl.jar so it's not visible to plugins. What you could use is PortalClassInvoker to invoke it. If you need example check out com.liferay.portal.kernel.struts.PortletActionInvoker class.
I don't know what to do with this invoker, where to call it or use it.

integrade PwdEncryptor and Crypt.

Related

Hybris CDC customize GigyaLoginAddon, GigyaFacades and GigyaServices

I need to customize this OOTB extensions, in order to achieve this and create my own custom logic which are the steps that I must follow? Do I have to create through ant extgen a new extension based on Gigya template (if this exists) and there override the beans or can I just override the bean in my trainingfacades extension?
When you want to change a facade or service you can just extend the default implementation and override the public method you want to change. An example is the product service here:
public class TrainingGigyaServiceImpl extends DefaultGigyaService implements GigyaService
{
// Override your methods here
}
Then define a unique bean for it and override the only the alias with your newly created bean id:
<alias name="trainingGigyaService" alias="gigyaService"/>
Make also sure you load the gigya* extensions before your training extension by adding it to the extensioninfo.xml
This process of overriding is also more elaborated on the SAP help page https://help.sap.com/viewer/aa417173fe4a4ba5a473c93eb730a417/v2105/en-US/034a7f51580e45b19d67c51cc3e6a6dc.html

Sending custom objects across portlets in liferay

I'm having serious issues trying to send share custom objects between portlets in liferay. I have a Hook Plugin, with a servlet filter, which loads an object of Type MyCustomClass and inserts it into the request object as a parameter.
When i try to read this object in a portlet's render() i get a ClassCastException, though i am casting the object to the same class.
I understand that liferay plugins have different contexts, and i already tried to change the classloader before loading the object in the bean and portlet like this:
ClassLoader portalcl = PortalClassLoaderUtil.getClassLoader();
ClassLoader currentcl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(portalcl);
//do my stuff
Thread.currentThread().setContextClassLoader(currentcl);
however, it did not solved the problem, and the only way i found to solve the problem is to serialize the object into a json string, and deserialize it whenever i need it.
Isn't this kinda lame ? Does anyone know a better solution ?
Regards, DS
It sounds like the main problem you're seeing is that two different class loaders are loading the class which techncally makes them different classes (which it seems like you've already determined).
I haven't used LifeRay much but this has been a problem I've seen on other platforms as well. We were using WebSphere and solved this problem by putting the common MyCustomClass into a shared library that was on the server classpath. This way the server will load the class and make it available to all applications on the server through the server's single classloader. If you let each application load the class then you'll keep seeing this exception.

How to override property "sites.email.membership.reply.body" in liferay

I want override the following properties in my portal-ext.properties:
sites.email.membership.reply.subject=com/liferay/portlet/sites/dependencies/email_membership_reply_subject.tmpl
sites.email.membership.reply.body=com/liferay/portlet/sites/dependencies/email_membership_reply_body.tmpl
sites.email.membership.request.subject=com/liferay/portlet/sites/dependencies/email_membership_request_subject.tmpl
sites.email.membership.request.body=com/liferay/portlet/sites/dependencies/email_membership_request_body.tmpl
to something like this:
sites.email.membership.reply.subject=com/krishna/email_membership_reply_subject.tmpl
sites.email.membership.reply.body=com/krishna/email_membership_reply_body.tmpl
sites.email.membership.request.subject=com/krishna/email_membership_request_subject.tmpl
sites.email.membership.request.body=com/krishna/email_membership_request_body.tmpl
I have done this in EXT, i.e. I have created the package: ext-impl/src/com/krishna/ in EXT-plugin and it works fine, but I am not able to do this in a hook or portlet. Why? Because its giving me exception:
java.io.IOException: Unable to open resource in class loader com/krishna/email_membership_request_subject.tmpl
So, my question: Is there a way to do it in hook or portlet or only EXT can be used?
Thanks
This can be done only in an EXT plugin. Because of the following two reasons:
Hooks can be advantageous to override few properties/services but not all. This particular property is not supported by hooks.
This is definitely not possible with portlets, as you already are facing class loading issues. As portal-impl.jar is located inside the ROOT/WEB-INF/lib of liferay and your portlet doesn't have access to it.
So EXT plugin is the only way.

adding custom methods in Hook environment?

i am adding a new method into CalEventLocalServiceImpl using hook...
my code is ..
public class MyCalendarLocalServiceImpl extends CalEventLocalServiceWrapper {
public MyCalendarLocalServiceImpl(CalEventLocalService calEventLocalService) {
super(calEventLocalService);
// TODO Auto-generated constructor stub
}
public List getUserData(long userId) throws SystemException{
DynamicQuery query=DynamicQueryFactoryUtil.forClass(CalEvent.class)
.add(PropertyFactoryUtil.forName("userId").eq(userId));
List deatils=CalEventLocalServiceUtil.dynamicQuery(query);
return deatils;
}
}
liferay-hook.xml:
<service>
<service-type>
com.liferay.portlet.calendar.service.CalEventLocalService
</service-type>
<service-impl>
com.liferay.portlet.calendar.service.impl.MyCalendarLocalServiceImpl
</service-impl>
</service>
my question is how to use getUserData from jsp file.
Can anybody help me out....
i think u didn't gt my question...i want list of events based on USERID from Calendar ...to achieve this task what i need to do??
I assume getUserData() is not overridden but a new method (can't look up currently). This is not what you can do when overriding a service. Instead you'd have to add a new Service and make it available to the portal.
Remember that a customized ("hooked") jsp is running in the portal classloader, while your overloaded service is running in the hook's classloader. Thus, if you create a new service and make the service.jar available to Liferay (e.g. on the global classpath) you can call it from JSPs. The interface of Liferay services can not be extended through an overloaded service.
In case getUserData() is already in the interface (as I said I can't look up currently), you just need to call the CalendarLocalServiceUtil from your jsp and it will be delegated to your wrapper.
Just to add to Olaf's answer and comments...
if you you want to extend CalEventLocalService service with just "getUsetData" and use it in one jsp than building your own service might be overkill. Simply put your code from "getUserData" in jsp. Otherwise follow Olaf's suggestions.

Kohana: Adapting Mixu's Auth Useradmin Template

I'm looking at Mixu's Auth module for Kohana 3.1 but want to implement the UI into my own site templates. At the moment my site runs properly using its own template until it gets to a restricted page. At that point it loads the useradmin module's template for logins. I'd like to just load the page components into my own template and navigation.
What is the best way to go about this please? I had imagined I would be able to arrest the flow at some point within my 'application' environment without editing the 'module' environment.
EDIT:
I'm a little further along now. I've created two Controller classes:
application/classes/controller/app.php
application/classes/controller/user.php
Each extends the module class and replaces the template reference. Eg:
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_User extends Useradmin_Controller_User {
public $template = 'smarty:maintemplate';
}
I guess this is the right approach. I'm using Smarty Templates which is compounding the issues as I need to merge different templates. I'll keep plugging away and see how I go.
I don't know about the best way, but I had a similar situation.
In the end, I copied part of the code from the module that I needed, and rolled my own implementation of the module.
Btw. Smarty is ok, but Kostache (Mustache for Kohana) rocks. More flexible and you can use the same templates for php and javascript.

Resources