cancel
Showing results for 
Search instead for 
Did you mean: 

Overriding the LoginBean

simon
Champ in-the-making
Champ in-the-making
Hi again,

I wrote some small JSF application that checks some extra required login parameters at our company and now I would like to join this code with my Alfresco system. Problem is… I don't see how. I tested my bean as a standalone JSF with JSP app and it works.

Please noe: I don't need to replace the LoginBean, just want to add an extra check (e.g. abort login if HTTP header X, Y or Z is not present).

I would like to use my own namespace and be as flexible as possible to keep it maintainable when we uprgrade Alfresco (using Enterprise 1.2 at the moment): overriding, Spring configuration,…

Should I add my bean and override some Spring XML file to point to my bean or should I overwrite the LoginBean and extend my bean?

What is the syntax of the configuration file (I suppose I should use the custom-services-context.xml file, correct?) and what's the safest place to keep my bean (shared Tomcat path?).

Thanks!
8 REPLIES 8

simon
Champ in-the-making
Champ in-the-making
No one?

gavinc
Champ in-the-making
Champ in-the-making
Hi,

Customization is a focus of 1.3 so we are still working on the best practices for doing stuff like this.

I think the best bet in this situation is to replace the LoginBean with your extended implementation. To do this you will need to change the class name for the managed bean definition i.e.

<managed-bean>
   <description>
      The bean that backs up the Login screen
   </description>
   <managed-bean-name>LoginBean</managed-bean-name>
   <managed-bean-class>your.LoginBean</managed-bean-class>
….

This is currently defined in faces-config-beans.xml. You could change it in here but this will not be upgrade proof. The best solution is to create a new faces config file with your change in it and package it in a JAR file. The faces config file must be within a META-INF folder inside the JAR.

This JAR file can then be placed in WEB-INF/lib or in <tomcat>/shared/lib.

As I say we are working on this area (including documentation for it) for 1.3 so the process should hpefully become clearer.

Hope that helps.

simon
Champ in-the-making
Champ in-the-making
Thanks Gavin, still some problems though.

1. What's the difference between the faces-config.xml and the faces-config-beans.xml? Both files have the managed-bean definition for the LoginBean, is this relevant?

2. Secondly the JAR file. I compile my customised LoginBean an put it in some JAR file.  The JAR file now looks like this:

myLogin.jar
– META-INF
—— Manifest.mf
—— faces-config-beans.xml
– my
—— package
———- LoginBean.class

What's the faces-config-beans.xml doing IN the JAR? It works when I change the main faces-config-beans file in the WEB-INF folder so why do I need the one in the JAR?

I changed the error message at the login screen and it works! Didn't expect an error message could be SO welcome. Smiley Wink Let's try some serious stuff now.

PS: It does NOT work when I drop the JAR in the <tomcat>/shared/lib folder. It does work when I put the file in the WEB-INF/lib folder. Don't know why.

gavinc
Champ in-the-making
Champ in-the-making
OK.

1. It sounds like you may have merged some files from different versions. We no longer have a faces-config.xml file. This file got separated out into separate files one of those being faces-config-beans.xml. As the name suggests faces-config-beans contains all the managed beans definitions so that's the one you want.

2. You have the structure of the JAR file right but the file must be called faces-config.xml, this is only if you have created a new file. If you have changed the faces-config-beans.xml in WEB-INF then you don't need any config file in the JAR file. I suggested this way as an upgrade proof approach.

Yes, you're right, the JAR should go into WEB-INF/lib. The only time it will work in <tomcat>/shared/lib is when you ONLY have a faces-config.xml file in the JAR i.e. no Java code.

Hope this all makes sense.

simon
Champ in-the-making
Champ in-the-making
Thanks agina Gavin, this clarifies some things for me.

I copied the LoginBean to another package, compiled it and bundled the JAR, changed the WEB-INF configuration file (I know, not perfect but hey, it's fine for testing). When I surf to the login page I get the customised error message, perferct!

One last problem though…

When the login is successfull (admin, admin combination) I get the following error:
17:23:41,368 WARN  [org.alfresco.web.app.ResourceBundleWrapper] Failed to find I18N message string key: error_login_missingCUSTOM
17:24:10,660 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/alfresco].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
java.lang.ClassCastException: be.company.access.LoginBean
        at org.alfresco.web.app.servlet.AuthenticationHelper.authenticate(AuthenticationHelper.java:106)
        at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:67)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)


The I18N error is not the problem, I changed the error messages to get some visual feedback so I could see that my LoginBean was used and not the standard one.

I did NOT change the code of the login bean, I only added those 2 lines at the top of the class:

package be.company.access.access;
import org.alfresco.web.bean.*;

Any idea?

Thanks!

simon
Champ in-the-making
Champ in-the-making
No one here to help me out on this?

gavinc
Champ in-the-making
Champ in-the-making
Hi,

The AuthenticationHelper class is trying to cast the bean to "org.alfresco.web.bean.LoginBean".

I'm guessing your bean does not extend our LoginBean which would explain the error message you are seeing.

Try extending our LoginBean class and see if that helps.

simon
Champ in-the-making
Champ in-the-making
Yes, that was the problem… should have seen that.

Thanks Gavin!