There are two possibilities for spring security to work.
Use prependId="false" in JSF form
Since <h:form> is a naming container, it adds the identifier of its children with the specified id or auto-generated identifier, since Spring Security expects identifiers to remain unclean, just do not add identifiers:
<h:form prependId="false"> <h:outputLabel value="User Id: " for="userId" /> <h:inputText id="j_username" label="User Id" required="true" value="#{loginBean.name}" /> <h:outputLabel value="Password: " for ="password" /> <h:inputSecret id="j_password" value="#{loginBean.password}" /> <h:commandButton value="Submit" action="#{loginBean.login}" /> </h:form>
Please note that #{j_spring_security_check} is the wrong action method: it must be #{loginBean.login} with the following contents:
public String login() {
Basically, all you have to do is send to /j_spring_security_check and specify j_username and j_password as request parameters.
Use a regular HTML form
Basically, there is no particular need to contact the JSF form on this issue if you do not need to do any additional things besides authentication, and a simple HTML form is enough for Spring security to do its job.
<form action="/j_spring_security_check" method="POST"> <label for="j_username">User Id: </label> <input id="j_username" name="j_username" type="text" /> <label for="j_password">Password: </label> <input id="j_password" name="j_password" type="password"/> <input type="submit" value="Submit"/> </form>
source share