我必须创建一个ADF应用程序,其中有一个登录页面。登录页面有两个用于用户名和密码的输入字段,一个用于员工类型的单选按钮(即员工或经理)和一个提交按钮。
现在,根据用户的类型,应该将其重定向到员工或经理页面。
对于凭据我正在使用ADF安全功能。我创建了两个用户,一个用于管理员角色,另一个用于员工角色。
我正在使用Java类登录: -
package demo.view;
import java.io.IOException;
import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class Login {
private String _username;
private String _password;
private String typeOfEmpl;
public void setUsername(String _username) {
this._username = _username;
}
public String getUsername() {
return _username;
}
public void setPassword(String _password) {
this._password = _password;
}
public String getPassword() {
return _password;
}
public void setTypeOfEmpl(String typeOfEmpl) {
this.typeOfEmpl = typeOfEmpl;
}
public String getTypeOfEmpl() {
return typeOfEmpl;
}
public String doLogin() {
FacesContext ctx = FacesContext.getCurrentInstance();
if (_username == null || _password == null) {
showError("Invalid credentials", "An incorrect username or password was specified.", null);
} else {
ExternalContext ectx = ctx.getExternalContext();
HttpServletRequest request = (HttpServletRequest) ctx.getExternalContext().getRequest();
try {
request.login(_username, _password);
_username = null;
_password = null;
HttpSession session = request.getSession();
session.setAttribute("success_url", "/faces" + ctx.getViewRoot().getViewId());
redirect(ectx.getRequestContextPath() + "/adfAuthentication");
} catch (ServletException fle) {
showError("ServletException", "Login failed. Please verify the username and password and try again.",
null);
}
}
return null;
}
private void redirect(String forwardUrl) {
FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext ectx = ctx.getExternalContext();
try {
ectx.redirect(forwardUrl);
} catch (IOException ie) {
showError("IOException", "An error occured during redirecting. Please consult logs for more info.", ie);
}
}
private void showError(String errType, String message, Exception e) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, errType, message);
FacesContext.getCurrentInstance().addMessage("d2:it35", msg);
if (e != null) {
e.printStackTrace();
}
}
}
此代码仅允许访问应用程序特权的人员。但是我无法将员工或经理的无线电选择与他们的页面联系起来。
如何将这两种信息(即安全登录和应根据其工作打开的页面)相关联,并推进我的申请。
答案 0 :(得分:0)
尝试使用任务流路由器作为页面流的开始,以查看用户角色的值,并根据它直接指向正确的页面。 使用EL访问使用的角色。 更多信息 - http://www.oracle.com/technetwork/issue-archive/2012/12-jan/o12adf-1364748.html