Problem with EntityIdentifierStrategy and PermissionManager
mroeoesli Oct 23, 2008 12:09 PMProblem with EntityIdentifierStrategy and PermissionManager
I try to grant a permission to an entity. my permission store works properly for non entity objects with my own IdentifierStrategy implementation but not for entitys using the EntityIdentifierStrategy.
this is my entity class:
@Entity
@Table(name = "DUMMY_USER")
@Identifier(value = EntityIdentifierStrategy.class)
@Name("dummyUser")
public class DummyUser implements Serializable{
private static final long serialVersionUID = -3134097431661355175L;
@Id
@Column(name = "ID")
@GeneratedValue(generator = "pomopSequenceGenerator")
@GenericGenerator(name = "pomopSequenceGenerator", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = {
@Parameter(name = "sequence_name", value = "POMOP_SEQUENCE"),
@Parameter(name = "initial_value", value = "1000"),
@Parameter(name = "increment_size", value = "1") })
public Long id;
@Column(name = "FIRSTNAME", length = 63, nullable = false)
private String firstname;
/**
*
*/
@Length(max=20)
@Column(name = "LASTNAME", length = 63, nullable = false)
private String lastname;
@Column(name = "EMAIL", length = 255, nullable = true)
private String email;
@OneToMany(cascade = CascadeType.ALL)
private List<DummySettings> settings;
@OneToOne(cascade = CascadeType.ALL)
private DummySettings setting=new DummySettings("test");
public List<DummySettings> getSettings() {
return settings;
}
public void setSettings(List<DummySettings> settings) {
this.settings = settings;
}
public DummyUser() {
}
public DummyUser(String firstname, String lastname, String email) {
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getFullname() {
return getFirstname() + " " + getLastname();
}
public void postLoad()
{
System.out.println("*************************");
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return email;
}
/**
* fgdfgfdgfdgfdg. {@link AbstractOwnedEntity}
*
* @param email
*/
public void setEmail(String email) {
this.email = email;
}
public String toString() {
return getFirstname() + " " + getLastname();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public DummySettings getSetting() {
return setting;
}
public void setSetting(DummySettings setting) {
this.setting = setting;
}
}
I made a rule to grant permissions for this class in my security.drl file
rule ManageDummyUserGrantPermissions no-loop activation-group "permissions" when du: DummyUser() check: PermissionCheck(target == du, action == "seam.grant-permission", granted == false) Role(name == "root") then check.grant(); end
I call the method grantUpdateForRoleRoot() from a jsf button. The user who click on this button is authed successfuly by the identityManager and has the role root
I want to give the update
action to this target for the role root
Here is the method what will be called:
public void grantUpdateForRoleRoot()
{
DummyUser du = (DummyUser) getDataTable().getRowData();
Role r = new Role("root");
Permission p= new Permission(du,"update",r);
this.permissionManager.grantPermission(p);
}
I call the method grantUpdateForRoleRoot() from a jsf button. The user who click on this button is authed successfuly by the identityManager and has the role root
I want to give the update
action to this target for the role root
Here is the method what will be called:
public void grantUpdateForRoleRoot()
{
DummyUser du = (DummyUser) getDataTable().getRowData();
Role r = new Role("root");
Permission p= new Permission(du,"update",r);
this.permissionManager.grantPermission(p);
}
while debuging everything is ok until it comes here
EntityIdentifierStrategy Line 59 in private String getIdentifierName(Class cls)
Identifier identifier = (Identifier) cls.getAnnotation(Identifier.class);
this line throws an NullPointer exception
this will be called from IdentityPolicy (line 85) from method getIdentifier(Object target))
return strategy != null ? strategy.getIdentifier(target) : null;
and this will be called from JpaPermissionStore (Line 224 in method createPermissionQuery(..)
if (target != null) query.setParameter("target", identifierPolicy.getIdentifier(target));
finally the exception from above will be catched in JpaPermissionStore (Line 428) in method updatePermissionActions(..)
...
catch (Exception ex)
{
throw new RuntimeException("Could not grant permission", ex);
}
what can be the problem? my bee its not able to find the @Id annotation
thx for your help
greetz Marco