Compare commits
2 Commits
8b78265e51
...
c67af5948b
Author | SHA1 | Date | |
---|---|---|---|
|
c67af5948b | ||
|
1c2cdf207c |
@ -20,6 +20,7 @@ import net.hostsharing.hsadminng.test.dom.TestDomainEntity;
|
|||||||
import net.hostsharing.hsadminng.test.pac.TestPackageEntity;
|
import net.hostsharing.hsadminng.test.pac.TestPackageEntity;
|
||||||
|
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.persistence.Version;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@ -29,6 +30,7 @@ import java.util.function.Consumer;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static java.lang.reflect.Modifier.isStatic;
|
import static java.lang.reflect.Modifier.isStatic;
|
||||||
|
import static java.util.Arrays.stream;
|
||||||
import static java.util.Optional.ofNullable;
|
import static java.util.Optional.ofNullable;
|
||||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR;
|
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR;
|
||||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.autoFetched;
|
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.autoFetched;
|
||||||
@ -76,7 +78,7 @@ public class RbacView {
|
|||||||
|
|
||||||
public RbacView withUpdatableColumns(final String... columnNames) {
|
public RbacView withUpdatableColumns(final String... columnNames) {
|
||||||
Collections.addAll(updatableColumns, columnNames);
|
Collections.addAll(updatableColumns, columnNames);
|
||||||
// TODO: automatically add @Version column, otherwise optimistic locking won't work
|
verifyVersionColumnExists();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,6 +216,14 @@ public class RbacView {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void verifyVersionColumnExists() {
|
||||||
|
if (stream(rootEntityAlias.entityClass.getDeclaredFields())
|
||||||
|
.noneMatch(f -> f.getAnnotation(Version.class) != null)) {
|
||||||
|
// TODO: convert this into throw Exception once RbacEntity is a base class with @Version field
|
||||||
|
System.err.println("@Version field required in updatable entity " + rootEntityAlias.entityClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public RbacGrantBuilder toRole(final String entityAlias, final Role role) {
|
public RbacGrantBuilder toRole(final String entityAlias, final Role role) {
|
||||||
return new RbacGrantBuilder(entityAlias, role);
|
return new RbacGrantBuilder(entityAlias, role);
|
||||||
}
|
}
|
||||||
@ -801,7 +811,7 @@ public class RbacView {
|
|||||||
HsOfficeCoopSharesTransactionEntity.class,
|
HsOfficeCoopSharesTransactionEntity.class,
|
||||||
HsOfficeMembershipEntity.class
|
HsOfficeMembershipEntity.class
|
||||||
).forEach(c -> {
|
).forEach(c -> {
|
||||||
final Method mainMethod = Arrays.stream(c.getMethods()).filter(
|
final Method mainMethod = stream(c.getMethods()).filter(
|
||||||
m -> isStatic(m.getModifiers()) && m.getName().equals("main")
|
m -> isStatic(m.getModifiers()) && m.getName().equals("main")
|
||||||
)
|
)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
|
@ -127,9 +127,9 @@ public class RbacGrantsDiagramService {
|
|||||||
: "";
|
: "";
|
||||||
|
|
||||||
final var grants = graph.stream()
|
final var grants = graph.stream()
|
||||||
.map(g -> quoted(g.getAscendantIdName()) +
|
.map(g -> quoted(g.getAscendantIdName())
|
||||||
(g.isAssumed() ? " --> " : " -.-> ") +
|
+ " -->" + (g.isAssumed() ? " " : "|XX| ")
|
||||||
quoted(g.getDescendantIdName()))
|
+ quoted(g.getDescendantIdName()))
|
||||||
.sorted()
|
.sorted()
|
||||||
.collect(joining("\n"));
|
.collect(joining("\n"));
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ public class TestCustomerController implements TestCustomersApi {
|
|||||||
context.define(currentUser, assumedRoles);
|
context.define(currentUser, assumedRoles);
|
||||||
|
|
||||||
final var saved = testCustomerRepository.save(mapper.map(customer, TestCustomerEntity.class));
|
final var saved = testCustomerRepository.save(mapper.map(customer, TestCustomerEntity.class));
|
||||||
em.flush();
|
|
||||||
final var uri =
|
final var uri =
|
||||||
MvcUriComponentsBuilder.fromController(getClass())
|
MvcUriComponentsBuilder.fromController(getClass())
|
||||||
.path("/api/test/customers/{id}")
|
.path("/api/test/customers/{id}")
|
||||||
|
@ -41,7 +41,7 @@ public class TestCustomerEntity implements HasUuid {
|
|||||||
.withIdentityView(SQL.projection("prefix"))
|
.withIdentityView(SQL.projection("prefix"))
|
||||||
.withRestrictedViewOrderBy(SQL.expression("reference"))
|
.withRestrictedViewOrderBy(SQL.expression("reference"))
|
||||||
.withUpdatableColumns("reference", "prefix", "adminUserName")
|
.withUpdatableColumns("reference", "prefix", "adminUserName")
|
||||||
// TODO: do we want explicit specification of parent-indenpendent insert permissions?
|
// TODO: do we want explicit specification of parent-independent insert permissions?
|
||||||
// .toRole("global", ADMIN).grantPermission("customer", INSERT)
|
// .toRole("global", ADMIN).grantPermission("customer", INSERT)
|
||||||
|
|
||||||
.createRole(OWNER, (with) -> {
|
.createRole(OWNER, (with) -> {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
### rbac customer 2024-03-10T11:42:41.089596517
|
### rbac customer 2024-03-11T09:06:04.484587070
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
%%{init:{'flowchart':{'htmlLabels':false}}}%%
|
%%{init:{'flowchart':{'htmlLabels':false}}}%%
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--liquibase formatted sql
|
--liquibase formatted sql
|
||||||
-- This code generated was by RbacViewPostgresGenerator at 2024-03-10T11:42:41.121556631.
|
-- This code generated was by RbacViewPostgresGenerator at 2024-03-11T09:06:04.497071201.
|
||||||
|
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
--changeset test-customer-rbac-OBJECT:1 endDelimiter:--//
|
--changeset test-customer-rbac-OBJECT:1 endDelimiter:--//
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
### rbac package 2024-03-10T11:42:41.162678472
|
### rbac package 2024-03-11T09:06:04.536081351
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
%%{init:{'flowchart':{'htmlLabels':false}}}%%
|
%%{init:{'flowchart':{'htmlLabels':false}}}%%
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--liquibase formatted sql
|
--liquibase formatted sql
|
||||||
-- This code generated was by RbacViewPostgresGenerator at 2024-03-10T11:42:41.163393064.
|
-- This code generated was by RbacViewPostgresGenerator at 2024-03-11T09:06:04.536525766.
|
||||||
|
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
--changeset test-package-rbac-OBJECT:1 endDelimiter:--//
|
--changeset test-package-rbac-OBJECT:1 endDelimiter:--//
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--liquibase formatted sql
|
--liquibase formatted sql
|
||||||
-- This code generated was by RbacViewPostgresGenerator at 2024-03-10T11:42:41.186902574.
|
-- This code generated was by RbacViewPostgresGenerator at 2024-03-11T09:06:04.558752062.
|
||||||
|
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
--changeset test-domain-rbac-OBJECT:1 endDelimiter:--//
|
--changeset test-domain-rbac-OBJECT:1 endDelimiter:--//
|
||||||
|
@ -473,7 +473,6 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
|||||||
.contact(givenContact)
|
.contact(givenContact)
|
||||||
.build();
|
.build();
|
||||||
relationshipRepo.save(partnerRole);
|
relationshipRepo.save(partnerRole);
|
||||||
em.flush(); // TODO: why is that necessary?
|
|
||||||
|
|
||||||
final var newPartner = HsOfficePartnerEntity.builder()
|
final var newPartner = HsOfficePartnerEntity.builder()
|
||||||
.partnerNumber(partnerNumber)
|
.partnerNumber(partnerNumber)
|
||||||
|
Loading…
Reference in New Issue
Block a user