I was just following the steps given in FMW Dev Guide to create a custom login page and figured out that the DEV guide is not up-to-date.
The login method that is given in the guide is as follows:
public String doLogin() {
String un = _username;
byte[] pw = _password.getBytes();
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)ctx.getExternalContext().getRequest();
CallbackHandler handler = new SimpleCallbackHandler(un, pw);
try {
Subject mySubject = Authentication.login(handler);
ServletAuthentication.runAs(mySubject, request);
ServletAuthentication.generateNewSessionID(request);
String loginUrl = "/adfAuthentication?success_url=/faces" + ctx.getViewRoot().getViewId();
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
sendForward(request, response, loginUrl);
} catch (FailedLoginException fle) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Incorrect Username or Password", "An incorrect Username or Password" + " was specified");
ctx.addMessage(null, msg);
} catch (LoginException le) {
reportUnexpectedLoginError("LoginException", le);
}
return null;
}
However, I am using JDev 11.1.1.4, and now seems like SimpleCallbackHandler is deprecated.
I tried to import the libraries required to import this class but I was getting deployment errors after making those changes.
Then, I came around this blog by Andrejus:
http://andrejusb.blogspot.com/2010/11/things-you-must-know-about-adf-faces.html
After going through this post, figured out that now we need to use URLCallbackHandler instead of SimpleCallbackHandler, and the above method should look like :
public String doLogin() {
String un = _username;
byte[] pw = _password.getBytes();
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)ctx.getExternalContext().getRequest();
try {
Subject subject = Authentication.login(new URLCallbackHandler(un, pw));
weblogic.servlet.security.ServletAuthentication.runAs(subject, request);
String loginUrl = "/adfAuthentication?success_url=/faces" + ctx.getViewRoot().getViewId();
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
sendForward(request, response, loginUrl);
} catch (FailedLoginException fle) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Incorrect Username or Password", "An incorrect Username or Password was specified");
ctx.addMessage(null, msg);
} catch (LoginException le) {
reportUnexpectedLoginError("LoginException", le);
}
return null;
}
However, to make this work, we need to include 'WebLogic 10.3 Remote-Client' library to our project. This library points to weblogic.jar and is required for the above method to run successfully.
JDev Release 11.1.1.4
The login method that is given in the guide is as follows:
public String doLogin() {
String un = _username;
byte[] pw = _password.getBytes();
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)ctx.getExternalContext().getRequest();
CallbackHandler handler = new SimpleCallbackHandler(un, pw);
try {
Subject mySubject = Authentication.login(handler);
ServletAuthentication.runAs(mySubject, request);
ServletAuthentication.generateNewSessionID(request);
String loginUrl = "/adfAuthentication?success_url=/faces" + ctx.getViewRoot().getViewId();
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
sendForward(request, response, loginUrl);
} catch (FailedLoginException fle) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Incorrect Username or Password", "An incorrect Username or Password" + " was specified");
ctx.addMessage(null, msg);
} catch (LoginException le) {
reportUnexpectedLoginError("LoginException", le);
}
return null;
}
However, I am using JDev 11.1.1.4, and now seems like SimpleCallbackHandler is deprecated.
I tried to import the libraries required to import this class but I was getting deployment errors after making those changes.
Then, I came around this blog by Andrejus:
http://andrejusb.blogspot.com/2010/11/things-you-must-know-about-adf-faces.html
After going through this post, figured out that now we need to use URLCallbackHandler instead of SimpleCallbackHandler, and the above method should look like :
public String doLogin() {
String un = _username;
byte[] pw = _password.getBytes();
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)ctx.getExternalContext().getRequest();
try {
Subject subject = Authentication.login(new URLCallbackHandler(un, pw));
weblogic.servlet.security.ServletAuthentication.runAs(subject, request);
String loginUrl = "/adfAuthentication?success_url=/faces" + ctx.getViewRoot().getViewId();
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
sendForward(request, response, loginUrl);
} catch (FailedLoginException fle) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Incorrect Username or Password", "An incorrect Username or Password was specified");
ctx.addMessage(null, msg);
} catch (LoginException le) {
reportUnexpectedLoginError("LoginException", le);
}
return null;
}
However, to make this work, we need to include 'WebLogic 10.3 Remote-Client' library to our project. This library points to weblogic.jar and is required for the above method to run successfully.
JDev Release 11.1.1.4
No comments:
Post a Comment