About Me

My photo
Talk to me... you will know

Wednesday, December 14, 2011

Custom login interceptor


The login in a struts page needs a proper interceptor to handle all possible cases of login... Have tried to make one that works :)


package com.interceptor;


import java.util.List;


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


import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.StrutsStatics;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;






import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.user.User_Info;


public class LoginInterceptor extends AbstractInterceptor implements StrutsStatics
{


private static final long serialVersionUID = 1L;
HttpSession session;
HttpServletRequest request;
HttpServletResponse response;
String t;

@Override
public String intercept(ActionInvocation actin) throws Exception
{
//System.out.println("call interceptor");
ActionContext ctx=actin.getInvocationContext();
request=(HttpServletRequest)ctx.get(HTTP_REQUEST) ;
response=(HttpServletResponse) ctx.get(HTTP_RESPONSE);
session =  request.getSession (true);
Object user = session.getAttribute ("user");
   if (user == null)
   {
    //System.out.println("inside near user=null");
    String trylog = request.getParameter("user");
       if (! StringUtils.isBlank (trylog) )
       {
        //System.out.println("try");
        String usern=request.getParameter("user").toString();
   
        String pass=request.getParameter("pass").toString();
        SessionFactory sf=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
        Session ses= sf.openSession();
        //System.out.println("enter id");
        User_Info u=new User_Info();
        try
        {
        List l = ses.createQuery("select password from com.user.User_Info e where e.user_id="+"'"+usern+"'").list();
        for(Object o:l)
        {
        t=(String) o;
       
        }


        }
        catch (HibernateException e)
        {
        e.printStackTrace();
        }
        if(pass.equals(t.toString()))
        {
        //System.out.println("ho gaya");
        session.setAttribute("user", usern);
        //request.setAttribute("page", "dummy.jsp");//Following line of code is for a concern of a project for using a master page to include other pages by calling the page required to be included from session
        return "success";
        }
        /*else
        {
        System.out.println("cookie");
        Cookie c[]=request.getCookies();
        if(c==null)
{
       
        int counter = 1;
        Cookie cnt = new Cookie("count",new Integer(counter).toString());
        cnt.setMaxAge(65000);
        System.out.println(cnt);
        response.addCookie(cnt);
        }
        else
{
        for(int i=0;i<c.length;i++)
{
        if(c[i].getName().equals("count"))
        {
        int count = Integer.parseInt(c[i].getValue());
         if(count<3)
 {
          count++;
          //System.out.println("now="+count);
          c[i].setValue(new Integer(count).toString());
          response.addCookie(c[i]);
          return "login";
         }
         else
         {
         count++;
         c[i].setValue(new Integer(count).toString());
         response.addCookie(c[i]);
 return "change";
         }
        }
        }
}
       
     
        ses.close();
        System.out.println(u);
        }*/
    return "login";
       
       }


       else
{
           
         Object action = actin.getAction ();
     if (action instanceof com.opensymphony.xwork2.ValidationAware)
 {
    ((com.opensymphony.xwork2.ValidationAware) action).addActionError ("Username / password / code incorrect!");
     }
   
       }
       return "login";
   }
else
    {
    return actin.invoke();
    }
    }
}

80 comments:

  1. Pega Training in Chennai
    Brilliant article. The information I have been searching precisely. It helped me a lot, thanks. Keep coming with more such informative article. Would love to follow them.

    ReplyDelete
  2. I was looking about the Oracle Training in Chennai for something like this,Thank you for posting the great content..I found it quiet interesting, hopefully you will keep posting such blogs…
    Greens Technologies In Chennai

    ReplyDelete
  3. You have stated definite points about the technology that is discussed above. The content published here derives a valuable inspiration to technology geeks like me. Moreover you are running a great blog. Many thanks for sharing this in here.

    Salesforce Training
    Salesforce training in chennai
    Salesforce training institutes in chennai

    ReplyDelete
  4. I would recommend the Qlikview course to anyone interested in learning Business Intelligence .Absolutely professional and engaging training sessions helped me to appreciate and understand the technology better. thank you very much if our dedicated efforts and valuable insights which made it easy for me to understand the concepts taught and more.. qlikview Training in Chennai

    ReplyDelete
  5. Thanks for sharing this informative blog .To make it easier for you visualizing all the materials about (OBIEE).SO lets Start brightening your future.and using modeling tools how to prepare and build objects and metadata to be used in reports and more trained itself visit obiee Training in Chennai

    ReplyDelete
  6. Greens Technology offer a wide range of training from ASP.NET , SharePoint, Cognos, OBIEE, Websphere, Oracle, DataStage, Datawarehousing, Tibco, SAS, Sap- all Modules, Database Administration, Java and Core Java, C#, VB.NET, SQL Server and Informatica, Bigdata, Unix Shell, Perl scripting, SalesForce , RedHat Linux and Many more.

    ReplyDelete
  7. Thanks for sharing this information article
    Hi we at Colan Infotech Private Limited , a company which is Situated in US and India, will provide you best service and

    our talented team will assure you best result and we are familiar with international markets, We work with customers in a

    wide variety of sectors. Our talented team can handle all the aspects of custom application development, we are the best

    among the dot net development companies in Chennai .
    asp .net web development company.
    We have quite an extensive experience working with
    asp .net development services. we are the only
    asp.net web development company
    which offer custom services to a wide range of industries by exceeding our client’s expectations. You can even interact

    directly with the team regarding your project, just as you would with your in-house team.
    hire asp.net programmers to achieve your dream product.
    Custom application development company,
    asp.net development companies, asp .net web development company,Hire asp .net programmers,asp.net web development

    services,dot net development companies in chennai
    Hire asp .net programmers. Here is a good resource if anyone in need

    of asp.net web development services
    dot net development companies in chennai.

    ReplyDelete
  8. Brilliant article. The information I have been searching precisely. It helped me a lot, thanks. Keep coming with more such informative article. Would love to follow them. sap abap crm training

    ReplyDelete
  9. Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.
    Air Hostess Training in Chennai | Air Hostess Training Institute in Chennai | Air Hostess Academy in Chennai | Air Hostess Course in Chennai | Air Hostess Institute in Chennai

    ReplyDelete
  10. Amazing information,thank you for your ideas.after along time i have studied an interesting information's.we need more updates in your blog.
    AWS Courses in T nagar
    AWS Course in Anna Nagar
    Best AWS Training in Bangalore
    AWS Certification Training in Bangalore

    ReplyDelete
  11. QuickBooks Enterprise has almost eliminated the typical accounting process. Along with a wide range of tools and automations, it provides a QuickBooks Enterprise Support Phone Number of industry verticals with specialized reporting formats and tools

    ReplyDelete
  12. QuickBooks Customer Support Number advisors are certified Pro-advisors’ and it has forte in furnishing any type of technical issues for QuickBooks. They have been expert and certified technicians of these domains like QuickBooks accounting,QuickBooks Payroll, Point of Sales, QuickBooks Merchant Services and Inventory issues to provide 24/7 service to your esteemed customers.

    ReplyDelete
  13. Might you run a business? Can it be way too hard to manage all? You need a hand for support. Quickbooks Payroll Support Phone Number is an answer. If you wish to accomplish this through QuickBooks, you receive several advantages. Today, payroll running is currently complex. You may need advanced software.

    ReplyDelete
  14. A QuickBooks Customer Support Number package to create you clear of Financial accounting and back office worries any time to make sure you concentrate on your own expert area and yield potential development in business.

    ReplyDelete
  15. Now you can get an amount of benefits with QuickBooks Support Number. Proper analyses are done first. The experts find out of the nature pertaining to trouble. You will definately get a complete knowledge as well.

    ReplyDelete
  16. To obtain a mistake free accounting experience, our QuickBooks Enterprise Tech Support team is here to permit you focus on your organization development in place of troubleshooting the accounting errors.

    ReplyDelete
  17. No matter if you are getting performance errors or you are facing any kind of trouble to upgrade your software to its latest version, you can quickly get help with Quickbooks Support.

    ReplyDelete
  18. Why you ought to choose QuickBook Support phone Number The principal intent behind would be to give you the technical help 24*7 so as with order in order to prevent wasting your productivity hours

    ReplyDelete
  19. Are you currently scratching your head and stuck together with your QuickBooks Tech Support Phone Number related issues, you'll be only one click definately not our expert tech support team for your QuickBooks related issues.

    ReplyDelete
  20. this is one of the most luring features of QuickBooks Technical Support Number channel available on a call.You can easily avail our other beneficial technical support services easily as we are just a single call away from you.

    ReplyDelete
  21. QuickBooks Payroll Support Contact Number is available and beneficial to many business owners, accountants, CA, CPA to calculate taxes and pay employees. Types of issues and errors arise the necessity to contact the Intuit Payroll support team using QuickBooks Payroll telephone number.

    ReplyDelete
  22. Yes, our QuickBooks Enterprise Support Number may be a magic bullet to solve any QuickBooks Enterprise tech issue. Our QuickBooks Enterprise Support team comes with QuickBooks Experts who is able to solve your problems instantly as soon as they get a call on QuickBooks Enterprise number.

    ReplyDelete
  23. Well! The QuickBooks Payroll Support Number world is extremely crucial and important as well. The only that has deficiencies in knowledge battle to experience along with options.

    ReplyDelete
  24. Our customer care executives at QuickBooks Support Phone Number try not to hesitate from putting extra efforts to offer respite from the troubles brought on by QB Payroll errors.

    ReplyDelete
  25. If you should be experiencing any hiccups in running the Enterprise type of the QuickBooks Enterprise Tech Support Number for your requirements, it is best to not ever waste another second in trying to find a remedy for the problems.

    ReplyDelete

  26. Have you been encountering issues in running of QuickBooks Support Premier? We urge one to not ever have problems with losses brought on by longer downtime of the respective QB Premier.

    ReplyDelete
  27. The above mentioned solutions must be sufficient in solving the The above mentioned solutions must be sufficient in solving the QuickBooks Error Code 6000-301 and restoring your workflow. If you wish to know or are confused on some of the above-provided info, you should talk to a technical expert at QuickBooks Desktop support telephone number. and restoring your workflow. If you wish to know or are confused on some of the above-provided info, you should talk to a technical expert at QuickBooks Desktop support telephone number.

    ReplyDelete
  28. It is specially developed when it comes to wholesale, contract, nonprofit retail, and related industries. QuickBooks Enterprise Contact Phone Number is preferred for users to offer you intuitive accounting means to fix SMEs running enterprise kind of QuickBooks.

    ReplyDelete
  29. QuickBook Tech Support is software that fulfils the requirement for accuracy, correctness, etc. in Payroll calculation. Our team at QuickBooks Payroll Support contact number makes certain to combat the errors that hinder the performance with this software.

    ReplyDelete
  30. Sometimes errors may possibly also happen as a consequence of some small QuickBooks Tech Support Number Those are decimals, comma, backspace, etc.

    ReplyDelete

  31. Sometimes, many QuickBooks Support Phone Number users face unexpected issues such as for example simply linked to QuickBooks online accountant if they just grow their practice for business. Not to mention, some issues linked to QuickBooks company file, QuickBooks email service and heavy and unexpected QuickBooks error 1603 and many more.

    ReplyDelete
  32. a person can certainly project the sales associated with business. Our QuickBooks Customer Technical Support Phone Number team will certainly supply you understand how to make a projection into the business in regards to the sales this has built in an occasion period.

    ReplyDelete
  33. And as everyone knows that QuickBooks has its own great benefits and QuickBooks scan manager is among the amazing options that come with QuickBooks Support Number just to maintain your all documents.

    ReplyDelete
  34. QuickBooks Support – The core strength of each business, be it a start-up or the biggest Multi-national firms is its accounting and management. it’s looked at to be one among the foremost tedious and tough tasks to manage the Payroll of the workers, making Invoices chase sales. It really is nearly not possible not to wander away once in a very whereas following the written account to control the accounts. That is why intuit created Intuit QuickBooks Support associate degree accounting and management code. Today, QuickBooks is the most used accounting and management code out there.

    ReplyDelete
  35. Even for small companies we operate. This technique is wonderful for a medium-sized company. You may get the most wonderful financial tool. QuickBooks Payroll Support Number is present 24/7. You can actually call them anytime. The experts are thrilled to aid.

    ReplyDelete
  36. Whenever you notice that HP Laptop won’t turn on or its battery just isn't charging, it becomes necessary for you really to take an immediate help of the professionals at HP Printer Support Number. As soon as you contact HP support, they are going to quickly guide you in resolving HP laptop slow or frozen issues.

    ReplyDelete
  37. The user needs to click on the Download option present under the Driver heading or the HP Inkjet Printer Support Number user may click the option of the Basic Drivers for other driver options.

    ReplyDelete
  38. QuickBooks Payroll Support Phone Number be able to very easily keep an eye on 50 employees at the same time and you also can monitor the sheer number of working hours of each employee.

    ReplyDelete
  39. Different styles of queries or QuickBooks related issue, then you're way in the right direction. You simply give single ring at our toll-free intuit QuickBooks Payroll Support Phone Number . we shall help you right solution according to your issue. We work online and can take away the technical problems via remote access and also being soon considering the fact that problem occurs we shall fix the identical.

    ReplyDelete

  40. One will manage the Payroll, produce Reports and Invoices, Track sales, file W2’s, maintain Inventories by victimization QuickBooks. detain mind that QuickBooks Tech Support Phone Number isn’t solely restricted towards the options that we have a tendency to simply told you, it's going to do a lot more and it’ll all feel as simple as pie.

    ReplyDelete
  41. QuickBooks Technical Support Phone Number and its own attributes demand lots of care and attention. These attributes of every business or organization always need to be run in safe hands.

    ReplyDelete
  42. QuickBooks Payroll also offers a passionate accounting package which include specialized features for accountants also. You can simply all from the QuickBooks Payroll Support Phone Number for more information details. Let’s see several of your choices that are included with QuickBooks that has made the QuickBooks payroll service exremely popular.

    ReplyDelete
  43. Our dedicated team is sure with you. These are typically surely working at any hour to assist and make suggestions if you run into any QuickBooks error/s. Our QuickBooks Support Number team surely have in-depth knowledge regarding the issues and complications of QuickBooks.

    ReplyDelete
  44. It signifies that one can access our tech support for QuickBooks at any moment. Our backing team is dedicated enough to bestow you with end-to-end QuickBooks Payroll Tech Support Number solutions when you desire to procure them for every single QuickBooks query.

    ReplyDelete
  45. The QuickBooks Support Number can be obtained 24/7 to offer much-needed integration related support and to promptly take advantage of QuickBooks Premier along with other Microsoft Office software applications.

    ReplyDelete
  46. QuickBooks Online Banking users must have an integration with the banking account. This integration can be carried out either by Direct Connect or Web Connect feature. There are several other benefits associated with the online version. As is with other great utilities, QuickBooks Online is also susceptible to errors. QuickBooks Error 9999 is just one such error. Let’s take a look at what this error is. If you would like to learn how to Troubleshoot Quickbooks Error 9999 yourself, you can continue reading this blog.

    ReplyDelete