Saturday, August 1, 2009

Form Login for WebSphere Application Server 6.1

To enable a form based login (instead of a Basic Authentification) edit the web.xml of the application and add a login configuration:

FORMExample Form-Based Authentication Area/login.jsp/error.jsp
The login.jsp contains the login form (ibm example):
Security FVT Login Page

Form Login

Enter user ID and password:
User ID Password

And then click this button:



the error.jsp contains an error message (ibm example):

A Form login authentication failure occurred</head>

A Form login authentication failure occurred

Authentication may fail for one of many reasons. Some possibilities include:

  1. The user-id or password may be entered incorrectly; either misspelled or thewrong case was used.
  2. The user-id or password does not exist, has expired, or has been disabled.


So whats going on (example):
1. User is trying to access http://example.com/app/index.html
2. User get redirected to http://example.com/app/login.jsp
2.1 WAS creates a cookie called WASReqURL which contains the whished path (Value: http[s]://[:Port]/app/index.jsp)
3. User types in user-id and passwort and submits the login credentials
3.1 WAS reads the WASReqURL-Cookie and redirects the the requested path (http://example.com/app/index.html).
3.2 If the credentials are wrong WAS redirects the user to http://example.com/app/error.jsp
It is possible to edit the WASReqURL-Cookie to change the redirect path after a successful login.
Steps:
1. Read cookie Value:

1.
String url ="";
2.
String text = "";
3.
String newurl = "";
4.
//Get all cookies
5.
Cookie[] cookies = request.getCookies();
for (int index=0; index <= cookies.length; index++) {
6.
String cookieName = cookies[index].getName();
7.
if ("WASReqURL".equals(cookieName)) {
8.
//If WASReqURL-Cookie is found, get the value and cancel for-loop urlwithoutlogging = cookies[index].getValue();
9.
break;
10.
}
11.
}

2. Set a new WASReqURL-Cookie

1.
Cookie wasrequrlcookie = new Cookie("WASReqURL",newurl));
2.
response.addCookie(wasrequrlcookie);

Links: