Step by Step creating a custom authentication filter in WebSphere Portal


Types of authentication filter

Explicit login: This is a login by user name and password as represented by the For example, this can be a login by using the login portlet or the login URL.

Implicit login: For example, this can be when a user is already authenticated by WAS, but not yet to Portal. This is represented by the interface

Explicit logout: This means that the user triggers a logout action directly, for example by clicking the Logout button in the user interface, interface

Implicit logout: For example, this can be after a session timeout, or if an authenticated user accesses a public page, or if the user navigates to a virtual portal without being member of the associated user realm. This is represented by the interface

Session Timeout: This is called immediately after an idle timeout of the user session occurred. This is represented by the interface

Session Validation: This is called for every request before actions are triggered and the page is rendered. This is represented by the interface

Steps to be followed to Create Custom Filter

To create a custom authentication filter, follow the below steps:

1. Implement one of the available 6 filter interfaces.
2. Export your implementation as a JAR onto the Portal class path, for example, profile_root/shared/app.
3. Complete the following steps to register the filter in WebSphere Application Server:
  • Login to the WebSphere Application Server Integrated Solutions Console as an Administrator.
  • Select Resources->Resource Environment Providers->WPAuthenticationService->Custom properties.
  • Add a new entry to register your custom filter as shown in below screenshot.
4. Restart WebSphere Portal for the changes to take effect.

Creating Custom Explicit LoginFilter

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestExplictFilter implements ExplicitLoginFilter{

public void destroy() {}

public void init(SecurityFilterConfig arg0) throws SecurityFilterInitException {}

public void login(HttpServletRequest req, HttpServletResponse resp, String userID, char[] password, FilterChainContext portalLoginContext, Subject subject, String realm, ExplicitLoginFilterChain chain) throws, WSSecurityException, PasswordInvalidException, UserIDInvalidException, AuthenticationFailedException, AuthenticationException, SystemLoginException,
LoginException {
// first call the next filter in the chain to pass on the login information

try {
   chain.login(req, resp, userID, password, portalLoginContext, subject, realm);
} catch ( e) { }
}  }

Registering the service

  • One the WAS console and navigate to Resources -> Environment Resource Provider -> WP_Authentication Service -> Custom Properties

Authentication Filter

  • Create a new property with the following details.
Name: login.explicit.filterchain
Value: com.sample.login.filter.TestExplictFilter
  •  Click Save to save the configuration and now try to login to the portal server to hit the filter.
  • Output of filter can be checked in the System.out logs.

No comments:

Post a Comment

Recent Posts

Popular Posts

© 2011-2019 Web Portal Club