00001 package net.threebit.utils.sosc;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00063
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");
00070
00071
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 }