|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.db.DbObject
org.tentackle.appworx.AppDbObject
org.tentackle.appworx.Security
public class Security
A security rule.
Any object, whether it is a database object (AppDbObject) or any
other class (for example a dialog) can be secured by rules.
Security rules grant or deny a permission to a grantee object or a grantee class.
Optionally, rules can be restricted to some context object or context class.
Grantees and contexts must be of type AppDbObject.
The permission is an integer associated to a permission type, which is
also an integer identifying the permission scheme. Permission types
can be application specific, for example "invoiceable".
Security rules also have a priority, can explain the denial to the user
by means of a message text and can easily be extended by the application.
Furthermore, rules may optionally be restricted to an application database context.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.tentackle.db.DbObject |
|---|
DbObject.CopyAllToDbLogger, DbObject.IdComparator<T extends DbObject>, DbObject.NameComparator<T extends DbObject>, DbObject.NameIdComparator<T extends DbObject> |
| Field Summary | |
|---|---|
static int |
EXEC
allow to execute |
static String |
FIELD_ALLOWED
database column name for allowed |
static String |
FIELD_CONTEXTCLASS
database column name for contextClass |
static String |
FIELD_CONTEXTID
database column name for contextId |
static String |
FIELD_EXTENDEDRULE
database column name for extendedRule |
static String |
FIELD_GRANTCLASS
database column name for grantClass |
static String |
FIELD_GRANTID
database column name for grantId |
static String |
FIELD_MESSAGE
database column name for message |
static String |
FIELD_OBJECTCLASS
database column name for objectClass |
static String |
FIELD_OBJECTID
database column name for objectId |
static String |
FIELD_PERMISSION
database column name for permission |
static String |
FIELD_PERMISSIONTYPE
database column name for permissionType |
static String |
FIELD_PRIORITY
database column name for priority |
static int |
NONE
no permission at all |
static int |
READ
allow for read |
static String |
TABLENAME
database tablename |
static int |
TYPE_DATA
permissiontype "data", i.e. |
static int |
TYPE_PROGRAM
java executable class, i.e. |
static int |
WRITE
allow for write, create, delete |
| Fields inherited from class org.tentackle.appworx.AppDbObject |
|---|
FIELD_EDITEDBY, FIELD_EDITEDEXPIRY, FIELD_EDITEDSINCE, FIELD_NORMTEXT, TX_DELETE_ALL_IN_CONTEXT, TX_SAVE_COPY_IN_CONTEXT, TX_TRANSFER_EDITEDBY, VERIFIED_DUPLICATE |
| Fields inherited from class org.tentackle.db.DbObject |
|---|
BEGIN, COMMIT, DELETE, DELETEALL, FIELD_ID, FIELD_SERIAL, FIELD_TABLESERIAL, idComparator, INSERT, lazyMethodInterval, nameComparator, nameIdComparator, TX_DELETE_LIST, TX_DELETE_MISSING_IN_LIST, TX_DELETE_OBJECT, TX_DUMMY_UPDATE, TX_INSERT_OBJECT, TX_INSERT_PLAIN, TX_SAVE, TX_SAVE_LIST, TX_UPDATE_OBJECT, TX_UPDATE_PLAIN, TX_UPDATE_SERIAL, TX_UPDATE_SERIAL_AND_TABLESERIAL, TX_UPDATE_TABLESERIAL, UPDATE |
| Constructor Summary | |
|---|---|
Security()
Creates a security rule (without db context). |
|
Security(ContextDb db)
Creates a security rule. |
|
| Method Summary | |
|---|---|
static List<Security> |
createSecurityForObjectInOtherDb(AppDbObject fromObject,
AppDbObject toObject)
Creates security rules for objects created by AppDbObject.createCopyInContextDb(org.tentackle.appworx.ContextDb).The method copies the rules from one object to another (logically the same) object in another context. |
int |
deleteByGrantee(long grantId)
Delete all rules for given grantee. Notice that among all objects of grantee-classes (usually one for the user and one for the roles) the IDs must be unique! |
int |
deleteByObject(AppDbObject object)
Deletes all rules for given AppDbObject. |
int |
deleteByObject(long objectId,
String objectClass)
Deletes all rules for given objectId and objectClass. |
int |
deleteObjectRulesByGrantClass(String grantClass)
Deletes all rules for given grantClass. This will NOT delete any class-based rules (with grantId = 0) ! |
int |
deleteObjectRulesByGrantClassAndContext(String grantClass,
long contextId,
String contextClass)
Deletes all rules for given grantClass and Context. |
int |
deleteObjectRulesByObjectClass(String objectClass)
Delete all object-related rules for given objectClass. This will NOT delete any class-based rules (with objectId = 0) ! |
int |
deleteObjectRulesByObjectClassAndContext(String objectClass,
long contextId,
String contextClass)
Delete all rules for given objectClass and Context. This will NOT delete any class-based rules (with objectId = 0) ! |
boolean |
evaluate(ContextDb contextDb,
int permission)
Evaluates a rule. |
boolean |
getAllowed()
Gets the db attribute allowed |
AppDbObjectClassVariables |
getAppDbObjectClassVariables()
Gets the application oriented class variables for this object. Class variables for classes derived from AppDbObject are kept in an instance of AppDbObjectClassVariables. |
String |
getContextClass()
Gets the db attribute contextClass |
long |
getContextId()
Gets the db attribute contextId |
AppDbObject |
getContextObject()
Gets the application context's object. The object will be loaded in its valid context. |
Binary |
getExtendedRule()
Gets the db attribute extendedRule |
boolean |
getFields(ResultSetWrapper rs)
Retrieves the values of all fields (all columns of the database table) in the given ResultSetWrapper and stores them in the object's attributes. |
FormTableEntry |
getFormTableEntry()
Gets the table entry for viewing lists of this object in a FormTable.The default implementation returns an AppDbObjectDefaultTableEntry. |
String |
getFormTableName()
Gets the tablename used in to initialize the table's gui (columns, sizes, etc...). |
String |
getGrantClass()
Gets the db attribute grantClass |
AppDbObject |
getGrantee()
Gets the grantee. |
long |
getGrantId()
Gets the db attribute grantId |
String |
getMessage()
Gets the db attribute message |
AppDbObject |
getObject()
Gets the object this rule applies to. The object is retrieved in its valid context. |
String |
getObjectClass()
Gets the db attribute objectClass |
long |
getObjectId()
Gets the db attribute objectId |
int |
getPermission()
Gets the db attribute permission |
int |
getPermissionType()
Gets the db attribute permissionType |
int |
getPriority()
Gets the db attribute priority |
boolean |
isCountingModification(int modType)
Changes in Security usually force caches, etc... |
boolean |
isTracked()
Overridden cause of "--tracked". |
String |
orderBy()
All selects are sorted by priority! |
static String |
permissionToString(int type,
int permission)
Converts a permission and its type to a string. |
int |
prepareInsertStatement()
Prepares the insert statement. |
boolean |
prepareSetFields()
Prepares the object's attributes before the object is saved to the database. |
int |
prepareUpdateStatement()
Prepare the update statement. |
Security |
select(long id)
Selects a rule by ID. |
List<Security> |
selectByGrantId(long grantId)
Selects all rules for a given grantId. Notice that among all objects of grantee-classes (usually one for the user and one for the roles) the IDs must be unique! |
TrackedArrayList<Security> |
selectByObject(AppDbObject object)
Select all rules for given object. |
TrackedArrayList<Security> |
selectByObject(long objectId,
String objectClass)
Select all rules for given objectId and objectClass. |
void |
setAllowed(boolean allowed)
Sets the db attribute allowed |
void |
setContextClass(String contextClass)
Sets the db attribute contextClass |
void |
setContextId(long contextId)
Sets the db attribute contextId |
void |
setContextObject(AppDbObject contextObject)
Sets the application context's object. |
void |
setExtendedRule(Binary extendedRule)
Sets the db attribute extendedRule |
int |
setFields(PreparedStatementWrapper st)
Sets the values of all fields (all columns of the database table) in the given PreparedStatementWrapper from the object's attributes. |
void |
setGrantClass(String grantClass)
Sets the db attribute grantClass |
void |
setGrantee(AppDbObject grantee)
Sets the grantee. |
void |
setGrantId(long grantId)
Sets the db attribute grantId |
void |
setMessage(String message)
Sets the db attribute message |
void |
setObject(AppDbObject object)
Sets the object this rule applies to. Setting the null object also clears the objectClass making the rule invalid. |
void |
setObjectClass(Class clazz)
Sets the class to be secured. If the class is an AppDbObject only the basename
will be stored. |
void |
setObjectClass(String objectClass)
Sets the db attribute objectClass |
void |
setObjectId(long objectId)
Sets the db attribute objectId |
void |
setPermission(int permission)
Sets the db attribute permission |
void |
setPermissionType(int permissionType)
Sets the db attribute permissionType |
void |
setPriority(int priority)
Sets the db attribute priority |
String |
toString()
for debugging only |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int TYPE_DATA
public static final int TYPE_PROGRAM
public static final int NONE
public static final int READ
public static final int WRITE
public static final int EXEC
public static final String TABLENAME
public static final String FIELD_OBJECTCLASS
public static final String FIELD_OBJECTID
public static final String FIELD_CONTEXTID
public static final String FIELD_CONTEXTCLASS
public static final String FIELD_GRANTID
public static final String FIELD_GRANTCLASS
public static final String FIELD_PRIORITY
public static final String FIELD_PERMISSIONTYPE
public static final String FIELD_PERMISSION
public static final String FIELD_ALLOWED
public static final String FIELD_MESSAGE
public static final String FIELD_EXTENDEDRULE
| Constructor Detail |
|---|
public Security(ContextDb db)
db - the database contextpublic Security()
| Method Detail |
|---|
public static String permissionToString(int type,
int permission)
type - the permission typepermission - the permission
public static List<Security> createSecurityForObjectInOtherDb(AppDbObject fromObject,
AppDbObject toObject)
throws ApplicationException
AppDbObject.createCopyInContextDb(org.tentackle.appworx.ContextDb).
fromObject - toObject -
ApplicationException - if security instances could not be created
public boolean evaluate(ContextDb contextDb,
int permission)
The method is only invoked for rules that apply to the object and/or class in question.
Notice further, that due to servermode the given ContextDb may point to a different
Db than this security rule. For example, if some extendedRule must load data
from the db, it must handle that appropriately.
contextDb - the context-Db the object or class is used in, null = allpermission - the requested permission(s)
public AppDbObject getObject()
public void setObject(AppDbObject object)
object - the object, null to clearpublic void setObjectClass(Class clazz)
AppDbObject only the basename
will be stored. Otherwise the full qualified classname
is used.
clazz - the objectclasspublic AppDbObject getGrantee()
public void setGrantee(AppDbObject grantee)
grantee - the grantee, null to clear (all)public AppDbObject getContextObject()
public void setContextObject(AppDbObject contextObject)
contextObject - the context object, null to clear (all)public FormTableEntry getFormTableEntry()
AppDbObjectFormTable.AppDbObjectDefaultTableEntry.
Should be overridden in subclasses.
getFormTableEntry in class AppDbObjectAppDbObject.getFormTableName()public String getFormTableName()
AppDbObjectAppDbObject.formTableName.
Should be overridden.
getFormTableName in class AppDbObjectAppDbObject.getFormTableEntry()public Security select(long id)
select in class AppDbObjectid - is the object id
public String toString()
toString in class DbObjectpublic String orderBy()
orderBy in class AppDbObjectpublic AppDbObjectClassVariables getAppDbObjectClassVariables()
AppDbObjectAppDbObjectClassVariables.Notice: we cannot use a covariant method getDbObjectClassVariables() returning AppDbObjectClassVariables because super.getDbObjectClassVariables() is abstract and in that case covariance does not work. You will get the compiler error: "abstract method getDbObjectClassVariables() in org.tentackle.db.DbObject cannot be accessed directly"
getAppDbObjectClassVariables in class AppDbObjectDbObject.getDbObjectClassVariables()public boolean isCountingModification(int modType)
isCountingModification in class DbObjectmodType - is one of the modtypes INSERT, UPDATE, DELETE, ...
ModificationCounterpublic List<Security> selectByGrantId(long grantId)
grantId - the grantee's object ID
public TrackedArrayList<Security> selectByObject(long objectId,
String objectClass)
objectId - the object's IDobjectClass - the object's class
public TrackedArrayList<Security> selectByObject(AppDbObject object)
object - the object
public int deleteByGrantee(long grantId)
grantId - the grantee's object ID
public int deleteByObject(long objectId,
String objectClass)
objectId - the object's IDobjectClass - the object's class
public int deleteByObject(AppDbObject object)
object - the database object
public int deleteObjectRulesByObjectClass(String objectClass)
objectClass - the object class
public int deleteObjectRulesByObjectClassAndContext(String objectClass,
long contextId,
String contextClass)
objectClass - the object classcontextId - the ID of the context objectcontextClass - the class of the context object
public int deleteObjectRulesByGrantClass(String grantClass)
grantClass - the grantee class
public int deleteObjectRulesByGrantClassAndContext(String grantClass,
long contextId,
String contextClass)
grantClass - the grantee classcontextId - the ID of the context objectcontextClass - the class of the context object
public boolean isTracked()
isTracked in class DbObjectpublic String getObjectClass()
public void setObjectClass(String objectClass)
objectClass - classbasename if database class, else full classnamepublic long getObjectId()
public void setObjectId(long objectId)
objectId - object id, 0=all or not a database classpublic long getContextId()
getContextId in interface ContextDependablegetContextId in class AppDbObjectpublic void setContextId(long contextId)
contextId - ID of context object, 0 = all of contextClasspublic String getContextClass()
public void setContextClass(String contextClass)
contextClass - classbasename of ContextDb's Rootobjectpublic long getGrantId()
public void setGrantId(long grantId)
grantId - ID of grantobject, 0 = all of grantClasspublic String getGrantClass()
public void setGrantClass(String grantClass)
grantClass - classbasename of grantobjectpublic int getPriority()
public void setPriority(int priority)
priority - ordering, 0=firstpublic int getPermissionType()
public void setPermissionType(int permissionType)
permissionType - set of possible Permissionspublic int getPermission()
public void setPermission(int permission)
permission - permissionbits according to permtypepublic boolean getAllowed()
public void setAllowed(boolean allowed)
allowed - false=denied, true=allowedpublic String getMessage()
public void setMessage(String message)
message - user messagepublic Binary getExtendedRule()
public void setExtendedRule(Binary extendedRule)
extendedRule - extension objectpublic boolean prepareSetFields()
Overridden to set the normtext from DbObject.toString().
Overridden to assert objectClass != null.
prepareSetFields in class AppDbObjectpublic boolean getFields(ResultSetWrapper rs)
DbObjectResultSetWrapper and stores them in the object's attributes.
getFields in class DbObjectrs - the result set
public int setFields(PreparedStatementWrapper st)
DbObjectPreparedStatementWrapper from the object's attributes.
setFields in class DbObjectst - the statement
public int prepareInsertStatement()
DbObject
prepareInsertStatement in class DbObjectpublic int prepareUpdateStatement()
DbObject
prepareUpdateStatement in class DbObject
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||