KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > auth > NullAuthentication


1 /* *****************************************************************************
2  * NullAuthentication.java
3 * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.auth;
11
12 import javax.servlet.http.*;
13 import java.util.*;
14
15 public class NullAuthentication implements Authentication
16 {
17     public static final String JavaDoc DEFAULT_USERNAME = "user";
18     public String JavaDoc mDefaultUserName = null;
19
20     public void init(Properties prop) {
21         mDefaultUserName =
22             prop.getProperty("connection.none-authenticator.username", DEFAULT_USERNAME);
23     }
24
25     public int login(HttpServletRequest req, HttpServletResponse res,
26               HashMap param, StringBuffer JavaDoc xmlResponse) {
27
28         String JavaDoc usr = (String JavaDoc) param.get("usr");
29         if (usr == null)
30             usr = mDefaultUserName;
31
32         xmlResponse
33             .append("<authentication>")
34             .append("<response type=\"login\">")
35             .append("<status code=\"0\" msg=\"ok\" />")
36             .append("<username>").append(usr).append("</username>")
37             .append("</response>")
38             .append("</authentication>");
39         return 0;
40     }
41
42
43     public int logout(HttpServletRequest req, HttpServletResponse res,
44                HashMap param, StringBuffer JavaDoc xmlResponse) {
45         xmlResponse
46             .append("<authentication>")
47             .append("<response type=\"logout\">")
48             .append("<status code=\"0\" msg=\"ok\" />")
49             .append("</response>")
50             .append("</authentication>");
51         return 0;
52     }
53
54
55     public String JavaDoc getUsername(HttpServletRequest req, HttpServletResponse res,
56                               HashMap param)
57     {
58         String JavaDoc usr = (String JavaDoc) param.get("usr");
59         return (usr!=null ? usr : mDefaultUserName);
60     }
61 }
62
Popular Tags