01: /* *****************************************************************************
02: * RoleAuthentication.java
03: * ****************************************************************************/
04:
05: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
06: * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
07: * Use is subject to license terms. *
08: * J_LZ_COPYRIGHT_END *********************************************************/
09:
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: * Role implementation of Authentication.
29: *
30: * This class implements the Authentication interface
31: * methods. Every public member is an implementation of
32: * the Authentication interface.
33: **/
34: public class RoleAuthentication implements Authentication {
35: /** RoleAuthentication logger */
36: protected static Logger mLogger = Logger
37: .getLogger(RoleAuthentication.class);
38:
39: public void init(Properties prop) {
40: }
41:
42: public int login(HttpServletRequest req, HttpServletResponse res,
43: HashMap param, StringBuffer xmlResponse) {
44:
45: mLogger.debug("login(req,res,param,xmlResponse)");
46: String role = req.getParameter("role");
47: return req.isUserInRole(role) ? 0 : 1;
48: }
49:
50: public int logout(HttpServletRequest req, HttpServletResponse res,
51: HashMap param, StringBuffer xmlResponse) {
52:
53: mLogger.debug("logout(req,res,param,xmlResponse)");
54: // get the current session, if it doesn't exist, we can't logout
55: HttpSession sess = req.getSession(false);
56: if (sess == null) {
57: return 1;
58: } else {
59: req.getSession().invalidate();
60: return 0;
61: }
62: }
63:
64: public String getUsername(HttpServletRequest req,
65: HttpServletResponse res, HashMap param) {
66: mLogger.debug("getUsername(req,res,param)");
67: return req.getRemoteUser();
68: }
69:
70: }
|