jsf - Error 404 : /j_spring_security_check is not available -
i tried integrate spring security on jsf in authentication form , private page need authentication , when enter login , password ,this error diplayed
error 404 : project/j_spring_security_check not available
so created jsf form :
<h:form id="loginform" prependid="false" > <label for="exampleinputemail1">email address</label> <h:inputtext class="form-control" id="j_username" required="true"/> <label for="exampleinputpassword1">password</label> <h:inputsecret class="form-control" id="j_password" required="true"/> <h:commandbutton type="submit" class="btn btn-primary btn-block" action="#{authentication.dologin()}" value="login" /> </h:form>
the function dologin() in authentication bean defined :
public string dologin() throws servletexception, ioexception { externalcontext context=facescontext.getcurrentinstance().getexternalcontext(); requestdispatcher dispatcher=((servletrequest)context.getrequest()).getrequestdispatcher("j_spring_security_check"); dispatcher.forward((servletrequest)context.getrequest(),(servletresponse)context.getresponse()); facescontext.getcurrentinstance().responsecomplete(); return null; }
the spring-security.xml :
<http auto-config="true"> <intercept-url pattern="/j_spring_security_check" access="is_authenticated_anonymously"/> <intercept-url pattern="/login.xhtml*" access="is_authenticated_anonymously" /> <intercept-url pattern="/backoff/*" access="role_user"/> <form-login login-page="/login.xhtml" default-target-url="/backoff/activities.xhtml" always-use-default-target="true" authentication-failure-url="/front/error.xhtml" /> </http>
what should add make works ?
to solve problem can follow steps below:
1-change spring-security.xml this:
<http use-expressions="true"> <intercept-url pattern="/login.xhtml*" access="is_authenticated_anonymously" /> <intercept-url pattern="/backoff/*" access="role_user"/> <form-login login-page="/login.xhtml" default-target-url="/backoff/activities.xhtml" always-use-default-target="true" authentication-failure-url="/front/error.xhtml" <!-- if want use primefaces components can use this: password-parameter="j_idt10" : name of password input username-parameter="j_idt8" : name of username input ==>to name of inputs can use "element inspection" offred browser (chrome,firefox) --> /> </http>
2-change jsf form this
<h:form id="loginform" prependid="false" onsubmit="document.getelementbyid('loginform').action='j_spring_security_check';" > <label for="exampleinputemail1">email address</label> <h:inputtext id="exampleinputemail1" class="form-control" name="j_username" required="true"/> <label for="exampleinputpassword1">password</label> <h:inputsecret id="exampleinputpassword1" class="form-control" name="j_password" required="true"/> <h:commandbutton type="submit" class="btn btn-primary btn-block" value="login" /> </h:form>
you can notice remove action of commandbutton , change id of inputs name, add onsubmit
function inside form
hope out
Comments
Post a Comment