added admin functions for viewing audit records; gave users the ability
to set their default language and time zone preferences; added footer text and account signup accept/decline rules; added additional implementation of dictyionary code for future; minor cleanup of rendering config; and so forth
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Community System.
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
@@ -20,10 +20,125 @@ package com.silverwrist.venice.security;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import com.silverwrist.venice.db.SQLUtil;
|
||||
import com.silverwrist.venice.core.AuditData;
|
||||
import com.silverwrist.venice.core.DataException;
|
||||
import com.silverwrist.venice.core.InternalStateError;
|
||||
|
||||
public class AuditRecord implements Audit
|
||||
public class AuditRecord implements AuditData
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Private implementation of ReadOnlyVector
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static class ReadOnlyVector extends AbstractList
|
||||
{
|
||||
private Vector my_vec; // local vector
|
||||
|
||||
ReadOnlyVector(Vector vec)
|
||||
{
|
||||
my_vec = vec;
|
||||
my_vec.trimToSize();
|
||||
|
||||
} // end constructor
|
||||
|
||||
protected void finalize() throws Throwable
|
||||
{
|
||||
my_vec = null;
|
||||
super.finalize();
|
||||
|
||||
} // end finalize
|
||||
|
||||
public Object get(int index)
|
||||
{
|
||||
return my_vec.elementAt(index);
|
||||
|
||||
} // end get
|
||||
|
||||
public int size()
|
||||
{
|
||||
return my_vec.size();
|
||||
|
||||
} // end size
|
||||
|
||||
} // end class ReadOnlyVector
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal class for caching description strings on load
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static class DescrStringCache
|
||||
{
|
||||
private Hashtable descr_cache = new Hashtable();
|
||||
private Hashtable uname_cache = new Hashtable();
|
||||
private Hashtable signame_cache = new Hashtable();
|
||||
private Statement stmt;
|
||||
|
||||
DescrStringCache(Connection conn) throws SQLException
|
||||
{
|
||||
stmt = conn.createStatement();
|
||||
|
||||
} // end constructor
|
||||
|
||||
String getDescription(int code) throws SQLException, DataException
|
||||
{
|
||||
Integer code_x = new Integer(code);
|
||||
String rc = (String)(descr_cache.get(code_x));
|
||||
if (rc==null)
|
||||
{ // OK, get it from the database...
|
||||
ResultSet rs = stmt.executeQuery("SELECT descr FROM refaudit WHERE type = " + code + ";");
|
||||
if (!(rs.next()))
|
||||
throw new DataException("description string not found for code " + code);
|
||||
rc = rs.getString(1);
|
||||
descr_cache.put(code_x,rc);
|
||||
|
||||
} // end if
|
||||
|
||||
return rc;
|
||||
|
||||
} // end getDescription
|
||||
|
||||
String getUserName(int uid) throws SQLException, DataException
|
||||
{
|
||||
Integer uid_x = new Integer(uid);
|
||||
String rc = (String)(uname_cache.get(uid_x));
|
||||
if (rc==null)
|
||||
{ // OK, get it from the database
|
||||
ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + uid + ";");
|
||||
if (!(rs.next()))
|
||||
throw new DataException("user name not found for UID " + uid);
|
||||
rc = rs.getString(1);
|
||||
uname_cache.put(uid_x,rc);
|
||||
|
||||
} // end if
|
||||
|
||||
return rc;
|
||||
|
||||
} // end getUserName
|
||||
|
||||
String getSIGName(int sigid) throws SQLException, DataException
|
||||
{
|
||||
if (sigid<=0)
|
||||
return ""; // no SIG
|
||||
Integer sigid_x = new Integer(sigid);
|
||||
String rc = (String)(signame_cache.get(sigid_x));
|
||||
if (rc==null)
|
||||
{ // OK, get it from the database
|
||||
ResultSet rs = stmt.executeQuery("SELECT signame FROM sigs WHERE sigid = " + sigid + ";");
|
||||
if (!(rs.next()))
|
||||
throw new DataException("SIG name not found for SIGID " + sigid);
|
||||
rc = rs.getString(1);
|
||||
signame_cache.put(sigid_x,rc);
|
||||
|
||||
} // end if
|
||||
|
||||
return rc;
|
||||
|
||||
} // end getSIGName
|
||||
|
||||
} // end class DescrStringCache
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
@@ -37,6 +152,8 @@ public class AuditRecord implements Audit
|
||||
private String ip; // the IP address of the user
|
||||
private String[] data; // the data values associated with the record
|
||||
private String descr = null; // audit record description
|
||||
private String uname = null; // user name of user
|
||||
private String signame = null; // name of SIG
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructors
|
||||
@@ -124,6 +241,25 @@ public class AuditRecord implements Audit
|
||||
|
||||
} // end constructor
|
||||
|
||||
protected AuditRecord(ResultSet rs, DescrStringCache cache) throws SQLException, DataException
|
||||
{
|
||||
record = rs.getLong("record");
|
||||
when = SQLUtil.getFullDateTime(rs,"on_date");
|
||||
type = rs.getInt("event");
|
||||
uid = rs.getInt("uid");
|
||||
sigid = rs.getInt("sigid");
|
||||
ip = rs.getString("ip");
|
||||
data = new String[DATA_COUNT];
|
||||
data[0] = rs.getString("data1");
|
||||
data[1] = rs.getString("data2");
|
||||
data[2] = rs.getString("data3");
|
||||
data[3] = rs.getString("data4");
|
||||
descr = cache.getDescription(type);
|
||||
uname = cache.getUserName(uid);
|
||||
signame = cache.getSIGName(sigid);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal functions
|
||||
*--------------------------------------------------------------------------------
|
||||
@@ -141,7 +277,7 @@ public class AuditRecord implements Audit
|
||||
|
||||
private void setData(String data1, String data2, String data3, String data4)
|
||||
{
|
||||
data = new String[4];
|
||||
data = new String[DATA_COUNT];
|
||||
data[0] = data1;
|
||||
data[1] = data2;
|
||||
data[2] = data3;
|
||||
@@ -150,7 +286,7 @@ public class AuditRecord implements Audit
|
||||
} // end setData
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
* Implementations from interface AuditData
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -202,6 +338,23 @@ public class AuditRecord implements Audit
|
||||
|
||||
} // end getDescription
|
||||
|
||||
public String getUserName()
|
||||
{
|
||||
return uname;
|
||||
|
||||
} // end getUserName
|
||||
|
||||
public String getSIGName()
|
||||
{
|
||||
return signame;
|
||||
|
||||
} // end getSIGName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void store(Connection conn) throws SQLException
|
||||
{
|
||||
if (record!=0)
|
||||
@@ -238,4 +391,47 @@ public class AuditRecord implements Audit
|
||||
|
||||
} // end store
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static List getAuditRecords(Connection conn, int sigid, int offset, int count)
|
||||
throws SQLException, DataException
|
||||
{
|
||||
Vector rc = new Vector();
|
||||
DescrStringCache cache = new DescrStringCache(conn);
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
StringBuffer sql = new StringBuffer("SELECT * FROM audit");
|
||||
if (sigid>0)
|
||||
sql.append(" WHERE sigid = ").append(sigid);
|
||||
sql.append(" ORDER BY on_date DESC LIMIT ").append(offset).append(", ").append(count).append(';');
|
||||
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||
|
||||
while (rs.next())
|
||||
{ // load the results
|
||||
AuditData dta = new AuditRecord(rs,cache);
|
||||
rc.add(dta);
|
||||
|
||||
} // end while
|
||||
|
||||
return new ReadOnlyVector(rc);
|
||||
|
||||
} // end getAuditRecords
|
||||
|
||||
public static int getAuditRecordCount(Connection conn, int sigid) throws SQLException
|
||||
{
|
||||
Statement stmt = conn.createStatement();
|
||||
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM audit");
|
||||
if (sigid>0)
|
||||
sql.append(" WHERE sigid = ").append(sigid);
|
||||
sql.append(';');
|
||||
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||
if (!(rs.next()))
|
||||
throw new InternalStateError("query failure on getAuditRecordCount");
|
||||
return rs.getInt(1);
|
||||
|
||||
} // end getAuditRecordCount
|
||||
|
||||
} // end class AuditRecord
|
||||
|
||||
Reference in New Issue
Block a user