Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add security domain

  • Loading branch information...
commit 6ee2dc6ef77292c2bed5b160ef1f58af5dcc35b2 1 parent 00a86da
@martinusadyh authored
View
21 domain/src/main/java/id/web/martinusadyh/logbook/domain/security/Permission.java
@@ -0,0 +1,21 @@
+package id.web.martinusadyh.logbook.domain.security;
+
+import id.web.martinusadyh.logbook.domain.BaseEntity;
+import java.io.Serializable;
+
+/**
+ *
+ * @author martinus
+ */
+public class Permission extends BaseEntity implements Serializable {
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
View
63 domain/src/main/java/id/web/martinusadyh/logbook/domain/security/Role.java
@@ -0,0 +1,63 @@
+package id.web.martinusadyh.logbook.domain.security;
+
+import id.web.martinusadyh.logbook.domain.BaseEntity;
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+import org.hibernate.annotations.Cascade;
+
+/**
+ *
+ * @author martinus
+ */
+@Entity
+@Table(name="role")
+public class Role extends BaseEntity implements Serializable {
+
+ @Column(unique = true, nullable = false)
+ private String name;
+
+ @ManyToMany(cascade = CascadeType.ALL)
+ @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
+ @JoinTable(name = "role_permission",
+ joinColumns =
+ @JoinColumn(name = "id_role"),
+ inverseJoinColumns =
+ @JoinColumn(name = "id_permission"))
+ private Set<Permission> daftarPermission = new HashSet<Permission>();
+
+ public Boolean hasPermission(Permission permission) {
+ if (permission == null || permission.getId() == null) {
+ return false;
+ }
+ for (Permission p : daftarPermission) {
+ if (permission.getId().equals(p.getId())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Set<Permission> getDaftarPermission() {
+ return daftarPermission;
+ }
+
+ public void setDaftarPermission(Set<Permission> daftarPermission) {
+ this.daftarPermission = daftarPermission;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
View
18 domain/src/main/java/id/web/martinusadyh/logbook/domain/security/UserProfile.java
@@ -5,8 +5,13 @@
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
+import org.hibernate.annotations.Fetch;
+import org.hibernate.annotations.FetchMode;
/**
*
@@ -33,6 +38,11 @@
@Column(name="password")
private String password;
+
+ @ManyToOne(fetch=FetchType.EAGER)
+ @Fetch(FetchMode.JOIN)
+ @JoinColumn(name="id_role", nullable=false)
+ private Role role;
@OneToMany(mappedBy = "solvedBy")
private List<LogBookDetails> logBooksSolvedBy;
@@ -40,6 +50,14 @@
@OneToMany(mappedBy = "receivedBy")
private List<LogBookDetails> logBooksReceivedBy;
+ public Role getRole() {
+ return role;
+ }
+
+ public void setRole(Role role) {
+ this.role = role;
+ }
+
public String getEmailAddress() {
return emailAddress;
}
View
6 jpa/src/main/resources/hibernate.cfg.xml
@@ -14,6 +14,10 @@
<mapping class="id.web.martinusadyh.logbook.domain.trx.LogBookDetails" />
<mapping class="id.web.martinusadyh.logbook.domain.utility.EmailTemplate" />
- <mapping class="id.web.martinusadyh.logbook.domain.utility.UserProfile" />
+
+ <!-- security -->
+ <mapping class="id.web.martinusadyh.logbook.domain.security.UserProfile" />
+ <mapping class="id.web.martinusadyh.logbook.domain.security.Role" />
+ <mapping class="id.web.martinusadyh.logbook.domain.security.Permission" />
</session-factory>
</hibernate-configuration>

0 comments on commit 6ee2dc6

Please sign in to comment.
Something went wrong with that request. Please try again.