3- login.xhtml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:ace="http://www.icefaces.org/icefaces/components">
<h:head>
<ice:outputStyle href="./resources/stylesheet.css" id="outputStyle1"/>
<ice:outputStyle href="./xmlhttp/css/xp/xp.css" id="outputStyle2"/>
</h:head>
<h:body bgcolor="#677070" id="outputBody1" style="-rave-layout: grid">
<ice:panelLayout id="panelLayout2" style="border-width: 1px; background-color:#d9dbdb ; height: 100%; left: 0px; top: 0px; position: absolute; width: 40%"/>
<ice:panelLayout id="panelLayout3" style="border-width: 3px; border-style: solid; border-color: rgb(51, 0, 0) rgb(51, 0, 0) rgb(51, 0, 0) rgb(51, 0, 0); background-color: rgb(255, 255, 255); height: 330px; left: 408px; top: 144px; position: absolute; width: 570px; -rave-layout: grid">
<h:form>
<ice:graphicImage id="graphicImage1" style="height: 322px; left: 0px; top: 0px; position: absolute" url="/resources/images/LoginImage.jpg" width="560"/>
<ice:outputLabel for="j_username" id="outputLabel1" style="left: 48px; top: 120px; position: absolute" value="Username:"/>
<ice:outputLabel for="j_password" id="outputLabel2" style="left: 48px; top: 168px; position: absolute" value="Password:"/>
<ice:inputText binding="#{login.username}" id="j_username" required="true"
style="left: 142px; top: 118px; position: absolute; width: 237px" />
<ice:inputSecret binding="#{login.password}" id="j_password" required="true" style="left: 142px; top: 166px; position: absolute; width: 237px"/>
<ice:commandButton actionListener="#{login.login}" id="loginBtn" style="left: 144px; top: 240px; position: absolute" value="Login"/>
<ice:commandButton action="#{login.reset}" id="resetBtn" style="position: absolute; left: 360px; top: 240px" value="Reset"/>
<ice:outputText id="errorMessage" style="left:0px;top:300px;position:absolute"/>
<ice:message errorClass="errorMessage" for="j_username" fatalClass="fatalMessage" id="messages1" infoClass="infoMessage" showSummary="false"
style="height: 43px; left: 24px; top: 288px; position: absolute; width: 523px;color:red;" warnClass="warnMessage"/>
</h:form>
</ice:panelLayout>
</h:body>
</html>
4- LoginBean:
Code:
package com.spring.sample.beans;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.security.web.authentication.AbstractProcessingFilter;
import org.springframework.stereotype.Component;
@SuppressWarnings("deprecation")
@Component("login")
@Scope("request")
public class LoginBean {
Log log = LogFactory.getLog(getClass());
private String username;
private String password;
/**
* default empty constructor
*/
public LoginBean() {
Exception ex = (Exception) FacesContext
.getCurrentInstance()
.getExternalContext()
.getSessionMap()
.get(AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY);
if (ex != null)
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, ex
.getMessage(), ex.getMessage()));
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void login(ActionEvent e) throws Exception {
log.debug("Login Button Action");
FacesContext
.getCurrentInstance()
.getExternalContext()
.redirect(
"/myapp/j_spring_security_check?j_username="
+ username + "&j_password=" + password);
}
public String reset() throws Exception {
setUsername("");
setPassword("");
return "";
}
}