Reputation: 795
I have found so many examples but the problem is all of them are using JSP/JSF
as view. The problem is they always use j_username
as username input id and j_password
as password id. What I found is these names are standard names. Primefaces doesn't allow me to give name to p:inputtext
component. Do you have any solution?
Here is an example : http://krams915.blogspot.com/2012/01/spring-security-31-implement_13.html
Upvotes: 1
Views: 10699
Reputation: 1
You can post directly to j_spring_security_check
, but sometimes it might come handy to do it programmatically to combine both worlds.
<p:commandButton value="Login" action="#{loginController.login}" ajax="false">
<h:inputText id="j_username" required="true" />
<h:inputSecret id="j_password" required="true" />
with h xmlns:h="http://java.sun.com/jsf/html"
in your loginController:
ExternalContext context = FacesContext.getCurrentInstance()
.getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()).getRequestDispatcher("/j_spring_security_check");
dispatcher.forward((ServletRequest) context.getRequest(),
(ServletResponse) context.getResponse());
Upvotes: 0
Reputation: 2995
j_username
and j_password
are only default values in Spring Security. You can customize these names as you expected. To do this, you set values for password-parameter
and username-parameter
as below:
<security:form-login login-page="/login.html"
default-target-url="/welcome.html"
always-use-default-target="true"
authentication-failure-url="/login.html?error"
password-parameter="your_value"
username-parameter="your_value"/>
I'm using Spring Security 3.1. With another version, the configuration is possibly something like above.
Upvotes: 2
Reputation: 7817
Try to use a normal HTML form pointing to the URL of login controller instead of a Primefaces tags:
<form name='f' action="/j_spring_security_check" method='POST'>
<input type='text' name='j_username' value=''>
<input type='password' name='j_password' />
<input name="submit" type="submit" value="submit" />
</form>
Upvotes: 0