cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco 4.0d + CAS

luca
Star Contributor
Star Contributor
Hi all,
I'm trying to enable authentication through CAS in Alfresco 4.0d, but I have some problems.

When I restart Alfresco I get this error:
Cannot create JDBC driver of class '' for connect URL 'null'
java.lang.NullPointerException
   at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
   at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
   at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
   at java.sql.DriverManager.getDriver(DriverManager.java:253)
   at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
   at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
   at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
   at org.alfresco.config.JndiObjectFactoryBean.lookup(JndiObjectFactoryBean.java:44)
   at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
   at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)

This happens when Alfresco calls the filter class, when I try to get the applicationContext to retrieve Alfresco system beans like this:
applicationContext = ApplicationContextHelper.getApplicationContext();

Am I doing something wrong?
Anyone can help me?

It seems like I am getting the application Context in a wrong way, but I don't know why  :cry:

The filter class is very simple now because I want to know what is causing the problem.
14 REPLIES 14

afaust
Legendary Innovator
Legendary Innovator
Hello,

you cannot manually create the SecureContext - it is provided once the user has been authenticated. A SecureContext is also automatically set for operations you call in a runAsSystem context. Alternatively, when you use the service implementation beans instead of the public service beans (i.e. "authenticationService" instead of "AuthenticationService"), you don't need a SecureContext as this is only checked by the security interceptors.

In your case, I would choose to use runAsSystem since I think it would be inappropriate to use service implementation beans in this case (which would also circumvent transaction management, exception translation and auditing, which are all handled by the public service beans).

Regards
Axel

luca
Star Contributor
Star Contributor
More details on the error:

The exception is thrown when I call (username has the value of the user logged through CAS, and casTicket is the ticket given by the CAS like ST-355-RzBwnI0vgGRpKsZEfzzY-cas2 😞
AuthenticationHelper.setUser(context, req, username, casTicket, true);

Going deeper I see that the error is thrown inside the method AuthenticationHelper.createUser and in particular when it calls
 NodeRef homeRef = (NodeRef) nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER);

The property is successfull retrieved, but before returning it it is fired the MethodSecurityInterceptor which tells me that "A valid SecureContext was not provided in the RequestContext"

I have the user already authenticated by CAS and I have only the ticket, what do I have to use to log it in Alfresco?  :?:

afaust
Legendary Innovator
Legendary Innovator
Hello,

the user is "only" authenticated by CAS - Alfresco does not know this yet. With your code, your attempting to tell Alfresco, but doing so involves access to some of the users data. As said before, I'd expect runAsSystem to be a big help…
On the other hand, looking at the code in AuthenticationHelper.createUser, I can't help but wonder why Alfresco users the unsecured "personService" but the secured "NodeService" (which is the cause of this behavior). I think in this case, the "nodeService" should be used instead of "NodeService", and you wouldn't need runAsSystem.

Regards
Axel

luca
Star Contributor
Star Contributor
Hi AFaust,
you were right and now I succesfully put the user in the session, but now I get another error because of the NavigationBean is not set correctly. I think I'm missing something else….

For now this is the things I do in my filter:
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
      public Void doWork() throws Exception {
               
         AuthenticationHelper.setUser(contextF, reqF, usernameF, ticketF, true);

         AuthenticationHelper.setUsernameCookie(reqF, respF, usernameF);

         AuthenticationHelper.setupThread(contextF, reqF, respF, true);
      }}

And this is the stacktrace that I get:
javax.faces.FacesException: javax.faces.el.EvaluationException: Cannot get value for expression '#{NavigationBean.toolbarLocation}'
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:432)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:255)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:146)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:147)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.alfresco.repo.web.filter.beans.SessionSynchronizedFilter.doFilter(SessionSynchronizedFilter.java:67)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at it.eng.api.alfresco.authentication.cas.CASAuthenticationFilterBean.doFilter(CASAuthenticationFilterBean.java:222)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:116)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy229.doFilter(Unknown Source)
at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:82)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at edu.yale.its.tp.cas.client.filter.CASFilter.doFilter(CASFilter.java:401)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:774)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:896)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.jasper.JasperException: javax.faces.el.EvaluationException: Cannot get value for expression '#{NavigationBean.toolbarLocation}'
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:426)
… 41 more
Caused by: javax.faces.el.EvaluationException: Cannot get value for expression '#{NavigationBean.toolbarLocation}'
at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:405)
at javax.faces.component.UICommand.getValue(UICommand.java:223)
at org.alfresco.web.ui.common.renderer.ModeListRenderer.renderItem(ModeListRenderer.java:333)
at org.alfresco.web.ui.common.renderer.ModeListRenderer.encodeChildren(ModeListRenderer.java:268)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:776)
at javax.faces.webapp.UIComponentTag.encodeChildren(UIComponentTag.java:663)
at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:544)
at org.apache.jsp.jsp.browse.browse_jsp._jspx_meth_a_005fmodeList_005f0(browse_jsp.java:1076)
at org.apache.jsp.jsp.browse.browse_jsp._jspService(browse_jsp.java:421)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
… 51 more
Caused by: javax.faces.el.EvaluationException: Exception getting value of property toolbarLocation of base of type : org.alfresco.web.bean.NavigationBean
at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:99)
at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:539)
at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:386)
… 62 more
Caused by: javax.faces.el.EvaluationException: Bean: org.alfresco.web.bean.NavigationBean, property: toolbarLocation
at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:463)
at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:85)
… 65 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:459)
… 66 more
Caused by: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:481)
at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:359)
at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.transaction.RetryingTransactionInterceptor$1.execute(RetryingTransactionInterceptor.java:69)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:388)
at org.alfresco.repo.transaction.RetryingTransactionInterceptor.invoke(RetryingTransactionInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy8.getProperty(Unknown Source)
at org.alfresco.web.bean.repository.Preferences.getValue(Preferences.java:73)
at org.alfresco.web.bean.users.UserPreferencesBean.getStartLocation(UserPreferencesBean.java:263)
at org.alfresco.web.bean.NavigationBean.getToolbarLocation(NavigationBean.java:324)
… 71 more

Note that the cause of this stacktrace is "Caused by: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext"  :x

luca
Star Contributor
Star Contributor
Hi all,
I have to apologize with all who have lost time with this post, I was tryng to follow a wrong road because I started with what I did with an older version of Alfresco.  Smiley Surprisedops:   Smiley Surprisedops:   Smiley Surprisedops:

If you follow the official wiki here (http://wiki.alfresco.com/wiki/Central_Authentication_Service_Configuration) you get it work! Now I am trying to use CAS to authenticate also with web service using the REST interface, I hope it will be easy…