I am implementing Liferay 6.2 AuthVerifier. I developed it but it does not get called that is, TestAuthVerifier.verify() method.
I referred https://docs.liferay.com/portal/6.2/propertiesdoc/portal.properties.html the link to develop tthe est AuthVerifer. Here is what I do below
I make entries in portal-ext.properties file as below and develop the class further.
auth.verifier.pipeline=com.test.TestAuthVerifier
auth.verifier.TestAuthVerifier.version.supported=1.0
my code is as below just for reference.
package comt.test;
import com.liferay.portal.security.auth.*;
public class TestAuthVerifier implements AuthVerifier {
#Override
public String getAuthType() {
return PhAuthVerifier.class.getSimpleName();
}
#Override
public AuthVerifierResult verify(
AccessControlContext accessControlContext, Properties properties)
throws AuthException {
System.out.println("MyAuthVerifier.verify() invoked..")
try {
.....
return authVerifierResult;
} catch (AutoLoginException e) {
throw new AuthException(e);
}
}
On debugging from Liferay 6.2.3 source code I see the point when
the flow is broken is AuthVerifierPipeline._mergeAuthVerifierConfiguration() method.
the statement : Map settings = accessControlContext.getSettings(); returns zero size map.
Finally the actual place where the Verifier is called : AuthVerifierPipeline._verifyRequest() does not run as List authVerifierConfigurations is ZERO size.
I looked in AccessControlContext class and other classes, I could not see any setter method to set _settings or any references which set this var.
any help around this is much appreciated.
note : I verified that LifeRay does recognize my TestAuthVerifier impl.
to make it work you have to work with the hook plugin. First create a file liferay-hook.xml in WEB-INF folder to override the portal.properties
<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">
<hook>
<portal-properties>portal.properties</portal-properties>
</hook>
In the src folder put the file portal.properties or if you are using maven in the resource folder with the properties of the AuthVerifier in your case
auth.verifier.pipeline=com.test.TestAuthVerifier
auth.verifier.TestAuthVerifier.version.supported=1.0
This is a link of a sample in liferay git for more detail sample-authverifier-hook
Related
I'm trying to create a component within an addon. Everything works fine during impex process (contentslot, pagetemplate etc.) but it doesn't get rendered when accessing the page.
I've followed these steps but my controller isn't even get called.
#Controller("ConfirmationComponentController")
#RequestMapping(value = ControllerConstants.Actions.Cms.ConfirmationComponent)
public class ConfirmationComponentController extends AbstractCMSAddOnComponentController<ConfirmationComponentModel> {
#Override
protected void fillModel(HttpServletRequest request, Model model, ConfirmationComponentModel component) {
}
}
I've added the component's jsp in "WEB-INF/views/responsive/cms/.." from the addon module but I keep getting this error:
File [/WEB-INF/views/addons/trainingcore/responsive/cms/confirmationcomponent.jsp] not found
P.S.: I've managed to get the component controller to be called, but the getView() is returning a wrong path and that's why the component is not getting called. Any help? Thank you very much:)
Should this component to be created in addon *-items.xml?
What you need to know first
Using addons is a complicated endeavor in hybris. You need to know, that the resources are not used in the addon, but they are copied (during build process) to your storefront, where they are used.
All classes in
myaddon/acceleratoraddon/web/src/
will be copied to:
mystorefront/web/addonsrc/myaddon/
All resources in
myaddon/acceleratoraddon/web/webroot/
will be copied to corresponding folders:
mystorefront/web/webroot/WEB-INF/_ui-src/addons/myaddon
mystorefront/web/webroot/WEB-INF/tld/addons/myaddon
mystorefront/web/webroot/WEB-INF/messages/addons/myaddon
mystorefront/web/webroot/WEB-INF/tags/addons/myaddon
mystorefront/web/webroot/WEB-INF/views/addons/myaddon
That means
That means, that the effective path to your component jsp will not be something like:
/WEB-INF/views/cms/...
but will be something like:
/WEB-INF/views/myaddon/cms/...
The path myaddon will depend on the extension your component is declared in. So if you declare it in trainingcore-items.xml it will be
/WEB-INF/views/trainingcore/...
If you declare it in myaddon-items.xml it will be
/WEB-INF/views/myaddon/...
I have a button on an XPage where I want to connect to a remote OpenOffice instance. OpenOffice is started and is listening for a socket connection.
The onclick event of the button runs following SSJS:
oo = new com.test.OpenOffice();
oo.init("host=127.0.0.1,port=8107");
oo.openFile("C:\\TEMP\\Test.odt");
The code raises an excepction jva.lang.IlleagalStateException: NotesContext not initialized for the thread
The exception is raised within the method initof the class OpenOffice.
The relevant parts of the class OpenOffice is the following code:
public class DHOpenOffice implements Serializable {
private static final long serialVersionUID = -7443191805456329135L;
private XComponentContext xRemoteContext;
private XMultiComponentFactory xMCF;
private XTextDocument oTextDocument;
public DHOpenOffice() {
xRemoteContext = null;
xMCF = null;
oTextDocument = null;
}
public void init(String hostAdr) throws java.lang.Exception {
xRemoteContext = null;
XComponentContext xLocalContext = Bootstrap.createInitialComponentContext(null);
XUnoUrlResolver xUrlResolver = UnoUrlResolver.create(xLocalContext);
String sConnect = "uno:socket," + hostAdr + ",tcpNoDelay=0;urp;StarOffice.ServiceManager";
Object context = xUrlResolver.resolve(sConnect);
xRemoteContext = UnoRuntime.queryInterface(XComponentContext.class, context);
xMCF = xRemoteContext.getServiceManager();
}
The code line Object context = xUrlResolver.resolve(sConnect); is the one that raises the exception.
Why is this happing? What is the reason for this exception and how can I resolve the situation?
N.B.: The class code runs smoothly in a standalone application. The error occurs only when the code is started by a SSJS code.
It looks like a threading issue. There are a number of things you can go and try:
Wrap the whole interaction into a custom class and use it from a managed bean instead of calling it from SSJS
Make sure not to hand over any Notes objects into the custom class, only your own
Check if the Open Document Toolkit would be sufficient to do the operations you are interested in, so you don't need to run OO
let us know how it goes
Update
Try to get outside the standard XPages cycle. One way is to deploy a custom plug-in servlet:
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class OpenOfficeServlet extends HttpServlet {
// Your code goes here
}
You need to get the plugin.xml right:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.equinox.http.registry.servlets">
<servlet alias="/ooproxy" class="com.yourcompany.OpenOfficeServlet" />
</extension>
</plugin>
Then you could e.g. post a JSON structure or a serializable Java object to the servlet with the data and process it there (async if necessary). You deploy such a plug-in using the updatesite.nsf
Thanks to the answer of #stwissel I was able to solve the problem (he pointed me to the right direction).
I could solve the problem with a simple OSGI plug-in. The servlet approach solved the problem, too, but for me the OSGI plug-in was easier to use.
So these are the steps to create the plug-in
start a new plugin project
copy the open office jar files into the project and include them into the build path
copy the custom class that uses the UNO API into the plug-in
create a feature project for the plugin
create an update site
deploy the plugin via an update site
The following site where also quite helpfull:
Creating an XPages Library
Wrap an existing JAR file into a plug-in
Inside my template file I use the safeitemname template variable to define my class name. The Item Template is intended to create a class that subclasses MXApplication. The result after exporting the template and utilizing it to create a new class is essentially the class inherits from itself. If I try adding a namespace to the class, I just get the namespace prefixed before the value substituted for safeitemname.
Here is the Template class (trimmed for explanation purposes):
namespace $rootnamespace$
{
public class $safeitemname$ : MonoCross.Navigation.MXApplication
{
public override void OnAppLoad()
{
//Do the work
}
}
}
The result when I use the template to create MyApp is:
namespace MyNameSpace
{
public class MyApp : MonoCross.Navigation.MyApp
{
public override void OnAppLoad()
{
//Do the work
}
}
}
I've tried to export this template using VS2012 (and VS2013).
Any advice would be much appreciated. I've been trying to update my Item Templates in Visual Studio 2012 (they worked in 2010) but I keep running into this issue. I've tried it on several of my existing templates; and even tried recreating the .csproj and adding my existing templates to the .csprog file created using Visual Studio 2012. All of my attempts result in the same class inheritance issue.
This is the MSDN Doc I've been using for reference:
http://msdn.microsoft.com/en-us/library/vstudio/tsyyf0yh.aspx
The issue was apparent when looking at the .zip file created by the Export Template command. The .cs file contained within the template .zip read:
namespace $rootnamespace$
{
class $safeitemname$ : MonoCross.Navigation.$safeitemname$
{
public override void OnAppLoad()
{
//Do the work
}
}
}
The fix to get my template working was to edit the .cs file manually and replace the last $safeitemname$ with MXApplication and then stick the .cs file back in the .zip file where it came from.
I finally got my test servlet working from this thread?
Calling HttpServlet class from xpages client side script and regular notes forms?
The issue that remains is I am being asked to login. But my final servlet will need to run without logging in. I have my acl set to Read public document and Write public documents for anonymous.
What I don't know how to do is to make the serlet public access. Other design documents have an "Available to Public Access users" property but I am seeing no such property for java files. Would this be set somewhere else? Maybe in my IServletFactory perhaps?
I don't know why I was required to log in before but it looks like it is now working. The only thing that is requred is that Read Public Public Document be enabled.
This is a bit concerning since it at least appears there is no way to make some servlets non-public. In my case it won't be an issue but it could be an issue for others.
Also what I noticed is that if you change the Public Access acl setting, it looks like you need to rebuild your servlets for some reason or the servlets won't run. When I get a chance I will open a ticket with notes support for both of these issues.
For those wanting to execute a servlet, I suggest this article:
http://8b30b0.wordpress.com/2013/02/04/creating-a-basic-domino-servlet/#comments
But here is a much more simplifed version of IServletFactory that might be easier to understand and get working.
package test;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import com.ibm.designer.runtime.domino.adapter.ComponentModule;
import com.ibm.designer.runtime.domino.adapter.IServletFactory;
import com.ibm.designer.runtime.domino.adapter.ServletMatch;
public class TestFactory implements IServletFactory {
private ComponentModule module;
public ServletMatch getServletMatch(String contextPath, String path)
throws ServletException {
System.out.println("TestFactory:getServletMatch");
String servletPath = "";
String pathInfo = path;
return new ServletMatch(getWidgetServlet(),servletPath,pathInfo);
}
public void init(ComponentModule arg0) {
System.out.println("TestFactory:init");
this.module = arg0;
}
public Servlet getWidgetServlet() throws ServletException {
return module.createServlet("com.pnc.cld.HelloWorld", "testServlet",null);
}
}
I'm working on REST web-service written with jersey and I'm trying to output some XML with CDATA sections in it. I understand the reference implementation of JAXB doesn't support that, so I've downloaded EclipseLink's MOXy and I'm trying to get the #XmlCDATA annotation to work.
My JAXB mapped bean looks like this
package com.me.entities;
#XmlRootElement #XmlAccessorType(XmlAccessType.FIELD)
public class MyBean {
#XmlAttribute
private URI thumbnail;
#XmlElement(name="longdescription") #XmlCDATA
private String description;
public MyBean() { }
public final String getDescription() { return description; }
public final void setDescription(String d) { this.description = d; }
}
and I have the jaxb.properties file in the com/me/entities along with the class files. The properties file has
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
in it. I'm sure it gets loaded successfully since if I replace the factory class name with some nonsense the app breaks down. Also, explicitly marshaling the file creating the JAXBContext on my own works fine, so the problem seems related to jersey. According to this my setup is fine, but when my jersey resource returns an instance of MyBean
...
#GET #Produces(MediaType.TEXT_XML)
public MyBean getMyBean() {
MyBean b = new MyBean();
b.setDescription("Some blurb plenty of invalid chars like <<< && >>>");
return b;
}
what I get back has no CDATA in it, but looks like
<?xml version="1.0" encoding="UTF-8"?>
<info><longdescription>Some blurb plenty of invalid chars like <<< && >>></longdescription></info>
What am I doing wrong?
Looks like the problem was my application server: I am running this with WebLogic 10.3.5 in development mode, which comes with a lot of common libraries pre-installed that in the default configuration take precedence over those deployed in the webapp WEB-INF/lib folder.
To fix this a weblogic specific application description is needed, just create a weblogic.xml file inside WEB-INF containing the prefer-web-inf-classes option. The file I used is this:
<?xml version='1.0' standalone='yes'?>
<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
I still have no idea which library was the problem though, anyone knows feel free to edit this answer.
Please download Jaxb Extension:
This is Eclipselink open source extension for Jaxb.
Get jar file: eclipselink.jar copy into Project lib.
http://www.eclipse.org/eclipselink/downloads/
EclipseLink 2.4.1 Installer Zip (37 MB)
And see example at:
http://theopentutorials.com/tutorials/java/jaxb/jaxb-marshalling-and-unmarshalling-cdata-block-using-eclipselink-moxy/
Good look!.