|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.appworx.SecurityManager
public class SecurityManager
The SecurityManager applies Security-rules to AppDbObjects
and grants or denies privileges.
The rules themselves are AppDbObjects
and thus can be easily stored in the database. The SecurityManager keeps
a list of rules that belong to a user. Again, this can easily be
extended to roles. The list of rules is interpreted as an ACL (access
control list). Whenever a privilege is checked, the list is processes
until a rule fires. If no rule fires the default result is returned,
which is ether granted or denied.
| Field Summary | |
|---|---|
static ContextDb |
serverContextDb
ContextDb to enable "server mode". |
| Constructor Summary | |
|---|---|
SecurityManager()
Creates a disabled security manager. |
|
SecurityManager(AppDbObject user)
Creates a security manager for given user. |
|
SecurityManager(ContextDb contextDb,
long userId)
Creates a security manager for a given database context and user. |
|
| Method Summary | |
|---|---|
protected void |
addForGrantId(long grantId)
Adds the Security rules for a given grantee ID
to the ACL cache. |
ContextDb |
getContextDb()
Gets the database context for this manager. |
Class |
getSecurityClass()
Gets the class for Security rules.Must be overridden in apps if Security is extended. |
Class |
getSecurityDialogClass()
Gets the Class of a SecurityDialog. Override in apps if the SecurityDialog is not tentackle's one. |
SecurityResult |
getSecurityDialogPrivilege()
Checks whether the user is allowed to invoke the SecurityDialog. |
long |
getUserId()
Gets the object ID of the user's identity. |
protected void |
initialize()
Initializes the ACL. Must be overridden to implement roles. |
static void |
invalidateAll()
Marks the rules cache invalid in all security managers. |
boolean |
isAcceptByDefault()
Determines whether this manager accepts by default, i.e. |
boolean |
isDenyByDefault()
Determines whether this manager denies by default, i.e. |
boolean |
isEnabled()
Determines whether this manager is enabled. |
SecurityDialog |
newSecurityDialogInstance(AppDbObject object)
Creates a new SecurityDialog instance for a given data object. |
SecurityDialog |
newSecurityDialogInstance(ContextDb contextDb)
Creates a new SecurityDialog for the SecurityDialog itself. |
SecurityDialog |
newSecurityDialogInstance(ContextDb contextDb,
Class clazz)
Creates a new SecurityDialog instance for a class figuring out its permission type. |
SecurityDialog |
newSecurityDialogInstance(ContextDb contextDb,
int permissionType,
Class clazz)
Creates a new SecurityDialog instance for a class and permission type. |
SecurityDialog |
newSecurityDialogInstance(ContextDb contextDb,
int permissionType,
Class clazz,
long id)
Creates a new SecurityDialog.The dialog edits the rules for a given object or class. |
Security |
newSecurityInstance()
Creates a new Security instance.Security instances should not be created by their constructor. |
SecurityResult |
privilege(AppDbObject obj,
ContextDb contextDb,
int permission)
Checks a privilege for an AppDbObject.Usually the object-ID rules come first and then the objectclass-rules. |
SecurityResult |
privilege(AppDbObject obj,
int permission)
Checks a privilege for an AppDbObject.Usually the object-ID rules come first and then the objectclass-rules. |
SecurityResult |
privilege(Class clazz,
ContextDb contextDb,
int permission)
Checks a privilege for class only. |
SecurityResult |
privilege(Class clazz,
ContextDb contextDb,
long objectId,
int permission)
Checks a privilege. |
void |
setAcceptByDefault(boolean acceptByDefault)
Sets the default behaviour for "no rules found" for the SecurityResult to "accepted". |
void |
setDenyByDefault(boolean denyByDefault)
Sets the default behaviour for "no rules found" for the SecurityResult to "denied". |
void |
setEnabled(boolean enabled)
Enables/disables this security manager. If it is disabled, all requests return GRANT_DEFAULT, which usually will be treated by the application as GRANT_ACCEPT. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static ContextDb serverContextDb
| Constructor Detail |
|---|
public SecurityManager(ContextDb contextDb,
long userId)
contextDb - the database contextuserId - the object ID of the userpublic SecurityManager(AppDbObject user)
user - the userpublic SecurityManager()
| Method Detail |
|---|
public static void invalidateAll()
Security rules change in the
database.
public Security newSecurityInstance()
Security instance.
public Class getSecurityClass()
Security rules.
public SecurityDialog newSecurityDialogInstance(ContextDb contextDb,
int permissionType,
Class clazz,
long id)
throws ApplicationException
SecurityDialog.
contextDb - the contextDbclazz - the class to set security rules for.
(use org.tentackle.appworx.SecurityDialog.class if working on security itself)permissionType - the kind of permission set. If 0, will be determined from clazz (if AppDbObject)
or set to Security.TYPE_PROGRAM otherwise.id - he object id in clazz (if clazz is a AppDbObject) or null
if all objects or clazz is not a AppDbObject.
ApplicationException - is setup failed
public final SecurityDialog newSecurityDialogInstance(AppDbObject object)
throws ApplicationException
object - the AppDbObject
ApplicationException - is setup failed
public final SecurityDialog newSecurityDialogInstance(ContextDb contextDb,
int permissionType,
Class clazz)
throws ApplicationException
contextDb - the contextDb-contextpermissionType - the permission typeclazz - the class
ApplicationException - is setup failed
public final SecurityDialog newSecurityDialogInstance(ContextDb contextDb,
Class clazz)
throws ApplicationException
contextDb - the contextDb-contextclazz - the class
ApplicationException - is setup failed
public final SecurityDialog newSecurityDialogInstance(ContextDb contextDb)
throws ApplicationException
contextDb - the contextDb-context
ApplicationException - is setup failedpublic Class getSecurityDialogClass()
public ContextDb getContextDb()
public long getUserId()
public SecurityResult getSecurityDialogPrivilege()
public SecurityResult privilege(Class clazz,
ContextDb contextDb,
long objectId,
int permission)
clazz - the class, for example a FormDialog or an AppDbObject (never null!)contextDb - the context-Db the object or class is used in, null = allobjectId - the objectId or 0 if applies to class, -1 for "any object of given class"permission - the requested permission(s)
public SecurityResult privilege(Class clazz,
ContextDb contextDb,
int permission)
clazz - the class, for example a FormDialog or an AppDbObject (never null!)contextDb - the context-Db the object or class is used in, null = allpermission - the requested permission(s)
privilege(java.lang.Class, org.tentackle.appworx.ContextDb, long, int)
public SecurityResult privilege(AppDbObject obj,
ContextDb contextDb,
int permission)
AppDbObject.
obj - the database object (never null!)contextDb - the optional database context the object is used in, null = object's contextDbpermission - the requested permission(s)
privilege(java.lang.Class, org.tentackle.appworx.ContextDb, long, int)
public SecurityResult privilege(AppDbObject obj,
int permission)
AppDbObject.
obj - the database object (never null!)permission - the requested permission(s)
privilege(org.tentackle.appworx.AppDbObject, org.tentackle.appworx.ContextDb, int)protected void initialize()
protected void initialize() {
super.initialize();
// get all role IDs the user belongs to
for (Role r: new Role(getContextDb()).selectByUserId(getUserId())) {
addForGrantId(r.getId());
}
}
protected void addForGrantId(long grantId)
Security rules for a given grantee ID
to the ACL cache.
grantId - the grantee IDpublic boolean isEnabled()
public void setEnabled(boolean enabled)
enabled - New value of property enabled.setAcceptByDefault(boolean)public boolean isAcceptByDefault()
public void setAcceptByDefault(boolean acceptByDefault)
SecurityResult to "accepted".
This is the default.
Notice: setting both acceptByDefault and denyByDefault to false will return "neither accepted nor denied" security results if no rules fire.
acceptByDefault - true if SecurityResult.isAccepted() returns true if no rules found.public boolean isDenyByDefault()
public void setDenyByDefault(boolean denyByDefault)
SecurityResult to "denied". The default is false.
Notice: setting both acceptByDefault and denyByDefault to false will return "neither accepted nor denied" security results if no rules fire.
denyByDefault - true if SecurityResult.isDenied() returns true if no rules found.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||