Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
15.6.5. Securing Entities
Seam Security also lets you apply security restrictions to certain actions (read, insert, update, and delete) for entities.
To secure all actions for an entity class, add a
@Restrict
annotation on the class itself:
If no expression is specified in the
@Restrict
annotation, the default action is a permission check of entity:action
, where the permission target is the entity instance, and the action
is either read
, insert
, update
or delete
.
You can also restrict certain actions by placing a
@Restrict
annotation on the relevant entity lifecycle method (annotated as follows):
@PostLoad
— Called after an entity instance is loaded from the database. Use this method to configure aread
permission.@PrePersist
— Called before a new instance of the entity is inserted. Use this method to configure aninsert
permission.@PreUpdate
— Called before an entity is updated. Use this method to configure anupdate
permission.@PreRemove
— Called before an entity is deleted. Use this method to configure adelete
permission.
The following example shows how an entity can be configured to perform a security check for any
insert
operations. Note that the method need not perform any action; it is only important that it be annotated correctly:
@PrePersist @Restrict public void prePersist() {}
@PrePersist
@Restrict
public void prePersist() {}
Note
You can also specify the callback method in
/META-INF/orm.xml
:
You will still need to annotate the
prePersist()
method on Customer
with @Restrict
.
The following configuration is based on the Seamspace example, and checks if the authenticated user has permission to insert a new
MemberBlog
record. The entity being checked is automatically inserted into the working memory (in this case, MemberBlog
):
This rule grants the permission
memberBlog:insert
if the name of the currently authenticated user (indicated by the Principal
fact) matches that of the member for whom the blog entry is being created. The principal: Principal()
structure is a variable binding. It binds the instance of the Principal
object placed in the working memory during authentication, and assigns it to a variable called principal
. Variable bindings let the variable be referenced in other places, such as the following line, which compares the member name to the Principal
name. For further details, refer to the JBoss Rules documentation.
Finally, install a listener class to integrate Seam Security with your JPA provider.
15.6.5.1. Entity security with JPA Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
Security checks for EJB3 entity beans are performed with an
EntityListener
. Install this listener with the following META-INF/orm.xml
file: