Witam chciałem zabezpieczyć moją stronę z wykorzystaniem spring security oraz stworzyćformularz logowania za pomocą primefaces. Skorzystałem z poniższego tutoriala.
http://ocpsoft.org/java/acegi-spring-security-jsf-login-page/
I mam problem taki że po uruchomieniu aplikacji nie ma żadnych błędów ale nie przekierowuje mnie do strony logowania. Jeżeli wpisze adres z palca to pokazuje mi się formularz logowania ale po wpisaniu danych i kliknięciu zatwierdź nic się nie dzieje (dalej pozostaje na stronie logowania). Praktycznie wszystko skopowiałem z powyższego tutoriala żeby sprawdzić jak to działa. Może mi ktoś powiedzieć co może być powodem tego że nie działa?. Dodatkowo wrzucam kod:
web.xml
<display-name>JSFSecurity</display-name>
<!-- Spring Config -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Filter Config -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<!-- Filter Mappings -->
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<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>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>aristo</param-value>
</context-param>
spring-security.xml
<global-method-security secured-annotations="enabled">
</global-method-security>
<beans:bean id="rememberMePostProcessor"
class="com.clinic.model.RememberMePostProcessor">
</beans:bean>
<http auto-config="true">
<remember-me/>
<intercept-url pattern="/registration.xhtml" access="ROLE_SUPERVISOR,ROLE_TELLER" />
<form-login login-processing-url="/j_spring_security_check"
login-page="/faces/login.xhtml" default-target-url="/faces/login.xhtml"
authentication-failure-url="/faces/login.xhtml" />
<logout logout-url="/logout*" logout-success-url="/" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="rod" password="rod"
authorities="ROLE_SUPERVISOR, ROLE_USER, ROLE_TELLER" />
<user name="dianne" password="dianne" authorities="ROLE_USER,ROLE_TELLER" />
<user name="scott" password="scott" authorities="ROLE_USER" />
<user name="peter" password="peter" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
login.xhtml
<h:body>
<h:form id="form1">
<p:messages id="messages" showDetail="false" autoUpdate="true"
closable="false" />
</h:form>
<h:form id="loginForm" prependId="false">
<div class="centeredBox">
<p:panelGrid columns="2">
<h:outputLabel for="j_username" value="Username:" />
<p:inputText id="j_username" required="true"
value="#{loginBean.username}">
</p:inputText>
<h:outputLabel for="j_password" value="Password:" />
<p:password id="j_password" required="true"
value="#{loginBean.password}">
</p:password>
<h:outputText for="_spring_security_remember_me" value="Remember me" />
<p:selectBooleanCheckbox id="_spring_security_remember_me"
value="#{loginBean.rememberMe}" />
<f:facet name="footer">
<p:commandButton type="submit" id="login" ajax="false"
actionListener="#{loginBean.doLogin}" value="Login" />
</f:facet>
</p:panelGrid>
</div>
</h:form>
</h:body>
loginBean.java
@Component
@Scope("request")
@ManagedBean
@RequestScoped
public class LoginBean {
private static final Log logger = LogFactory.getLog(LoginBean.class);
private String username = "";
private String password = "";
private boolean rememberMe = false;
private boolean loggedIn = false;
public String doLogin() throws IOException, ServletException {
logger.info("Start login sequence");
logger.info("Credentials: " + username + ":" + password
+ ", rememberMe:" + rememberMe);
ExternalContext context = FacesContext.getCurrentInstance()
.getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
.getRequestDispatcher("/j_spring_security_check");
ServletRequest request = ((ServletRequest) context.getRequest());
String checkboxValue = request
.getParameter("_spring_security_remember_me_input");
logger.info("Value of rememberMe option: " + checkboxValue);
dispatcher.forward((ServletRequest) context.getRequest(),
(ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
// It's OK to return null here because Faces is just going to exit.
return null;
}
public String getUsername() {
return this.username;
}
public void setUsername(final String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(final String password) {
this.password = password;
}
public boolean isRememberMe() {
return this.rememberMe;
}
public void setRememberMe(final boolean rememberMe) {
this.rememberMe = rememberMe;
}
public boolean isLoggedIn() {
return this.loggedIn;
}
public void setLoggedIn(final boolean loggedIn) {
this.loggedIn = loggedIn;
}
}
Klasy LoginErrorPharseListener i RememberMePostProcessor bez zmian. Bardzo prosze o jakieś wskazówki. A może ktoś wie jak inaczej zabrać się za temat spring security i primefaces to też prosze podpowiadać.