Friday, April 11, 2014

Create custom Authentication Filters for websphere portal 7/8

Create custom Authentication Filters for websphere portal 7/8




Portal authentication filters are used to intercept the portal login, logout or session timeout and process custom code.  Like redirecting the user to a specific landing page based on the users roles instead of the homepage.

Portal authentication filters uses the same pattern as servlet filters.

Available authentication filter chains
The filter chain concept described in the previous section is applied to six types of events that concern the flows of Portal login, logout, and session handling. This provides a flexible approach to plug custom logic to each of those flows. In particular, there are filter chains for the following events:
  • Explicit login: This is a login by user name and password as represented by the interface com.ibm.portal.auth.ExplicitLoginFilter. 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 com.ibm.portal.auth.ImplicitLoginFilter.
  • Explicit logout: This means that the user triggers a logout action directly, for example by clicking the Logout button in the user interface, interface com.ibm.portal.auth.ExplicitLogoutFilter.
  • 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 com.ibm.portal.auth.ImplicitLogoutFilter.
  • Session Timeout: This is called immediately after an idle timeout of the user session occurred. This is represented by the interface com.ibm.portal.auth.SessionTimeoutFilter.
  • Session Validation: This is called for every request before actions are triggered and the page is rendered. This is represented by the interface com.ibm.portal.auth.SessionValidationFilter.
Besides the session timeout filter, each of the previous filters has access to the HTTP request and response objects. A special context object can be used to share information between filters and set redirects that are executed after the filter chain has been processed. For more detailed information about each of the filter and the filter chain interfaces see the documentation for both WebSphere® Portal and the API JavaDoc. For a filter chain example see the topic with the Example of a custom authentication filter.

Steps for creating Authentication filters.

In Rad create a java project. Lets say TestAuthfilters and implement one of the six filters.
Add the below 4 jars to your projects build path.


Below is the sample code to implement custom Explicit login filter.

package com.test.authfilters;

import java.io.IOException;

import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.portal.auth.ExplicitLoginFilter;
import com.ibm.portal.auth.ExplicitLoginFilterChain;
import com.ibm.portal.auth.FilterChainContext;
import com.ibm.portal.auth.exceptions.AuthenticationException;
import com.ibm.portal.auth.exceptions.AuthenticationFailedException;
import com.ibm.portal.auth.exceptions.PasswordInvalidException;
import com.ibm.portal.auth.exceptions.SystemLoginException;
import com.ibm.portal.auth.exceptions.UserIDInvalidException;
import com.ibm.portal.security.SecurityFilterConfig;
import com.ibm.portal.security.exceptions.SecurityFilterInitException;
import com.ibm.websphere.security.WSSecurityException;

public class TestExplicitLoginFilter implements ExplicitLoginFilter {
     
      public void login(HttpServletRequest req, HttpServletResponse resp,
                  String userid, char[] password, FilterChainContext portalLoginContext, Subject subject,
                  String realm, ExplicitLoginFilterChain chain) throws LoginException,
                  WSSecurityException, PasswordInvalidException,
                  UserIDInvalidException, AuthenticationFailedException,
                  AuthenticationException, SystemLoginException,
                  com.ibm.portal.auth.exceptions.LoginException {
            // TODO Auto-generated method stub
           
            chain.login(req,resp, userid, password, portalLoginContext, subject, realm);
             
                  if(userid.equals(paul){
setRedirectURL(req, context, "/wps/myportal/pageA");
}else{
setRedirectURL(req, context, "/wps/myportal/pageB");

}
                  }
         

     

      @Override
      public void destroy() {
            // TODO Auto-generated method stub

      }

      @Override
      public void init(SecurityFilterConfig arg0)
                  throws SecurityFilterInitException {
           
      }

}


Registering the authentication filters.
Login to WAS Integrated solutions console
Under Resources -> resource Environment -> Resource Enviornment Provides -> click WP_AuthenticationService -> custom properties.
And select New
Enter the below values
Name:- login.explicit.filterchain
Value :- com.test.authfilters.TestExplicitLoginFilter
 
Click apply and save the changes. 
Now export your project as jar and copy it to portalServer_root/shared/app folder
And restart the portal server for these changes to take effect. 

13 comments:

  1. This is really good.
    I would like to log in in the theme using a form and after login i want to be in the same page not directed to Home.How can I do that?
    Thanks

    ReplyDelete
    Replies
    1. Thank you for this great explanation about authentication filter chains, its really good and informative. The reviews and proposals are also make more impact.

      Delete

  2. Sudah seru, odds nya menguntungkan lagi!!. itulah permainan sabung ayam online di agen sabung ayam
    Dapatkan informasi penting dalam dunia sabung ayam di website bawah ini
    https://agentaruhanayam.quora.com/Memahami-Permainan-Sabung-Ayam-CFT2288-Yang-Baru-Diluncurkan

    ReplyDelete
  3. Langkah Tepat Untuk Memenangkan Permainan Situs Judi Sabung Ayam Online Klik Di Sini

    Agen Judi Sabung Ayam Online Terpercaya & Terbaik Di Asia http://www.bakarayam.co

    Informasi Terlengkap Mengenai Sabung Ayam

    http://bakarayam33033.blogspot.com/2018/08/vitamin-harus-dikasihkan-terhadap-tipe.html/

    ReplyDelete
  4. Besides the session timeout filter, every of the previous filters has access to the HTTP request and response objects. A special context object may be accustomed share info between filters and set redirects that ar dead once the filter chain has been processed cheap essay writing service.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. If we are using jackson features in Custom filer then we have to provide jackson jar files otherwise while executing, custom filter throws jackson related class not found exception. How to solve this and How to provide dependency jar files.

    ReplyDelete
  7. Yakin anda selalu tidak hoki?? Kami tantang anda yang merasa selalu tidak hoki... Kami yakin tidak ada orang yang tidak hoki...disini akan kami adu hoki anda dengan hoki pemain lain...
    ==DONACOPOKER=
    Kami yakin anda lebih hoki bersama kami..!! sudah terbukti....

    Ayo segera bergabung dan dapatkan tips-tips menang dari kami
    Tips Jitu Poker

    Cara Daftar Deposit PULSA

    Hubungi Kami Secepatnya Di :
    WHATSAPP : +6281333555662

    ReplyDelete
  8. BPO Solutions is a Pakistani based, RPO & BPO Company in Lahore.
    info@bposol.com

    ReplyDelete
  9. If you are looking for the Finance Accounting Assignments help then in this case you can opt for our Finance Accounting Assignments help.we provide the best Online Assignment Help.We also provide Forensic Accounting Homework Help for students across the globe. for more information contact us +16692714848.

    ReplyDelete
  10. We Fullassignment.com is among the best companies on the Programming Database and IT Assignments Help writing market. We offer top-notch essays, Online Programming Assignment Help research papers, thesis and other types of works that can be assigned to you at a high school or college. We also provide HTML Markup Language Help from our experts. for more information contact us +16692714848.

    ReplyDelete
  11. Congratulations on receiving a great response to your post! We at the MyAssignmentHelpAU platform understand how difficult it can be for the students to manage complicated assignments in high school, college, or university, therefore, we have introduced an exclusive Dissertation Writing Service facility that will cater to all your writing requirements precisely.

    ReplyDelete
  12. Appreciative of my wellbeing and good health. In this article, you'll unearth a hidden gem Army Color Blind Test. A soldier may be given a different position if a color blindness test is successful.

    ReplyDelete

comments