Thursday, June 7, 2012
Login , Logout and Session Time Out Filter in WebSphere Portal
Here useful filter used when user log in, log out and session time in WebSphere portal
Example
package com.filter;
import com.ibm.websphere.security.WSSecurityException;
import com.ibm.portal.auth.ExplicitLoginFilter;
import com.ibm.portal.auth.ExplicitLoginFilterChain;
import com.ibm.portal.auth.FilterChainContext;
import com.ibm.portal.auth.exceptions.*;
import com.ibm.portal.security.SecurityFilterConfig;
import com.ibm.portal.security.exceptions.SecurityFilterInitException;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SampleLoginFilter implements ExplicitLoginFilter {
public void login(HttpServletRequest req, HttpServletResponse arg1,
String arg2, char[] arg3, FilterChainContext arg4, Subject arg5,
String arg6, ExplicitLoginFilterChain chain) throws LoginException,
WSSecurityException, PasswordInvalidException,
UserIDInvalidException, AuthenticationFailedException,
AuthenticationException, SystemLoginException,
com.ibm.portal.auth.exceptions.LoginException {
// TODO Auto-generated method stub
System.out.println("SampleLoginFilter login successfull from filter 1");
chain.login(req, arg1, arg2, arg3, arg4, arg5, arg6);
System.out.println("SampleLoginFilter login successfull from filter 2");
System.out.println("SampleLoginFilter login"+req.getRemoteHost());
System.out.println("SampleLoginFilter login"+req.getLocalAddr());
}
public void destroy() {
// TODO Auto-generated method stub
}
public void init(SecurityFilterConfig arg0)
throws SecurityFilterInitException {
// TODO Auto-generated method stub
System.out.println("SampleLoginFilter init");
}
}
------------------------------------------------------------------------
package com.filter;
import javax.security.auth.login.LoginException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.portal.auth.ExplicitLogoutFilter;
import com.ibm.portal.auth.FilterChainContext;
import com.ibm.portal.auth.LogoutFilterChain;
import com.ibm.portal.auth.exceptions.LogoutException;
import com.ibm.portal.security.SecurityFilterConfig;
import com.ibm.portal.security.exceptions.SecurityFilterInitException;
public class SampleLogoutFilter implements ExplicitLogoutFilter {
public void logout(HttpServletRequest arg0, HttpServletResponse arg1,
FilterChainContext arg2, LogoutFilterChain chain)
throws LogoutException, LoginException {
// TODO Auto-generated method stub
System.out.println("SampleLogoutFilter logout successfull from filter 1");
chain.logout(arg0, arg1, arg2);
System.out.println("SampleLogoutFilter logout successfull from filter 2");
}
public void destroy() {
// TODO Auto-generated method stub
}
public void init(SecurityFilterConfig arg0)
throws SecurityFilterInitException {
// TODO Auto-generated method stub
}
}
----------------------------------------------------------------------------------------------
package com.filter;
import java.util.Map;
import javax.servlet.http.HttpSession;
import com.ibm.portal.auth.SessionTimeoutFilter;
import com.ibm.portal.auth.SessionTimeoutFilterChain;
import com.ibm.portal.auth.exceptions.UserSessionTimeoutException;
import com.ibm.portal.security.SecurityFilterConfig;
import com.ibm.portal.security.exceptions.SecurityFilterInitException;
public class SampleSessionTimeoutFilter implements SessionTimeoutFilter {
public void onUserSessionTimeout(HttpSession arg0, Map arg1,
SessionTimeoutFilterChain chain) throws UserSessionTimeoutException {
// TODO Auto-generated method stub
System.out.println("SampleSessionTimeoutFilter timeout successfull from filter 1");
chain.onUserSessionTimeout(arg0, arg1);
System.out.println("SampleSessionTimeoutFilter timeout successfull from filter 1");
}
public void destroy() {
// TODO Auto-generated method stub
}
public void init(SecurityFilterConfig arg0)
throws SecurityFilterInitException {
// TODO Auto-generated method stub
}
}
-----------------------------------------------------------
Add above filter in WP AuthenticationService under Resources > Resource Environment > Resource Environment Providers >
Custom properties
Value as below
name : login.explicit.filterchain
Value : com.filter.SampleLoginFilter
name :logout.explicit.filterchain
Value :com.filter.SampleLogoutFilter
name :sessiontimeout.filterchain
Value : com.filter.SampleSessionTimeoutFilter
Subscribe to:
Posts (Atom)