/*AUTHOR: JAKE W. HOLMES */ /*DATE: SEPTEMBER 08, 1999 */ /*Securer applet is just a simple applet to give peaple who are not aloud cgi on their server an option to secure certain pages. What the applet does is take a base URL as a parameter which includes the full URL to the secured directory, minus the directory name. example: If your secured directory was placed at the address: http://freepages/joespage/securedstuff/secret/ then you would pass the following URL as the target parameter: http://freepages/joespage/securedstuff/ and the password would be "secret". To change the password you need only change the name of the directory. There must be an index.html file within your passworded directory. The other parameter, badURL, is just the URL address to an html page that will be displayed when the password is incorrect. Feel free to improve on this code. Let me know what you do with it by e-mailing me at blade25@worldnet.att.net or jake@mvmt.com */ import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.*; import java.io.*; public class securer extends Applet implements ActionListener { public void init() { /*GET THE APPLET PARAMETERS*/ target = getParameter("target"); badURL = getParameter("badURL"); /*BASIC LAYOUT OF APPLET, A SIMPLE TEXT DISPLAY AND BUTTON*/ setLayout(new BorderLayout()); display = new TextField(""); display.setEditable(true); Panel p = new Panel(); p.setLayout(new GridLayout(1,2)); p.add(display); addButton(p, "ENTER"); add(p, "North"); } /*WHEN BUTTON IS PRESSED PERFORM THE FOLLOWING*/ public void actionPerformed(ActionEvent evt) { int i; boolean correctPassword = true; { try { AppletContext context = getAppletContext(); /*APPEND THE PASSWORD GIVEN TO THE END OF THE BASE ADDRESS PASSED AS TARGET PARAMETER */ /*THIS GIVES THE ADDRESS TO THE SECURED DIRECTORY, WHICH HAS THE SAME NAME AS THE PASSWORD*/ URL u = new URL((String)(target + display.getText() + "/")); /*IF THERE IS ANY CONTENT IN THE NEW URL FORMED BY APPENDING THE PASSWORD GIVEN*/ /*THEN WE ASSUME THE THE PASSWORD WAS CORRECT*/ try { u.getContent(); } /*IF THERE WASN'T ANY CONTENT IN THE NEW URL, THEN WE ASSUME THE PASSWORD WAS INCORRECT*/ catch(Exception dd) { correctPassword = false; System.out.println("NULL: " + dd); } /*IF THE PASSWORD WAS FOUND TO BE CORRECT, THEN SHOW THE SECURED DOCUMENT*/ if(correctPassword) context.showDocument(u); } catch(Exception e) { showStatus("ERROR " + e); } } /*IF PASSWORD WAS FOUND TO BE INCORRECT, THEN SHOW THE BADPASSWORD DOCUMENT*/ if (!correctPassword) { try { AppletContext context = getAppletContext(); URL u = new URL((String)badURL); context.showDocument(u); } catch(Exception ef) { showStatus("ERROR " + ef + " bad badURL parameter to securer applet"); } } } public void addButton(Container c, String s) { Button b = new Button(s); c.add(b); b.addActionListener(this); } private static TextField display; private static String target; //base address for secured directory private static String badURL; //URL for page shown when password incorrect }