Spring security not redirect to default-target-url

UI Components for JSF
Post Reply
dss
Posts: 4
Joined: 02 Oct 2013, 19:26

02 Oct 2013, 20:13

Hello:
I want to use Spring security in my pf mobile app, the problem is that after a successful login, the login page is showed again. I don't know what can be wrong, I appreciate any help...
Here is my Spring security xml config:

Code: Select all

<http auto-config="true" access-decision-manager-ref="accessDecisionManager">

		<intercept-url pattern="/user_home/*" access="ROLE_USUARIO_BASE" />
		<intercept-url pattern="/hoja_verificacion/*" access="ROLE_CONTROLADOR_QC" />

		<form-login login-page="/login.jsf" 	default-target-url="/user_home/home.jsf" authentication-failure url="/fallo.jsf"	always-use-default-target="true" />
	</http>

	<authentication-manager>
		<authentication-provider user-service-ref="sgccUserDetailService">
		</authentication-provider>
	</authentication-manager>

	<beans:bean id="sgccUserDetailService"
		class="com.dbmobile.soft.web.sgcc.security.UserDetailsServiceImpl"></beans:bean>

	<beans:bean id="loggerListener"
		class="org.springframework.security.authentication.event.LoggerListener" />

	
LoginBean:

Code: Select all

public String login() throws ServletException, IOException {

		ExternalContext context = FacesContext.getCurrentInstance()
				.getExternalContext();
		RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
				.getRequestDispatcher("/login_url");
		dispatcher.forward((ServletRequest) context.getRequest(),
				(ServletResponse) context.getResponse());
		FacesContext.getCurrentInstance().responseComplete();

		return null;
	}
Login page:

Code: Select all

<f:view xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:pm="http://primefaces.org/mobile" contentType="text/html"
	renderKitId="PRIMEFACES_MOBILE">
	<pm:page title="Login" mini="true">
		<pm:view id="login">
			<pm:header title="Login" swatch="b">
			</pm:header>
			<pm:content>

				<h:form prependId="false">
					<p:messages showDetail="true" autoUpdate="true" sticky="true" />
					<h:outputLabel value="Username:" />
					<p:inputText id="j_username" required="true" />
					<h:outputLabel value="Password:" />
					<h:inputSecret id="j_password" required="true" />
					<p:commandButton value="Login" action="#{loginBean.login}"
						type="submit" />
				</h:form>

			</pm:content>
			<pm:footer swatch="b" fixed="true">
				<h:outputLabel value="Footer" />
			</pm:footer>
		</pm:view>

	</pm:page>
</f:view>

dss
Posts: 4
Joined: 02 Oct 2013, 19:26

03 Oct 2013, 18:42

Hello, I find the solution for this issue, the problem is not related with Spring security but with p:commandButton. I change it by h:commandButton and everything works fine.

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

05 Oct 2013, 00:28

dss wrote:Hello, I find the solution for this issue, the problem is not related with Spring security but with p:commandButton. I change it by h:commandButton and everything works fine.
does it work if you add ajax=false to p:commandButton?

h:commandButton default: ajax=false; per java ee 6 tutorial, you can use f:ajax with h:commandButton
p:commandButton default: ajax=true
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

dss
Posts: 4
Joined: 02 Oct 2013, 19:26

07 Oct 2013, 14:06

I try with p:commandButton setting ajax=false and I have the same result, the login page is sowed again.

yhanks for yor reply.

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

07 Oct 2013, 14:15

dss wrote:I try with p:commandButton setting ajax=false and I have the same result, the login page is sowed again.
trying to understand this response of yours, so I had to re-read OP, and my thoughts are...

same result = same problem mentioned in your OP (original post), and p:commandButton ajax=false shows login page, so p:commandButton ajax=false does 'not' solve your problem. h:commandbutton solves your problem.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Majestic-12 [Bot] and 46 guests