Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Commworx.java

Go to the documentation of this file.
00001 package net.threebit.utils.sosc;
00002 
00003 /*
00004         Copyright 2003 Shawn Deleurme
00005         Copyright 2003 Kevin O'Donnell
00006 
00007         This program is free software; you can redistribute it and/or modify
00008         it under the terms of the GNU General Public License as published by
00009         the Free Software Foundation; either version 2 of the License, or
00010         (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016 
00017         You should have received a copy of the GNU General Public License
00018         along with this program; if not, write to the Free Software
00019         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 import javax.xml.transform.*;
00023 import javax.xml.transform.stream.*;
00024 import java.sql.*;
00025 import java.io.*;
00026 import java.util.*;
00027 import javax.servlet.http.*;
00028 import javax.servlet.jsp.*;
00029 
00030 public class Commworx {
00031 
00032         final HttpServletRequest request;
00033         final HttpServletResponse response;
00034         final JspWriter out;
00035 
00036         Commworx (HttpServletRequest request, HttpServletResponse response, JspWriter out) {
00037                 this.request = request;
00038                 this.response = response;
00039                 this.out = out;
00040         }
00041 
00050         public boolean simpleAuth (String[] users) throws Exception {
00051 
00052                 String addr = request.getRemoteAddr();
00053 
00054                 // Go through the simple and FATAL conditions first.
00055                 if (users == null) {
00056                         throw new Exception("Auth denied; specified userlist was null; default no acess");
00057                 }
00058                 if (! addr.startsWith("192.168.20")) {
00059                         throw new Exception("Can't authenticate against Commworx session table if you are not on the local network; auth denied");
00060                 }
00061 
00062                 // Find out what username is logged into Commworx from the IP address that this
00063                 // request is originating from.
00064                 DbTool db = null;
00065                 ResultSet r = db.query(" select top 1 * from waf_sys_session where SessionMachine = '" + addr + "' order by sessionstart desc ");
00066                 if (! r.first()) {
00067                         throw new Exception("No Commworx Session information for your address (" + addr + ")");
00068                 }
00069                 String userid = "" + r.getObject("userid"); // NULLS in the commworx database SUCK!
00070 
00071                 // Compare this against the list of users
00072                 boolean ok = false;
00073                 for (int x = 0; x < users.length; x++) {
00074                         if (users[x].equalsIgnoreCase(userid)) { ok = true; }
00075                 }
00076 
00077                 if (! ok) {
00078                         String userList = "";
00079                         for (int x = 0; x < users.length; x++) { userList = userList + " " + users[x] + ";"; }
00080                         throw new Exception("Auth denied; you are not allowed to perform this action. (Talk to " + userList + ")");
00081                 }
00082 
00083                 return true;
00084         }
00085 
00086 
00087 }

Generated on Mon Jul 14 17:19:19 2003 for SOSC by doxygen1.2.15