KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* *****************************************************************************
2  * RoleAuthentication.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 org.openlaszlo.data.*;
13 import org.openlaszlo.server.*;
14 import org.openlaszlo.servlets.*;
15 import org.openlaszlo.utils.*;
16 import java.io.*;
17 import java.net.*;
18 import java.security.*;
19 import java.util.*;
20 import javax.servlet.http.*;
21 import org.apache.commons.httpclient.*;
22 import org.apache.commons.httpclient.methods.*;
23 import org.apache.log4j.*;
24 import org.jdom.*;
25 import org.jdom.input.*;
26
27
28 /**
29  * Role implementation of Authentication.
30  *
31  * This class implements the Authentication interface
32  * methods. Every public member is an implementation of
33  * the Authentication interface.
34  **/

35 public class RoleAuthentication implements Authentication
36 {
37     /** RoleAuthentication logger */
38     protected static Logger mLogger = Logger.getLogger(RoleAuthentication.class);
39
40     public void init(Properties prop)
41     {
42     }
43
44
45     public int login(HttpServletRequest req, HttpServletResponse res,
46                      HashMap param, StringBuffer JavaDoc xmlResponse)
47     {
48
49         mLogger.debug("login(req,res,param,xmlResponse)");
50         String JavaDoc role = req.getParameter("role");
51         return req.isUserInRole(role) ? 0 : 1;
52     }
53
54     public int logout(HttpServletRequest req, HttpServletResponse res,
55                       HashMap param, StringBuffer JavaDoc xmlResponse)
56     {
57
58         mLogger.debug("logout(req,res,param,xmlResponse)");
59         // get the current session, if it doesn't exist, we can't logout
60
HttpSession sess = req.getSession(false);
61         if (sess == null) {
62             return 1;
63         } else {
64             req.getSession().invalidate();
65             return 0;
66         }
67     }
68
69
70     public String JavaDoc getUsername(HttpServletRequest req, HttpServletResponse res,
71                               HashMap param)
72     {
73         mLogger.debug("getUsername(req,res,param)");
74             return req.getRemoteUser();
75     }
76
77 }
78
Popular Tags