-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
200 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
rest-api/src/main/java/life/qbic/data_download/rest/security/acl/setup-acl.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
CREATE TABLE acl_sid | ||
( | ||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
principal BOOLEAN NOT NULL, | ||
sid VARCHAR(100) NOT NULL, | ||
UNIQUE KEY unique_acl_sid (sid, principal) | ||
) ENGINE = InnoDB; | ||
|
||
CREATE TABLE acl_class | ||
( | ||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
class VARCHAR(100) NOT NULL, | ||
class_id_type VARCHAR(100) NOT NULL, | ||
UNIQUE KEY uk_acl_class (class) | ||
) ENGINE = InnoDB; | ||
|
||
CREATE TABLE acl_object_identity | ||
( | ||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
object_id_class BIGINT UNSIGNED NOT NULL, | ||
object_id_identity VARCHAR(36) NOT NULL, | ||
parent_object BIGINT UNSIGNED, | ||
owner_sid BIGINT UNSIGNED, | ||
entries_inheriting BOOLEAN NOT NULL, | ||
UNIQUE KEY uk_acl_object_identity (object_id_class, object_id_identity), | ||
CONSTRAINT fk_acl_object_identity_parent FOREIGN KEY (parent_object) REFERENCES acl_object_identity (id), | ||
CONSTRAINT fk_acl_object_identity_class FOREIGN KEY (object_id_class) REFERENCES acl_class (id), | ||
CONSTRAINT fk_acl_object_identity_owner FOREIGN KEY (owner_sid) REFERENCES acl_sid (id) | ||
) ENGINE = InnoDB; | ||
|
||
CREATE TABLE acl_entry | ||
( | ||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
acl_object_identity BIGINT UNSIGNED NOT NULL, | ||
ace_order INTEGER NOT NULL, | ||
sid BIGINT UNSIGNED NOT NULL, | ||
mask INTEGER UNSIGNED NOT NULL, | ||
granting BOOLEAN NOT NULL, | ||
audit_success BOOLEAN NOT NULL DEFAULT true, | ||
audit_failure BOOLEAN NOT NULL, | ||
UNIQUE KEY unique_acl_entry (acl_object_identity, ace_order), | ||
CONSTRAINT fk_acl_entry_object FOREIGN KEY (acl_object_identity) REFERENCES acl_object_identity (id), | ||
CONSTRAINT fk_acl_entry_acl FOREIGN KEY (sid) REFERENCES acl_sid (id) ON DELETE CASCADE | ||
) ENGINE = InnoDB; | ||
|
||
INSERT INTO acl_class(id, class, class_id_type) | ||
VALUES (1, 'life.qbic.projectmanagement.domain.model.project.Project', 'java.lang.String'); |
5 changes: 5 additions & 0 deletions
5
rest-api/src/main/java/life/qbic/data_download/rest/security/jpa/setup-roles.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
INSERT INTO roles(id, name, description) | ||
VALUES (1, 'ADMIN', 'Full administration of the application'), | ||
(2, 'USER', 'Standard user of the application'), | ||
(3, 'PROJECT_MANAGER', 'Manages projects at QBiC') | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
rest-api/src/main/java/life/qbic/data_download/rest/security/jpa/user/Role.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package life.qbic.data_download.rest.security.jpa.user; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import java.util.Optional; | ||
import java.util.StringJoiner; | ||
import org.springframework.data.annotation.ReadOnlyProperty; | ||
import org.springframework.security.core.GrantedAuthority; | ||
|
||
@Entity | ||
@Table(name = "roles") | ||
public class Role implements GrantedAuthority { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
@ReadOnlyProperty | ||
private long id; | ||
|
||
@Column(name = "name") | ||
@ReadOnlyProperty | ||
private String name; | ||
|
||
@Column(name = "description") | ||
@ReadOnlyProperty | ||
private String description; | ||
|
||
|
||
protected Role() { | ||
} | ||
|
||
protected Role(long id, String name, String description) { | ||
this.id = id; | ||
this.name = name; | ||
this.description = description; | ||
} | ||
|
||
public String name() { | ||
requireNonNull(this.name); | ||
return name; | ||
} | ||
|
||
public Optional<String> description() { | ||
return Optional.ofNullable(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", Role.class.getSimpleName() + "[", "]") | ||
.add("id='" + id + "'") | ||
.add("name='" + name + "'") | ||
.add("description='" + description + "'") | ||
.toString(); | ||
} | ||
|
||
@Override | ||
public String getAuthority() { | ||
return "ROLE_" + name(); | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} else { | ||
return obj instanceof GrantedAuthority && this.getAuthority() | ||
.equals(((GrantedAuthority) obj).getAuthority()); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return getAuthority().hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
rest-api/src/main/java/life/qbic/data_download/rest/security/jpa/user/UserRole.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package life.qbic.data_download.rest.security.jpa.user; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import java.io.Serializable; | ||
import org.springframework.data.annotation.ReadOnlyProperty; | ||
|
||
@Entity | ||
@Table(name = "user_role") | ||
public class UserRole implements Serializable { | ||
@Id | ||
@Column(name = "id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@ReadOnlyProperty | ||
private long id; | ||
|
||
@ManyToOne(optional = false) | ||
@JoinColumn(name = "userId", nullable = false) | ||
@ReadOnlyProperty | ||
private QBiCUserDetails user; | ||
|
||
@ManyToOne(optional = false) | ||
@JoinColumn(name = "roleId") | ||
@ReadOnlyProperty | ||
private Role role; | ||
|
||
public Role role() { | ||
return role; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters