be.personify.iam.model.authentication.Rule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of personify-model Show documentation
Show all versions of personify-model Show documentation
a possible model for personify
package be.personify.iam.model.authentication;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import be.personify.iam.model.util.Persisted;
import be.personify.util.Decision;
import be.personify.util.generator.MetaInfo;
@Entity
@MetaInfo( name="Rule", group="authentication", frontendGroup = "Authorization",
description="A rule", iconClass = "exclamation-circle", number=6, showInMenu = true)
@Table(name="rule", indexes = {
@Index(name = "idx_rule_role", columnList = "role", unique=false)
})
public class Rule extends Persisted implements Serializable {
private static final long serialVersionUID = -3914376150577055068L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@MetaInfo(name="The id of the object", description="The id of the object", showInSearchResultGrid = false)
private long id;
/**
* Role.
*/
@MetaInfo(name="the role", description="the role linked to this rule")
private String role;
/**
* Linked permission object.
*/
@OneToOne
@MetaInfo(name="the permision", description="the permission linked to this rule : see permission_", searchable = false)
private Permission permission;
/**
* Rules have a decision which is used to determine whether the permission is allowed or denied.
*/
@Enumerated(EnumType.STRING)
@MetaInfo(name="the decision", description="the descion linked to this rule : ALLOW, DENY")
private Decision decision;
/**
* Rules can have extra conditions to determine if they are applicable for a certain user.
*/
@OneToMany(mappedBy="rule", cascade=CascadeType.ALL)
@ElementCollection(targetClass=Rule.class)
@MetaInfo(name="the rule conditions", description="the rule conditions linked to this rule : see ruleCondition_")
private List ruleConditions;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public Permission getPermission() {
return permission;
}
public void setPermission(Permission permission) {
this.permission = permission;
}
public Decision getDecision() {
return decision;
}
public void setDecision(Decision decision) {
this.decision = decision;
}
public List getRuleConditions() {
return ruleConditions;
}
public void setRuleConditions(List ruleConditions) {
this.ruleConditions = ruleConditions;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((decision == null) ? 0 : decision.hashCode());
result = prime * result + (int) (id ^ (id >>> 32));
result = prime * result + ((permission == null) ? 0 : permission.hashCode());
result = prime * result + ((role == null) ? 0 : role.hashCode());
result = prime * result + ((ruleConditions == null) ? 0 : ruleConditions.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
Rule other = (Rule) obj;
if (decision != other.decision)
return false;
if (id != other.id)
return false;
if (permission == null) {
if (other.permission != null)
return false;
} else if (!permission.equals(other.permission))
return false;
if (role == null) {
if (other.role != null)
return false;
} else if (!role.equals(other.role))
return false;
if (ruleConditions == null) {
if (other.ruleConditions != null)
return false;
} else if (!ruleConditions.equals(other.ruleConditions))
return false;
return true;
}
}