Spring Web Flow 2.5.1.RELEASE with JSF2.2 flow not executed - jsf-2.2

I am struggling with this issue for 5 days now and I don't see where to look for a solution.
I upgraded a JSF application from 2.1 to 2.2 with Mojara 2.1.17 to 2.2.14, including Icefaces from 3.2.0 to 4.2.0.
I also upgraded Spring 3.2 to 5.1.2 and Spring Web Flow from 2.3.2.RELEASE to 2.5.1.RELEASE. The problem is, after the migration all Spring Web Flow are no longer invoked. When I click a button nothing happens. I take a look at the web console and every time I click on a button which should trigger the web-flow, I keep getting an http 403 error.
This is a snipet of my configuration:
<webflow:flow-executor id="flowExecutor">
<webflow:flow-execution-listeners>
<webflow:listener ref="facesContextListener"/>
<webflow:listener ref="icefacesFlowListener" />
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry"/>
<property name="order" value="0"/>
</bean>
<bean id="facesContextListener"
class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" />
<faces:flow-builder-services id="flowBuilderServices" development="true" />
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/flows">
<webflow:flow-location-pattern value="**/*-flow.xml" />
</webflow:flow-registry>
The faces-config.xml is simple with only:
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
And the web.xml
<welcome-file-list>
<welcome-file>flow/welcome</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>flowDispatchServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<multipart-config />
</servlet>
<servlet-mapping>
<servlet-name>flowDispatchServlet</servlet-name>
<url-pattern>/flow/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>flowDispatchServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>
javax.enterprise.inject.spi.BeanManager
</resource-env-ref-type>
</resource-env-ref>
The main dependencies:
<spring-integration.version>5.1.0.RELEASE</spring-integration.version>
<spring-orm.version>5.1.2.RELEASE</spring-orm.version>
<spring-security-cas-client.version>3.0.8.RELEASE</spring-security-cas-client.version>
<spring-security.version>5.1.2.RELEASE</spring-security.version>
<spring.version>5.1.2.RELEASE</spring.version>
<spring.webflow.version>2.5.1.RELEASE</spring.webflow.version>
<spring-ws-core.version>3.0.4.RELEASE</spring-ws-core.version>
<javax.faces.version>2.2.14</javax.faces.version>
<icefaces-ace.version>4.2.0</icefaces-ace.version>
<validation-api.version>2.0.1.Final</validation-api.version>
I use Tomcat 8.5.
And a simple flow for tests:
<view-state id="start" view="welcome.xhtml">
<transition on="test" to="testView" />
</<view-state>
<view-state id="testView" view="test.xhtml"/>
The button in welcome.xhtml:
<h:form id="testForm">
....
<h:commandButton id="btnTest" class="button" value="Test" action="test"/>
</h:form>
welcome.xhtml is well rendered but clicking on the button, I get the 403 error.
Thanks for your help.

I finaly found the reason. Spring Security enables CSRF by default, which blocks POST request on my form. Disabled it solve the issue. I lost 5 days!!!!

Related

Java config in Spring with AOP

This question is about Java config in Spring. Is it possible to replace the following declaration in Java code.
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/secure-app-context.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Where secure-app-context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
...
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<aop:aspectj-autoproxy />
<mvc:annotation-driven>
<mvc:message-converters register-defaults="false">
<bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</mvc:message-converters>
</mvc:annotation-driven>
<context:component-scan base-package="com.abc.secure.service" />
<bean id="securityAspect" class="com.abc.secure.service.Secure" />
</beans>
You can very well do it by using WebApplicationInitializer(you dont need web.xml in this case)
Please see the post below:
How to configure Spring MVC with pure Java-based configuration?

Spring Web Flow Request Mapping not working

I am trying to test Spring Web Flow and cannot access the flow basing on the mapping I'm using. I'm sure I must be missing something simple, but here is my setup...
web.xml:
<servlet>
<servlet-name>accommodations</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>accommodations</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/datasource-config.xml
/WEB-INF/security-config.xml
/WEB-INF/webflow-config.xml
/WEB-INF/aop-config.xml
</param-value>
</context-param>
webflow configuration:
<flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows/" >
<flow:flow-location-pattern value="**/*-flow.xml"/>
</flow:flow-registry>
<flow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry"/>
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor"/>
</bean>
</beans>
The flow xml defination is locations in "WEB-INF/flows/accommodations/accommodations-flow.xml",
so my understand is that /accommodations should map to the flow.
When I point the browser to /accommodations I receive a 404.
What mistake am I making..?

Spring Security-Error creating bean 'org.springframework.security.filterChains'

I am trying basic spring security set up. I am using 3.1.0.RELEASE
I have in the spring security xml as follows:
<security:http auto-config='true'>
<security:intercept-url pattern="/**" access="ROLE_USER" />
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN" />
<security:user name="bob" password="bobspassword" authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
When I access the start page , I get the following exception:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.security.filterChains': Initialization of bean failed; nested exception is java.lang.NoSuchFieldError: NULL.
Can any one help me?
The actual cause of the problem seems to be that spring-security 3.1.0 pulls in older versions of spring which create a silent conflict. In my case spring-security-3.1.0.RELEASE pulled in spring-aop, spring-jdbc, spring-tx and spring-expression 3.0.6 but I was using spring 3.1.0.RELEASE. After adding these dependencies explicitly the problem went away.
Your web.xml looks like you missed the org.springframework.web.context.ContextLoaderListener
Your web.xml shoul have this elements:
<!-- or in your case /WEB-INF/applicationContext-security.xml -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<servlet>
<servlet-name>My-Web-SpringProject</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/webmvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<filter-mapping>
<!-- do not change this name! -->
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<!-- it is configured by the parameter contextConfigLocation in the begining -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>My-Web-SpringProject</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
To be honest, this is a Spring 3.0 configuration, but I think it is the same for 3.1

Error creating bean with name : Scope 'request' is not active for the current thread

I have integrated SWF 2.2.1,Primefaces 2.2.1,JSF 2,Spring Security 3,Spring 3.1.0M1I and EhCache and AspectJ and Castor.
I have defined beans for castor in my app-config.xml like
<bean id="oXMapper" class="com.abc.xyz.util.OXMapper">
<property name="unmarshaller" ref="unmarshaller" />
<property name="marshaller" ref="marshaller" />
<property name="acordRequest" ref="acordRequest" />
<property name="acordResponse" ref="acordResponse" />
</bean>
<bean id="unmarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocation"
value="classpath:/templates/mapping/ACORD_Response_Mapping.xml" />
</bean>
<bean id="marshaller" class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocation"
value="classpath:/templates/mapping/ACORD_Request_Mapping.xml" />
</bean>
<bean id="acordRequest" class="com.abc.xyz.cate.domain.ACORD">
<property name="insuranceSvcRq" ref="insuranceSvcRq" />
<property name="signonRq" ref="CltSearch_signonRq" />
</bean>
I have a search page from where I am building the parameters like
<h:panelGrid>
<h:selectOneRadio id="#{msg.srchType}" value="#{acordRequest.insuranceSvcRq.com_csc_ClientSearchRq.com_csc_SearchInfo.com_csc_SearchCriteria.com_csc_ClientSearch.com_csc_SearchNameByType}">
<f:selectItem itemLabel="#{msg.exact}" itemValue="E" id="#{msg.exact}" />
<f:selectItem itemLabel="#{msg.phonetic}" itemValue="S" id="#{msg.phonetic}" />
<f:selectItem itemLabel="#{msg.truncated}" itemValue="P" id="#{msg.truncated}" />
</h:selectOneRadio>
</h:panelGrid>
Using Spring Webflow, I am calling the OXMapper functions and passing the ACORD(hierarchical structural as it is used to build xml) object to it. This OXMapper class is responsible for marshalling and unmarshalling of the object and xml respectively.
Now the problem is whenever I am searching again on search page , old values automatically populates inside the fields.
So I tried changing the scope to "Request".
<bean id="acordRequest" class="com.abc.xyz.cate.domain.ACORD"
scope="request">
<property name="insuranceSvcRq" ref="insuranceSvcRq" />
<property name="signonRq" ref="CltSearch_signonRq" />
</bean>
After changing the scope I get the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oXMapper' defined in ServletContext resource [/WEB-INF/config/app-config.xml]: Cannot resolve reference to bean 'acordRequest' while setting bean property 'acordRequest'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'acordRequest': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
My web.xml is as follows
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/web-application-config.xml
</param-value>
</context-param>
<error-page>
<error-code>500</error-code>
<location>/error.xhtml</location>
</error-page>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<!-- Enables Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/certs/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
My faces-config.xml has nothing as such
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<!-- <message-bundle>JsfMessageResources</message-bundle> -->
</application>
<!-- JSF 2.0 Version of this faces-config.xml file -->
If you are not using Spring MVC, in order to use the request scope, you must reference the RequestContextListener in your web.xml:
f you use a Servlet 2.4+ web container, with requests processed outside of Spring's DispatcherServlet (for example, when using JSF or Struts), you need to add the following javax.servlet.ServletRequestListener to the declarations in your web applications web.xml file:
<web-app>
...
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
...
</web-app>
Quote from docs.

"Unable to read TLD META-INF/jsf_core.tld from jsf-impl-2.0.jar" error when integrating JSF

We have a Struts+Spring+Hibernate Application and we are trying to integrate JSF. For that we have done some configuration in web.xml and struts-config.xml. I have added some
JAR files to WEB-INF/lib.
The jar files containing in my WEB-INF/lib are listed here:
antlr-2.7.6rc1.jar,asm.jar,asm-attrs.jar,bsh-2.0b2.jar,c3p0-0.9.1.2-jdk1.3.jar,cglib-2.1.3.jar,commons-beanutils-1.7.jar,commons-betwixt-0.8.jar,commons-cli-1.0.jar,commons-codec-1.3.jar,commons-collections-3.jar,commons-dbcp-1.2.1.jar,commons-digester-1.7.jar,commons-discovery-0.2.jar,commons-fileupload.jar,commons-httpclient-3.1.jar,commons-io-1.3.1.jar,commons-lang-2.3.jar,commons-logging-1.1.jar,commons-pool-1.2.jar,commons-validator.jar,connector-1_5.jar,dom4j-1.6.1.jar,ehcache-1.1.jar,el-api-6.0.20.jar,el-impl-2.2.0-SNAPSHOT.jar,hibernate-3.1.3.jar,jetty-util-6.0.0,.jar,servlet-api-2.3.jar,spring-2.5.6.jar,standard.jar,struts.jar,xercesImpl-2.6.2.jar,xmlParserAPIs-2.6.2.jar,xstream-1.3.1
The below jar file are the ones newly added for integrating JSF:
jsf-api-2.0.jar,jsf-impl-2.0.jar,myfaces-jsf-api-1.0.9.jar.jar.jar,struts-faces-1.3.10.jar
My web.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SSHIntgr</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/config/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>locale</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- struts-faces configuration start -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- struts-faces configuration start -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
My struts-config.xml is
<struts-config>
<form-beans>
<form-bean name="usrForm" type="com.sshi.web.form.UsrForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/login" type="com.sshi.web.action.LoginAction"
name="usrForm" scope="request">
<forward name="allowUser" path="/pages/Welcome.jsp"/>
<forward name="denyUser" path="/index.jsp"/>
</action>
</action-mappings>
<controller>
<set-property property="processorClass"
value="org.apache.struts.faces.
application.FacesRequestProcessor"/>
</controller>
<message-resources key="MessageResources" parameter="MessageResources" null="false" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/config/validator-rules.xml,/config/validation.xml" />
<set-property property="stopOnFirstError" value="true" />
</plug-in>
</struts-config>
I am using Spring source toll suite, Tomcat 5.5 and JDK 1.5.
My Tomcat 5.5\common\lib contains JAR files
commons-el.jar,jasper-compiler.jar,jasper-compiler-jdt.jar,jasper-runtime.jar,jsp-api.jar,naming-factory.jar,naming-factory-dbcp.jar,
naming-resources.jar,servlet-api.jar
My Server is starting properly but not able to load JSP page, I am getting the exception as
org.apache.jasper.JasperException: Unable to read TLD "META-INF/jsf_core.tld" from JAR file "file:/SSHIntgr/WEB-INF/lib/jsf-impl-2.0.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryValidator class: com.sun.faces.taglib.jsf_core.CoreValidator
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:50)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:179)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:181)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:418)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)
How can I solve this?
You're using tomcat 5.5 which is a Servlet 2.4 container, but JSF 2.0 requires Servlet 2.5 or newer.
So you have 2 options:
Upgrade your servletcontainer to a Servlet 2.5 comparible one (e.g. Tomcat 6.0).
Downgrade JSF to 1.2 which is compatible with Servlet 2.4.
Unrelated to the concrete problem: the file servlet-api-2.3.jar does not belong in WEB-INF/lib. Get rid of it. It's supposed to be already provided by the servletcontainer (in this case, the one in Tomcat's /lib). Keeping this file will only lead to missing class def or abstract method errors during runtime.

Resources