CCM NG: Permission and Privilege entities
git-svn-id: https://svn.libreccm.org/ccm/jpa@3392 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
fe957e93a5
commit
e122bc3f5e
|
|
@ -88,7 +88,7 @@ public class Domain extends CcmObject implements Serializable {
|
||||||
* http://example.org/domains/example-nav
|
* http://example.org/domains/example-nav
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
@Column(name = "uri", nullable = false, unique = true, length = 2048)
|
@Column(name = "uri", nullable = false, length = 2048)
|
||||||
@Convert(converter = UriConverter.class)
|
@Convert(converter = UriConverter.class)
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@URL
|
@URL
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,9 @@ public class CcmObject implements Serializable {
|
||||||
@Column(name = "display_name")
|
@Column(name = "display_name")
|
||||||
private String displayName;
|
private String displayName;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "object")
|
||||||
|
private List<Permission> permissions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Category Domains owned by this {@code CcmObject}.
|
* Category Domains owned by this {@code CcmObject}.
|
||||||
*/
|
*/
|
||||||
|
|
@ -93,6 +96,7 @@ public class CcmObject implements Serializable {
|
||||||
public CcmObject() {
|
public CcmObject() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
permissions = new ArrayList<>();
|
||||||
domains = new ArrayList<>();
|
domains = new ArrayList<>();
|
||||||
categories = new ArrayList<>();
|
categories = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
@ -113,6 +117,22 @@ public class CcmObject implements Serializable {
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Permission> getPermissions() {
|
||||||
|
return Collections.unmodifiableList(permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setPermissions(final List<Permission> permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addPermission(final Permission permission) {
|
||||||
|
permissions.add(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removePermission(final Permission permission) {
|
||||||
|
permissions.remove(permission);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an <strong>unmodifiable</strong> list of the domains which are owned
|
* Gets an <strong>unmodifiable</strong> list of the domains which are owned
|
||||||
* by the {@code CcmObject}.
|
* by the {@code CcmObject}.
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ package org.libreccm.core;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.security.acl.Group;
|
import java.security.acl.Group;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -28,6 +29,7 @@ import javax.persistence.CollectionTable;
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
|
@ -47,28 +49,53 @@ public class Party extends CcmObject implements Serializable {
|
||||||
joinColumns = {
|
joinColumns = {
|
||||||
@JoinColumn(name = "party_id")})
|
@JoinColumn(name = "party_id")})
|
||||||
@Size(min = 1)
|
@Size(min = 1)
|
||||||
private List<EmailAddress> eMailAddresses;
|
private List<EmailAddress> emailAddresses;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "grantee")
|
||||||
|
private List<Permission> grantedPermissions;
|
||||||
|
|
||||||
|
public Party() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
grantedPermissions = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
public List<EmailAddress> getEmailAddresses() {
|
public List<EmailAddress> getEmailAddresses() {
|
||||||
return Collections.unmodifiableList(eMailAddresses);
|
return Collections.unmodifiableList(emailAddresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setEmailAddresses(final List<EmailAddress> eMailAddresses) {
|
protected void setEmailAddresses(final List<EmailAddress> eMailAddresses) {
|
||||||
this.eMailAddresses = eMailAddresses;
|
this.emailAddresses = eMailAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addEmailAddress(final EmailAddress emailAddress) {
|
protected void addEmailAddress(final EmailAddress emailAddress) {
|
||||||
eMailAddresses.add(emailAddress);
|
emailAddresses.add(emailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeEmailAddress(final EmailAddress emailAddress) {
|
protected void removeEmailAddress(final EmailAddress emailAddress) {
|
||||||
eMailAddresses.remove(emailAddress);
|
emailAddresses.remove(emailAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Permission> getGrantedPermissions() {
|
||||||
|
return Collections.unmodifiableList(grantedPermissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setGrantedPermissions(final List<Permission> grantedPermissions) {
|
||||||
|
this.grantedPermissions = grantedPermissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addGrantedPermission(final Permission permission) {
|
||||||
|
grantedPermissions.add(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeGrantedPermission(final Permission permission) {
|
||||||
|
grantedPermissions.remove(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = super.hashCode();
|
int hash = super.hashCode();
|
||||||
hash = 41 * hash + Objects.hashCode(this.eMailAddresses);
|
hash = 41 * hash + Objects.hashCode(this.emailAddresses);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +116,7 @@ public class Party extends CcmObject implements Serializable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Objects.equals(this.eMailAddresses, other.getEmailAddresses());
|
return Objects.equals(this.emailAddresses, other.getEmailAddresses());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,204 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.core;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "permissions")
|
||||||
|
public class Permission implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2368935232499907547L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "permission_id")
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private long permissionId;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "grantee_id")
|
||||||
|
private Party grantee;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "granted_privilege_id")
|
||||||
|
private Privilege grantedPrivilege;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "object_id")
|
||||||
|
private CcmObject object;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "creation_user_id")
|
||||||
|
private User creationUser;
|
||||||
|
|
||||||
|
@Column(name = "creation_date")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date creationDate;
|
||||||
|
|
||||||
|
@Column(name = "creation_ip")
|
||||||
|
private String creationIp;
|
||||||
|
|
||||||
|
public long getPermissionId() {
|
||||||
|
return permissionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissionId(final long permissionId) {
|
||||||
|
this.permissionId = permissionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Party getGrantee() {
|
||||||
|
return grantee;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setGrantee(final Party grantee) {
|
||||||
|
this.grantee = grantee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Privilege getGrantedPrivilege() {
|
||||||
|
return grantedPrivilege;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setGrantedPrivilege(final Privilege grantedPrivilege) {
|
||||||
|
this.grantedPrivilege = grantedPrivilege;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CcmObject getObject() {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setObject(final CcmObject object) {
|
||||||
|
this.object = object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getCreationUser() {
|
||||||
|
return creationUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreationUser(final User creationUser) {
|
||||||
|
this.creationUser = creationUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreationDate() {
|
||||||
|
return new Date(creationDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreationDate(final Date creationDate) {
|
||||||
|
this.creationDate = new Date(creationDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreationIp() {
|
||||||
|
return creationIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreationIp(final String creationIp) {
|
||||||
|
this.creationIp = creationIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 3;
|
||||||
|
hash
|
||||||
|
= 31 * hash + (int) (permissionId ^ (permissionId >>> 32));
|
||||||
|
hash = 31 * hash + Objects.hashCode(grantee);
|
||||||
|
hash = 31 * hash + Objects.hashCode(grantedPrivilege);
|
||||||
|
hash = 31 * hash + Objects.hashCode(object);
|
||||||
|
hash = 31 * hash + Objects.hashCode(creationUser);
|
||||||
|
hash = 31 * hash + Objects.hashCode(creationDate);
|
||||||
|
hash = 31 * hash + Objects.hashCode(creationIp);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final Permission other = (Permission) obj;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (permissionId != other.getPermissionId()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Objects.equals(grantee, other.getGrantee())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Objects.equals(grantedPrivilege, other.getGrantedPrivilege())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Objects.equals(object, other.getObject())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Objects.equals(creationUser, other.getCreationUser())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Objects.equals(creationDate, other.getCreationDate())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Objects.equals(creationIp, other.getCreationIp());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canEqual(final Object obj) {
|
||||||
|
return obj instanceof Permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("%s{ "
|
||||||
|
+ "permissionId = %d, "
|
||||||
|
+ "grantee = %s, "
|
||||||
|
+ "grantedPrivilege = %s, "
|
||||||
|
+ "object = %s, "
|
||||||
|
+ "creationUser = %s,"
|
||||||
|
+ "creationDate = %tF %<tT, "
|
||||||
|
+ "creationIp = %s"
|
||||||
|
+ " }",
|
||||||
|
super.toString(),
|
||||||
|
permissionId,
|
||||||
|
Objects.toString(grantee),
|
||||||
|
Objects.toString(grantedPrivilege),
|
||||||
|
Objects.toString(object),
|
||||||
|
Objects.toString(creationUser),
|
||||||
|
creationDate,
|
||||||
|
creationIp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.core;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "privileges")
|
||||||
|
public class Privilege implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3986038536996049440L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "privilege_id")
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private long privilegeId;
|
||||||
|
|
||||||
|
@Column(name = "privilege", length = 255, nullable = false)
|
||||||
|
private String privilege;
|
||||||
|
|
||||||
|
public long getPrivilegeId() {
|
||||||
|
return privilegeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivilegeId(final long privilegeId) {
|
||||||
|
this.privilegeId = privilegeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrivilege() {
|
||||||
|
return privilege;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivilege(final String privilege) {
|
||||||
|
this.privilege = privilege;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 7;
|
||||||
|
hash = 43 * hash + (int) (privilegeId ^ (privilegeId >>> 32));
|
||||||
|
hash = 43 * hash + Objects.hashCode(privilege);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final Privilege other = (Privilege) obj;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (privilegeId != other.getPrivilegeId()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Objects.equals(privilege, other.getPrivilege());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canEqual(final Object obj) {
|
||||||
|
return obj instanceof Privilege;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("%s{ "
|
||||||
|
+ "privilegeId = %d, "
|
||||||
|
+ "privilege = \"%s\""
|
||||||
|
+ " }",
|
||||||
|
super.toString(),
|
||||||
|
privilegeId,
|
||||||
|
privilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue