Skip to content

Commit

Permalink
feat: add role
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Jan 7, 2024
1 parent e1b91c4 commit fbf89ee
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<PermissionAssignment> {
}
10 changes: 10 additions & 0 deletions src/main/java/io/github/onecx/permission/domain/daos/RoleDAO.java
Original file line number Diff line number Diff line change
@@ -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<Role> {

}
Original file line number Diff line number Diff line change
@@ -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;
}
45 changes: 45 additions & 0 deletions src/main/java/io/github/onecx/permission/domain/models/Role.java
Original file line number Diff line number Diff line change
@@ -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;

}
25 changes: 25 additions & 0 deletions src/test/java/io/github/onecx/permission/test/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
}
}

0 comments on commit fbf89ee

Please sign in to comment.