diff --git a/src/main/java/io/github/onecx/permission/domain/daos/PermissionAssignmentDAO.java b/src/main/java/io/github/onecx/permission/domain/daos/PermissionAssignmentDAO.java new file mode 100644 index 0000000..328d2ce --- /dev/null +++ b/src/main/java/io/github/onecx/permission/domain/daos/PermissionAssignmentDAO.java @@ -0,0 +1,9 @@ +package io.github.onecx.permission.domain.daos; + +import io.github.onecx.permission.domain.models.PermissionAssignment; +import jakarta.enterprise.context.ApplicationScoped; +import org.tkit.quarkus.jpa.daos.AbstractDAO; + +@ApplicationScoped +public class PermissionAssignmentDAO extends AbstractDAO { +} diff --git a/src/main/java/io/github/onecx/permission/domain/daos/RoleDAO.java b/src/main/java/io/github/onecx/permission/domain/daos/RoleDAO.java new file mode 100644 index 0000000..39ae36b --- /dev/null +++ b/src/main/java/io/github/onecx/permission/domain/daos/RoleDAO.java @@ -0,0 +1,10 @@ +package io.github.onecx.permission.domain.daos; + +import io.github.onecx.permission.domain.models.Role; +import jakarta.enterprise.context.ApplicationScoped; +import org.tkit.quarkus.jpa.daos.AbstractDAO; + +@ApplicationScoped +public class RoleDAO extends AbstractDAO { + +} diff --git a/src/main/java/io/github/onecx/permission/domain/models/PermissionAssignment.java b/src/main/java/io/github/onecx/permission/domain/models/PermissionAssignment.java new file mode 100644 index 0000000..71d1bd5 --- /dev/null +++ b/src/main/java/io/github/onecx/permission/domain/models/PermissionAssignment.java @@ -0,0 +1,24 @@ +package io.github.onecx.permission.domain.models; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.TenantId; + +@Getter +@Setter +@Entity +@Table(name = "PERMISSION_ASSIGNMENT") +public class PermissionAssignment { + + @TenantId + @Column(name = "TENANT_ID") + private String tenantId; + + @Column(name = "ROLE_NAME") + private String roleName; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "PERMISSION_ID") + private Permission permission; +} diff --git a/src/main/java/io/github/onecx/permission/domain/models/Role.java b/src/main/java/io/github/onecx/permission/domain/models/Role.java new file mode 100644 index 0000000..6464042 --- /dev/null +++ b/src/main/java/io/github/onecx/permission/domain/models/Role.java @@ -0,0 +1,45 @@ +package io.github.onecx.permission.domain.models; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.TenantId; +import org.tkit.quarkus.jpa.models.TraceableEntity; + +@Getter +@Setter +@Entity +@Table(name = "ROLE", + uniqueConstraints = { + @UniqueConstraint(columnNames = {"TENANT_ID", "NAME"}) + } +) +@SuppressWarnings("java:S2160") +public class Role extends TraceableEntity { + + @TenantId + @Column(name = "TENANT_ID") + private String tenantId; + + /** + * The role name. + */ + @Column(name = "NAME") + private String name; + + /** + * The role description. + */ + @Column(name = "DESCRIPTION") + private String description; + + /** + * The role short description. + */ + @Column(name = "SHORT_DESCRIPTION") + private String shortDescription; + +} diff --git a/src/test/java/io/github/onecx/permission/test/AbstractTest.java b/src/test/java/io/github/onecx/permission/test/AbstractTest.java index 43defa9..d6b3d09 100644 --- a/src/test/java/io/github/onecx/permission/test/AbstractTest.java +++ b/src/test/java/io/github/onecx/permission/test/AbstractTest.java @@ -8,10 +8,21 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import io.restassured.config.RestAssuredConfig; +import io.smallrye.jwt.build.Jwt; +import io.smallrye.jwt.util.KeyUtils; +import jakarta.json.Json; +import jakarta.json.JsonObjectBuilder; +import org.eclipse.microprofile.config.ConfigProvider; +import org.eclipse.microprofile.jwt.Claims; + +import java.security.PrivateKey; @SuppressWarnings("java:S2187") public class AbstractTest { + protected static final String CLAIMS_ORG_ID = ConfigProvider.getConfig() + .getValue("%test.tkit.rs.context.tenant-id.mock.claim-org-id", String.class); + static { config = RestAssuredConfig.config().objectMapperConfig( objectMapperConfig().jackson2ObjectMapperFactory( @@ -22,4 +33,18 @@ public class AbstractTest { return objectMapper; })); } + + protected static String createToken(String organizationId) { + try { + String userName = "test-user"; + JsonObjectBuilder claims = Json.createObjectBuilder(); + claims.add(Claims.preferred_username.name(), userName); + claims.add(Claims.sub.name(), userName); + claims.add(CLAIMS_ORG_ID, organizationId); + PrivateKey privateKey = KeyUtils.generateKeyPair(2048).getPrivate(); + return Jwt.claims(claims.build()).sign(privateKey); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } }