Re: Spring Security 3 authentication url forward

Splash Forums PrettyFaces Users Spring Security 3 authentication url forward Re: Spring Security 3 authentication url forward

#20879

antideluk
Participant

Hi Mr. Lincoln, my code was here http://www.megaupload.com/?d=MGE83HED… but as you request here is the stuff:

Version of Libraries:

<prime.version>2.2.1</prime.version> <– Primefaces

<spring.version>3.0.5.RELEASE</spring.version> <– Spring

<pretty.version>3.2.0</pretty.version> <– PrettyFaces

<jsfapi.version>2.1.1-b04</jsfapi.version> <– JSF 2 API

<jsfimpl.version>2.1.0-b11</jsfimpl.version> <– JSF 2 Impl

Web server: Apache Tomcat 7, latest version

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
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-app_2_5.xsd">
<!-- Context Params -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/configs/application-context.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/configs/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>com.ocpsoft.pretty.CONFIG_FILES</param-name>
<param-value>/WEB-INF/configs/pretty-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</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>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<!-- <context-param> <param-name>primefaces.THEME</param-name> <param-value>none</param-value>
</context-param> -->

<!-- Servlets and mappings -->
<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>

<!-- Filters and mappings -->
<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>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

<filter>
<filter-name>prettyFilter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>prettyFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>

<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>100000</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/WEB-INF/registros</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

</web-app>

Pretty config

<?xml version="1.0" encoding="UTF-8"?>
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.2.0
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.2.0.xsd">

<url-mapping id="home">
<pattern value="/" />
<view-id value="/WEB-INF/pages/home.xhtml" />
</url-mapping>

<url-mapping id="login">
<pattern value="/login" />
<view-id value="/WEB-INF/pages/login.xhtml" />
</url-mapping>

</pretty-config>

LoginBean

ExternalContext context = FacesContext.getCurrentInstance()
.getExternalContext();

StringBuilder url = new StringBuilder(
Constantes.SPRING_LOGIN_PROCESS_URL).append("?")
.append(Constantes.SPRING_LOGIN_USERNAME_PARAMETER).append("=")
.append(this.userName).append("&")
.append(Constantes.SPRING_LOGIN_PASSWORD_PARAMETER).append("=")
.append(this.password);

log.debug("Forwarding to authentication url '{}'", url.toString());

RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
.getRequestDispatcher(url.toString());

dispatcher.forward((ServletRequest) context.getRequest(),
(ServletResponse) context.getResponse());

FacesContext.getCurrentInstance().responseComplete();
return null;