[cvs]
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj
RowSecuredDBObject.java
Larry Hamel
lhamel at jcorp2.servlets.net
Sun May 2 16:03:27 PDT 2004
Update of /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj
In directory jcorp2.servlets.net:/tmp/cvs-serv24480/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj
Modified Files:
RowSecuredDBObject.java
Log Message:
cosmetic reformat, rename private datamember
Index: RowSecuredDBObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/RowSecuredDBObject.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** RowSecuredDBObject.java 10 Apr 2004 01:31:45 -0000 1.22
--- RowSecuredDBObject.java 2 May 2004 23:03:25 -0000 1.23
***************
*** 100,104 ****
* In most cases, the primary key is an integer or some other short field, so
* this limitation is not a problem.
! *
* LIMITATION: all permissions are stored in a two tables: RowPermissions & RowGroupPerms.
* If your application
--- 100,104 ----
* In most cases, the primary key is an integer or some other short field, so
* this limitation is not a problem.
! * <p/>
* LIMITATION: all permissions are stored in a two tables: RowPermissions & RowGroupPerms.
* If your application
***************
*** 110,120 ****
*
* @author larry hamel, CodeGuild, Inc.
- *
* @see com.jcorporate.expresso.services.dbobj.RowPermissions
* @see com.jcorporate.expresso.services.dbobj.RowGroupPerms
*/
! public class RowSecuredDBObject extends SecuredDBObject
! {
! private static Logger mlog = null;
/**
--- 110,118 ----
*
* @author larry hamel, CodeGuild, Inc.
* @see com.jcorporate.expresso.services.dbobj.RowPermissions
* @see com.jcorporate.expresso.services.dbobj.RowGroupPerms
*/
! public class RowSecuredDBObject extends SecuredDBObject {
! private static Logger slog = null;
/**
***************
*** 125,130 ****
* @throws DBException upon database communication error
*/
! public RowSecuredDBObject() throws DBException
! {
// by default, the requesting user ID is set to system,
//which gives a superuser status to all requests
--- 123,127 ----
* @throws DBException upon database communication error
*/
! public RowSecuredDBObject() throws DBException {
// by default, the requesting user ID is set to system,
//which gives a superuser status to all requests
***************
*** 140,154 ****
*
* @param theConnection A DBConnection that this object should use to
! * connect to the database
! * @param theUser User name attempting to use this object. If this is
! * "SYSTEM", then full permissions are granted. Note that you
! * cannot log in as "SYSTEM", it can only be used from within a
! * method.
! *
* @throws DBException If the object cannot be created
*/
public RowSecuredDBObject(DBConnection theConnection, int theUser)
! throws DBException
! {
super(theConnection, theUser);
--- 137,149 ----
*
* @param theConnection A DBConnection that this object should use to
! * connect to the database
! * @param theUser User name attempting to use this object. If this is
! * "SYSTEM", then full permissions are granted. Note that you
! * cannot log in as "SYSTEM", it can only be used from within a
! * method.
* @throws DBException If the object cannot be created
*/
public RowSecuredDBObject(DBConnection theConnection, int theUser)
! throws DBException {
super(theConnection, theUser);
***************
*** 161,169 ****
*
* @param theUser requesting user
- *
* @throws DBException upon database communication error
*/
! public RowSecuredDBObject(int theUser) throws DBException
! {
super(theUser);
--- 156,162 ----
*
* @param theUser requesting user
* @throws DBException upon database communication error
*/
! public RowSecuredDBObject(int theUser) throws DBException {
super(theUser);
***************
*** 176,184 ****
*
* @param request context for using this object
- *
* @throws DBException upon database communication error
*/
! public RowSecuredDBObject(RequestContext request) throws DBException
! {
super(request);
--- 169,175 ----
*
* @param request context for using this object
* @throws DBException upon database communication error
*/
! public RowSecuredDBObject(RequestContext request) throws DBException {
super(request);
***************
*** 190,198 ****
* @return list of a group names (strings) which have permission to change
* permission
- *
* @throws DBException upon database communication error
*/
! public List getAdministrateGroups() throws DBException
! {
List allGroups = this.getGroups();
--- 181,187 ----
* @return list of a group names (strings) which have permission to change
* permission
* @throws DBException upon database communication error
*/
! public List getAdministrateGroups() throws DBException {
List allGroups = this.getGroups();
***************
*** 222,231 ****
* @throws DBException upon database communication error
*/
! public List getGroups() throws DBException
! {
String primeKey = getKey();
RowGroupPerms rowGroupPerms = new RowGroupPerms(getJDBCMetaData()
! .getTargetTable(),
primeKey);
rowGroupPerms.setDataContext(getDataContext());
--- 211,219 ----
* @throws DBException upon database communication error
*/
! public List getGroups() throws DBException {
String primeKey = getKey();
RowGroupPerms rowGroupPerms = new RowGroupPerms(getJDBCMetaData()
! .getTargetTable(),
primeKey);
rowGroupPerms.setDataContext(getDataContext());
***************
*** 239,247 ****
* @return Category for logging
*/
! public Category getLogger()
! {
! if ( mlog == null ) mlog = Logger.getLogger(getClass().getName());
! return mlog;
}
--- 227,234 ----
* @return Category for logging
*/
! public Category getLogger() {
! if (slog == null) slog = Logger.getLogger(getClass().getName());
! return slog;
}
***************
*** 252,267 ****
*
* @param group name of group
! * @param perm value of permissions
* @throws DBException upon database communication error
- *
*/
public void setPermissions(String group, int perm)
! throws DBException
! {
if (!canRequesterAdministrate()) {
throw new SecurityException("cannot set permissions by user_id: " +
! getRequestingUid() + " for db object in table: " +
! getJDBCMetaData().getTargetTable() + " with primary key: " +
! getKey());
}
--- 239,252 ----
*
* @param group name of group
! * @param perm value of permissions
* @throws DBException upon database communication error
*/
public void setPermissions(String group, int perm)
! throws DBException {
if (!canRequesterAdministrate()) {
throw new SecurityException("cannot set permissions by user_id: " +
! getRequestingUid() + " for db object in table: " +
! getJDBCMetaData().getTargetTable() + " with primary key: " +
! getKey());
}
***************
*** 275,283 ****
*
* @param perm permissions to set
- *
* @throws DBException upon database communication error
*/
! public void setPermissions(int perm) throws DBException
! {
setPermissions(getRequestingUid(), null, perm);
}
--- 260,266 ----
*
* @param perm permissions to set
* @throws DBException upon database communication error
*/
! public void setPermissions(int perm) throws DBException {
setPermissions(getRequestingUid(), null, perm);
}
***************
*** 292,305 ****
* @throws DBException if keys are not set on this object
*/
! public RowPermissions getPermissions() throws DBException
! {
if (!this.haveAllKeys()) {
! throw new DBException(
! "cannot get/set permissions on item before item's primary key(s) are available.");
}
String primeKey = getKey();
RowPermissions rowPermissions = new RowPermissions(getJDBCMetaData()
! .getTargetTable(),
primeKey);
rowPermissions.setDataContext(getDataContext());
--- 275,286 ----
* @throws DBException if keys are not set on this object
*/
! public RowPermissions getPermissions() throws DBException {
if (!this.haveAllKeys()) {
! throw new DBException("cannot get/set permissions on item before item's primary key(s) are available.");
}
String primeKey = getKey();
RowPermissions rowPermissions = new RowPermissions(getJDBCMetaData()
! .getTargetTable(),
primeKey);
rowPermissions.setDataContext(getDataContext());
***************
*** 318,325 ****
* @return list of group names (strings) which have read permission
* @throws DBException upon database communication error
- *
*/
! public List getReadGroups() throws DBException
! {
List allGroups = this.getGroups();
--- 299,304 ----
* @return list of group names (strings) which have read permission
* @throws DBException upon database communication error
*/
! public List getReadGroups() throws DBException {
List allGroups = this.getGroups();
***************
*** 343,354 ****
/**
* determine if this function is allowed for this requesting user
* @param requestedFunction code for function -- Add, Update, Delete, Search (read)
* @return true if this function is allowed for this requesting user
- *
* @throws SecurityException (unchecked) if not allowed
*/
public boolean isRowAllowed(String requestedFunction)
! throws DBException
! {
boolean result = false;
--- 322,332 ----
/**
* determine if this function is allowed for this requesting user
+ *
* @param requestedFunction code for function -- Add, Update, Delete, Search (read)
* @return true if this function is allowed for this requesting user
* @throws SecurityException (unchecked) if not allowed
*/
public boolean isRowAllowed(String requestedFunction)
! throws DBException {
boolean result = false;
***************
*** 366,375 ****
if (!result) {
throw new SecurityException("User '" +
! User.getLoginFromId(getRequestingUid(), getDataContext()) +
! "' does not have permission to perform function '" +
! requestedFunction + "' on database object in table '" +
! getJDBCMetaData().getTargetTable() + "', row: " + getKey() +
! " in db/context '" + getDataContext() +
! "'. Please contact your system administrator if you feel this is incorrect.");
}
--- 344,353 ----
if (!result) {
throw new SecurityException("User '" +
! User.getLoginFromId(getRequestingUid(), getDataContext()) +
! "' does not have permission to perform function '" +
! requestedFunction + "' on database object in table '" +
! getJDBCMetaData().getTargetTable() + "', row: " + getKey() +
! " in db/context '" + getDataContext() +
! "'. Please contact your system administrator if you feel this is incorrect.");
}
***************
*** 383,395 ****
*
* @param requestedFunction code for function -- Add, Update, Delete, Search (read)
! * @param items is a collection of RowSecuredDBObjects
! *
* @return true if AT LEAST ONE item in collectino is allowed; also manipulates input list, removing unallowed items
- *
* @throws DBException upon database communication error
*/
public boolean isRowAllowed(String requestedFunction, Collection items)
! throws DBException
! {
if (items.size() == 0) {
return false;
--- 361,370 ----
*
* @param requestedFunction code for function -- Add, Update, Delete, Search (read)
! * @param items is a collection of RowSecuredDBObjects
* @return true if AT LEAST ONE item in collectino is allowed; also manipulates input list, removing unallowed items
* @throws DBException upon database communication error
*/
public boolean isRowAllowed(String requestedFunction, Collection items)
! throws DBException {
if (items.size() == 0) {
return false;
***************
*** 412,416 ****
} catch (SecurityException e) {
if (getLogger().isDebugEnabled()) {
! getLogger().debug("Security exception checking for isRowAllowed: denying a row with key: " + getKey() + " , removing it from list of approved.");
}
// do nothing; this Row will be removed
--- 387,392 ----
} catch (SecurityException e) {
if (getLogger().isDebugEnabled()) {
! getLogger().debug(
! "Security exception checking for isRowAllowed: denying a row with key: " + getKey() + " , removing it from list of approved.");
}
// do nothing; this Row will be removed
***************
*** 436,441 ****
* @throws DBException upon database communication error
*/
! public List getWriteGroups() throws DBException
! {
List allGroups = this.getGroups();
--- 412,416 ----
* @throws DBException upon database communication error
*/
! public List getWriteGroups() throws DBException {
List allGroups = this.getGroups();
***************
*** 461,474 ****
* by superclass) but rather to add default permissions
*
* @see #add(String group, int permissions ) for a way to add() with more
* specific permissions
- * @throws DBException upon database communication error
*/
! public void add() throws DBException
! {
super.add();
setDefaultPermissions();
}
! /* add() */
/*
--- 436,448 ----
* by superclass) but rather to add default permissions
*
+ * @throws DBException upon database communication error
* @see #add(String group, int permissions ) for a way to add() with more
* specific permissions
*/
! public void add() throws DBException {
super.add();
setDefaultPermissions();
}
! /* add() */
/*
***************
*** 481,490 ****
*/
public synchronized void add(String group, int permissions)
! throws DBException
! {
super.add();
setPermissions(getRequestingUid(), group, permissions);
}
! /* add() */
/**
--- 455,463 ----
*/
public synchronized void add(String group, int permissions)
! throws DBException {
super.add();
setPermissions(getRequestingUid(), group, permissions);
}
! /* add() */
/**
***************
*** 493,502 ****
*
* @param group to be added
! * @param perm to be added
! *
* @throws DBException upon database communication error
*/
! public void addGroupPerm(String group, int perm) throws DBException
! {
if (group == null) {
throw new DBException("null group name");
--- 466,473 ----
*
* @param group to be added
! * @param perm to be added
* @throws DBException upon database communication error
*/
! public void addGroupPerm(String group, int perm) throws DBException {
if (group == null) {
throw new DBException("null group name");
***************
*** 513,517 ****
RowGroupPerms rowGroupPerms = new RowGroupPerms(getJDBCMetaData()
! .getTargetTable(),
getKey());
rowGroupPerms.setDataContext(getDataContext());
--- 484,488 ----
RowGroupPerms rowGroupPerms = new RowGroupPerms(getJDBCMetaData()
! .getTargetTable(),
getKey());
rowGroupPerms.setDataContext(getDataContext());
***************
*** 535,543 ****
* @return true if requesting id has permission to administrate (change
* permissions)
- *
* @throws DBException upon database communication error
*/
! public boolean canRequesterAdministrate() throws DBException
! {
boolean result = false;
--- 506,512 ----
* @return true if requesting id has permission to administrate (change
* permissions)
* @throws DBException upon database communication error
*/
! public boolean canRequesterAdministrate() throws DBException {
boolean result = false;
***************
*** 566,571 ****
// public readability?
result = rowPermissions.canOthersAdministrate() ||
! ((userId == rowPermissions.owner()) &&
! rowPermissions.canOwnerAdministrate());
if (!result) {
--- 535,540 ----
// public readability?
result = rowPermissions.canOthersAdministrate() ||
! ((userId == rowPermissions.owner()) &&
! rowPermissions.canOwnerAdministrate());
if (!result) {
***************
*** 585,593 ****
*
* @return true if getRequestingUid has rights to read this row
- *
* @throws DBException upon database communication error
*/
! public boolean canRequesterRead() throws DBException
! {
boolean result = false;
--- 554,560 ----
*
* @return true if getRequestingUid has rights to read this row
* @throws DBException upon database communication error
*/
! public boolean canRequesterRead() throws DBException {
boolean result = false;
***************
*** 616,621 ****
// public readability?
result = rowPermissions.canOthersRead() ||
! ((userId == rowPermissions.owner()) &&
! rowPermissions.canOwnerRead());
if (!result) {
--- 583,588 ----
// public readability?
result = rowPermissions.canOthersRead() ||
! ((userId == rowPermissions.owner()) &&
! rowPermissions.canOwnerRead());
if (!result) {
***************
*** 636,646 ****
/**
- *
* @return true if requesting id has permission to write
- *
* @throws DBException upon database communication error
*/
! public boolean canRequesterWrite() throws DBException
! {
boolean result = false;
--- 603,610 ----
/**
* @return true if requesting id has permission to write
* @throws DBException upon database communication error
*/
! public boolean canRequesterWrite() throws DBException {
boolean result = false;
***************
*** 669,674 ****
// public readability?
result = rowPermissions.canOthersWrite() ||
! ((userId == rowPermissions.owner()) &&
! rowPermissions.canOwnerWrite());
if (!result) {
--- 633,638 ----
// public readability?
result = rowPermissions.canOthersWrite() ||
! ((userId == rowPermissions.owner()) &&
! rowPermissions.canOwnerWrite());
if (!result) {
***************
*** 685,696 ****
/**
- *
* @return the default group for this requesting user; null if user has no
* groups
- *
* @throws DBException upon database communication error
*/
! public String defaultGroup() throws DBException
! {
User user = new User();
user.setUid(getRequestingUid());
--- 649,657 ----
/**
* @return the default group for this requesting user; null if user has no
* groups
* @throws DBException upon database communication error
*/
! public String defaultGroup() throws DBException {
User user = new User();
user.setUid(getRequestingUid());
***************
*** 706,714 ****
/**
* override this to change default
* @return the default permissions
* @todo move this into ConfigManager
*/
! public int defaultPermissions()
! {
return RowPermissions.DEFAULT_PERMISSIONS;
}
--- 667,675 ----
/**
* override this to change default
+ *
* @return the default permissions
* @todo move this into ConfigManager
*/
! public int defaultPermissions() {
return RowPermissions.DEFAULT_PERMISSIONS;
}
***************
*** 721,726 ****
*/
public synchronized void delete(boolean deleteDetails)
! throws DBException
! {
isRowAllowed(DELETE);
super.delete(deleteDetails);
--- 682,686 ----
*/
public synchronized void delete(boolean deleteDetails)
! throws DBException {
isRowAllowed(DELETE);
super.delete(deleteDetails);
***************
*** 740,752 ****
}
}
! /* delete() */
/**
* check that all objects can be deleted; must retrieve all objects to
* check individually
* @throws DBException upon database communication error
*/
! public synchronized void deleteAll() throws DBException
! {
List list = searchAndRetrieveList();
--- 700,712 ----
}
}
! /* delete() */
/**
* check that all objects can be deleted; must retrieve all objects to
* check individually
+ *
* @throws DBException upon database communication error
*/
! public synchronized void deleteAll() throws DBException {
List list = searchAndRetrieveList();
***************
*** 758,762 ****
super.deleteAll();
}
! /* deleteAll() */
/**
--- 718,722 ----
super.deleteAll();
}
! /* deleteAll() */
/**
***************
*** 764,772 ****
*
* @return true if found AND allowed
- *
* @throws DBException if user does not have rights to read found item
*/
! public boolean find() throws DBException
! {
boolean result = super.find();
--- 724,730 ----
*
* @return true if found AND allowed
* @throws DBException if user does not have rights to read found item
*/
! public boolean find() throws DBException {
boolean result = super.find();
***************
*** 784,789 ****
* @throws DBException upon database communication error
*/
! public int ownerID() throws DBException
! {
// here is the inserted part of override
RowPermissions perms = this.getPermissions();
--- 742,746 ----
* @throws DBException upon database communication error
*/
! public int ownerID() throws DBException {
// here is the inserted part of override
RowPermissions perms = this.getPermissions();
***************
*** 798,803 ****
* @throws DBException upon database communication error
*/
! public void removeGroup(String group) throws DBException
! {
if (group == null) {
throw new DBException("null group name");
--- 755,759 ----
* @throws DBException upon database communication error
*/
! public void removeGroup(String group) throws DBException {
if (group == null) {
throw new DBException("null group name");
***************
*** 805,809 ****
RowGroupPerms rowGroupPerms = new RowGroupPerms(getJDBCMetaData()
! .getTargetTable(),
getKey());
rowGroupPerms.setDataContext(getDataContext());
--- 761,765 ----
RowGroupPerms rowGroupPerms = new RowGroupPerms(getJDBCMetaData()
! .getTargetTable(),
getKey());
rowGroupPerms.setDataContext(getDataContext());
***************
*** 817,824 ****
/**
* retrieve object on criteria provided in fields
* @throws DBException upon database communication error
*/
! public void retrieve() throws DBException
! {
super.retrieve();
this.isRowAllowed(SEARCH); // test second in case we have a new object which will not have any permissions yet, and therefore always be disallowed
--- 773,780 ----
/**
* retrieve object on criteria provided in fields
+ *
* @throws DBException upon database communication error
*/
! public void retrieve() throws DBException {
super.retrieve();
this.isRowAllowed(SEARCH); // test second in case we have a new object which will not have any permissions yet, and therefore always be disallowed
***************
*** 835,840 ****
*/
public synchronized ArrayList searchAndRetrieveList()
! throws DBException
! {
//return super.searchAndRetrieveList();
ArrayList result = super.searchAndRetrieveList();
--- 791,795 ----
*/
public synchronized ArrayList searchAndRetrieveList()
! throws DBException {
//return super.searchAndRetrieveList();
ArrayList result = super.searchAndRetrieveList();
***************
*** 851,861 ****
*
* @param sortKeys sort field(s)
- *
* @return list of RowSecuredDBObject's which are both found AND allowed for this requester
* @throws DBException upon database communication error
*/
public synchronized ArrayList searchAndRetrieveList(String sortKeys)
! throws DBException
! {
ArrayList result = super.searchAndRetrieveList(sortKeys);
this.isRowAllowed(SEARCH, result);
--- 806,814 ----
*
* @param sortKeys sort field(s)
* @return list of RowSecuredDBObject's which are both found AND allowed for this requester
* @throws DBException upon database communication error
*/
public synchronized ArrayList searchAndRetrieveList(String sortKeys)
! throws DBException {
ArrayList result = super.searchAndRetrieveList(sortKeys);
this.isRowAllowed(SEARCH, result);
***************
*** 863,878 ****
return result;
}
! /* searchAndRetrieve(String) */
/**
* before allowing update, check permission
* @throws DBException upon database communication error
*/
! public void update() throws DBException
! {
isRowAllowed(UPDATE);
super.update();
}
! /* update() */
/**
--- 816,831 ----
return result;
}
! /* searchAndRetrieve(String) */
/**
* before allowing update, check permission
+ *
* @throws DBException upon database communication error
*/
! public void update() throws DBException {
isRowAllowed(UPDATE);
super.update();
}
! /* update() */
/**
***************
*** 884,889 ****
*/
protected void checkDeleteDetailPerm(DBObject obj)
! throws DBException
! {
// here is the inserted part of override
if (obj instanceof RowSecuredDBObject) {
--- 837,841 ----
*/
protected void checkDeleteDetailPerm(DBObject obj)
! throws DBException {
// here is the inserted part of override
if (obj instanceof RowSecuredDBObject) {
***************
*** 897,905 ****
/**
* // warn if key of this row may be too long
* @throws DBException upon error
* @todo test this impl and uncomment
*/
! protected void checkKeyLength() throws DBException
! {
// int totalLength = 0;
// Iterator iter = getDef().getAllKeysIterator();
--- 849,857 ----
/**
* // warn if key of this row may be too long
+ *
* @throws DBException upon error
* @todo test this impl and uncomment
*/
! protected void checkKeyLength() throws DBException {
// int totalLength = 0;
// Iterator iter = getDef().getAllKeysIterator();
***************
*** 925,930 ****
* @throws DBException upon database communication error
*/
! private void setDefaultPermissions() throws DBException
! {
RowPermissions rowPermissions = getPermissions();
rowPermissions.owner(getRequestingUid());
--- 877,881 ----
* @throws DBException upon database communication error
*/
! private void setDefaultPermissions() throws DBException {
RowPermissions rowPermissions = getPermissions();
rowPermissions.owner(getRequestingUid());
***************
*** 941,954 ****
/**
- *
* set permissions as indicated
* @param owner new owner
* @param group new group for group perms
! * @param perm permissions to set
* @throws DBException upon database communication error
*/
private void setPermissions(int owner, String group, int perm)
! throws DBException
! {
RowPermissions rowPermissions = getPermissions();
rowPermissions.owner(owner);
--- 892,904 ----
/**
* set permissions as indicated
+ *
* @param owner new owner
* @param group new group for group perms
! * @param perm permissions to set
* @throws DBException upon database communication error
*/
private void setPermissions(int owner, String group, int perm)
! throws DBException {
RowPermissions rowPermissions = getPermissions();
rowPermissions.owner(owner);
More information about the cvs
mailing list