Configure interceptors to obtain interceptor configuration information and decrypt login information to avoid URL address plaintext display

Source: Internet
Author: User
Tags base64 decrypt

Web.xml

<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "> <!--Default Access index page--> <welcome-file-list> < Welcome-file>index.jsp</welcome-file> </welcome-file-list> <!--load-time Unified authentication Interceptor Start--> <filter > <filter-name>TassSSOLoginFilter</filter-name> <filter-class>com.filter.tassssologinfilter </filter-class> <!--application number--> <init-param> <param-name>APPID</param-name> <para M-value>53</param-value> </init-param> <!--application permission switch--> <init-param> <param-name> Vapp</param-name> <param-value>true</param-value> </init-param> <!--bill AD check switch--> & Lt;init-param> <param-name>vad</param-name> <param-value>true</param-value> </init-param> <!--bill AD checksum URL--> <!--Init-para M> <param-name>VADURL</param-name> <param-value> Http://127.0.0.1:8080/bakgcjAppl/verifyad. JSP </param-value> </init-param--> <!--bill IP checksum URL--> <!--init-param> <param-name& Gt 
		vipurl</param-name> <param-value> http://127.0.0.1:8080/bakgcjAppl/verifyip.jsp </param-value> </init-param--> <!--save user information, apply information to session switch--> <!--init-param> <param-name>UFAPP< /param-name> <param-value>true</param-value> </init-param--> <!--error message display URL--> <in it-param> <param-name>ERRURL</param-name> <param-value> Http://127.0.0.1:8080/bakgcjAppl/EI p.jsp </param-value> </init-param> </filter> <filter-mapping> <filter-name>tasss Sologinfilter</filTer-name> <!--address interception--> <url-pattern>/login.jsp</url-pattern> </filter-map for login page requests
 Ping> <!--Unified Authentication Interceptor End--> </web-app>


Tassssologinfilter

Package com.filter;
Import java.io.IOException;

Import Java.net.URLEncoder;
Import Javax.servlet.Filter;
Import Javax.servlet.FilterChain;
Import Javax.servlet.FilterConfig;
Import javax.servlet.ServletException;
Import Javax.servlet.ServletRequest;
Import Javax.servlet.ServletResponse;

Import Javax.servlet.http.HttpServletResponse;


Import com.tass.util.Base64;
	public class Tassssologinfilter implements filter{/* Application number */public static String APPID;
	/* Apply permission Switch * * private static Boolean VAPP;
	* * Bill AD Check switch * * private static Boolean VAD;
	* * Ticket AD checksum URL/private static String Vadurl;
	/* Bill IP check URL/private static String Vipurl;
	/* Save user information, apply information to session switch/private static Boolean Ufapp;

	/* error message Display URL */public static String Errurl;  public void Destroy () {} public void Dofilter (ServletRequest request, servletresponse response, Filterchain chain)
		Throws IOException, servletexception {HttpServletResponse resp = (httpservletresponse) response; /* Set the encoding and clear the page cache* * Resp.setcontenttype ("text/html;
		CHARSET=GBK ");
		Resp.setheader ("Pragma", "No-cache");
		Resp.setheader ("Cache-control", "No-cache");

	   Resp.setdateheader ("Expires", 0);
	   String username = request.getparameter ("username");
	   if (username = = null) {Chain.dofilter (request, response); }else{//Encryption if (Username.equals ("Zhangsan")) {username = Urlencoder.encode ("BASE64" + base64.encode (Usernam
			   E.getbytes ()), "Utf-8");
		   Resp.sendredirect ("login.jsp?desc=" + username);
		   }else{Resp.sendredirect (Errurl); /** * @description Interceptor initialization * Used to obtain interceptor configuration information * @param filterconfig Interceptor Configuration/public void init
		(Filterconfig filterconfig) throws Servletexception {/* application number */APPID = Filterconfig.getinitparameter ("APPID");
		APPID = Appid==null? "": APPID;

		System.out.println ("Tassssologinfilter APPID:" +appid);
		/* Apply permission switch/String Vapp = Filterconfig.getinitparameter ("Vapp"); VAPP = (vapp!=null) && ("true". Equals (VAPP));

		System.out.println ("Tassssologinfilter VAPP:" +vapp);
		/* Bill AD Check switch/String VAD = Filterconfig.getinitparameter ("Vad");
		VAD = (vad!=null) && ("true". Equals (VAD));

		System.out.println ("Tassssologinfilter VAD:" +vad);
		/* Ticket AD Check URL * * * Vadurl = Filterconfig.getinitparameter ("Vadurl");
		Vadurl = Vadurl==null? "": Vadurl;

		System.out.println ("Tassssologinfilter vadurl:" +vadurl);
		/* Bill IP Check url/vipurl = Filterconfig.getinitparameter ("Vipurl");
		Vipurl = Vipurl==null? "": Vipurl;

		System.out.println ("Tassssologinfilter vipurl:" +vipurl);
		/* Save user information, apply information to session switch/String Ufapp = Filterconfig.getinitparameter ("Ufapp");
		Ufapp = (ufapp!=null) && ("true". Equals (Ufapp));

		System.out.println ("Tassssologinfilter ufapp:" +ufapp);
		/* error message Display URL */errurl = Filterconfig.getinitparameter ("Errurl");
		Errurl = Errurl==null? "": Errurl;
System.out.println ("Tassssologinfilter errurl 1:" +errurl);
Errurl = "appid=" +APPID; System.out.println ("TassssologInfilter Errurl 2: "+errurl");
 }
}

index.jsp

<a href= "Login.jsp?username=zhangsan" > Login </a>



Url:

Http://127.0.0.1:8080/bakgcjAppl/login.jsp?desc=BASE64emhhbmdzYW4%3D


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.