refactor name extractors into entity classes
This commit is contained in:
parent
8041553734
commit
bc27e6dc89
@ -59,7 +59,10 @@ public class RbacGrantEntity {
|
||||
}
|
||||
|
||||
public String toDisplay() {
|
||||
return "{ grant " + (assumed ? "assumed " : "") +
|
||||
"role " + grantedRoleIdName + " to user " + granteeUserName + " by role " + grantedByRoleIdName + " }";
|
||||
return "{ grant role " + grantedRoleIdName +
|
||||
" to user " + granteeUserName +
|
||||
" by role " + grantedByRoleIdName +
|
||||
(assumed ? " and assume" : "") +
|
||||
" }";
|
||||
}
|
||||
}
|
||||
|
@ -20,16 +20,16 @@ public class RbacRoleEntity {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
|
||||
@Column(name="objectuuid")
|
||||
@Column(name = "objectuuid")
|
||||
private UUID objectUuid;
|
||||
|
||||
@Column(name="objecttable")
|
||||
@Column(name = "objecttable")
|
||||
private String objectTable;
|
||||
|
||||
@Column(name="objectidname")
|
||||
@Column(name = "objectidname")
|
||||
private String objectIdName;
|
||||
|
||||
@Column(name="roletype")
|
||||
@Column(name = "roletype")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private RbacRoleType roleType;
|
||||
|
||||
|
@ -23,8 +23,8 @@ import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.hsOfficeContact;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantDisplayExtractor.grantDisplaysOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleNameExtractor.roleNamesOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantDisplaysOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.roleNamesOf;
|
||||
import static net.hostsharing.test.JpaAttempt.attempt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
|
@ -26,8 +26,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantDisplayExtractor.grantDisplaysOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleNameExtractor.roleNamesOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantDisplaysOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.roleNamesOf;
|
||||
import static net.hostsharing.test.JpaAttempt.attempt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
|
@ -22,8 +22,8 @@ import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.person.TestHsOfficePerson.hsOfficePerson;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantDisplayExtractor.grantDisplaysOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleNameExtractor.roleNamesOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantDisplaysOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.roleNamesOf;
|
||||
import static net.hostsharing.test.JpaAttempt.attempt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
|
@ -1,14 +0,0 @@
|
||||
package net.hostsharing.hsadminng.rbac.rbacgrant;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RawRbacGrantDisplayExtractor {
|
||||
|
||||
@NotNull
|
||||
public static List<String> grantDisplaysOf(final List<RawRbacGrantEntity> roles) {
|
||||
return roles.stream().map(RawRbacGrantEntity::toDisplay).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
package net.hostsharing.hsadminng.rbac.rbacgrant;
|
||||
|
||||
import lombok.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.data.annotation.Immutable;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Entity
|
||||
@Table(name = "rbacgrants_ev")
|
||||
@ -52,4 +55,10 @@ public class RawRbacGrantEntity {
|
||||
" }";
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static List<String> grantDisplaysOf(final List<RawRbacGrantEntity> roles) {
|
||||
return roles.stream().map(RawRbacGrantEntity::toDisplay).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -272,9 +272,9 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
|
||||
.body("granteeUserName", is(givenNewUser.getName()));
|
||||
assertThat(findAllGrantsOf(givenCurrentUserAsPackageAdmin))
|
||||
.extracting(RbacGrantEntity::toDisplay)
|
||||
.contains("{ grant assumed role " + givenOwnPackageAdminRole.getRoleName() +
|
||||
.contains("{ grant role " + givenOwnPackageAdminRole.getRoleName() +
|
||||
" to user " + givenNewUser.getName() +
|
||||
" by role " + givenRoleToGrant + " }");
|
||||
" by role " + givenRoleToGrant + " and assume }");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -323,7 +323,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
|
||||
.toUser(givenArbitraryUser));
|
||||
assumeGrantExists(
|
||||
givenCurrentUserAsPackageAdmin,
|
||||
"{ grant assumed role %s to user %s by role %s }".formatted(
|
||||
"{ grant role %s to user %s by role %s and assume }".formatted(
|
||||
givenOwnPackageAdminRole.getRoleName(),
|
||||
givenArbitraryUser.getName(),
|
||||
givenCurrentUserAsPackageAdmin.assumedRole));
|
||||
|
@ -1,14 +0,0 @@
|
||||
package net.hostsharing.hsadminng.rbac.rbacgrant;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RbacGrantDisplayExtractor {
|
||||
|
||||
@NotNull
|
||||
public static List<String> grantDisplaysOf(final List<RbacGrantEntity> roles) {
|
||||
return roles.stream().map(RbacGrantEntity::toDisplay).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ class RbacGrantEntityUnitTest {
|
||||
final var display = entity.toDisplay();
|
||||
|
||||
// then
|
||||
assertThat(display).isEqualTo("{ grant assumed role GrantED to user GrantEE by role GrantER }");
|
||||
assertThat(display).isEqualTo("{ grant role GrantED to user GrantEE by role GrantER and assume }");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -41,6 +41,9 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
|
||||
@Autowired
|
||||
RbacGrantRepository rbacGrantRepository;
|
||||
|
||||
@Autowired
|
||||
RawRbacGrantRepository rawRbacGrantRepository;
|
||||
|
||||
@Autowired
|
||||
RbacUserRepository rbacUserRepository;
|
||||
|
||||
@ -68,7 +71,7 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
|
||||
// then
|
||||
exactlyTheseRbacGrantsAreReturned(
|
||||
result,
|
||||
"{ grant assumed role test_package#xxx00.admin to user pac-admin-xxx00@xxx.example.com by role test_customer#xxx.admin }");
|
||||
"{ grant role test_package#xxx00.admin to user pac-admin-xxx00@xxx.example.com by role test_customer#xxx.admin and assume }");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -83,10 +86,10 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
|
||||
// then
|
||||
exactlyTheseRbacGrantsAreReturned(
|
||||
result,
|
||||
"{ grant assumed role test_customer#xxx.admin to user customer-admin@xxx.example.com by role global#global.admin }",
|
||||
"{ grant assumed role test_package#xxx00.admin to user pac-admin-xxx00@xxx.example.com by role test_customer#xxx.admin }",
|
||||
"{ grant assumed role test_package#xxx01.admin to user pac-admin-xxx01@xxx.example.com by role test_customer#xxx.admin }",
|
||||
"{ grant assumed role test_package#xxx02.admin to user pac-admin-xxx02@xxx.example.com by role test_customer#xxx.admin }");
|
||||
"{ grant role test_customer#xxx.admin to user customer-admin@xxx.example.com by role global#global.admin and assume }",
|
||||
"{ grant role test_package#xxx00.admin to user pac-admin-xxx00@xxx.example.com by role test_customer#xxx.admin and assume }",
|
||||
"{ grant role test_package#xxx01.admin to user pac-admin-xxx01@xxx.example.com by role test_customer#xxx.admin and assume }",
|
||||
"{ grant role test_package#xxx02.admin to user pac-admin-xxx02@xxx.example.com by role test_customer#xxx.admin and assume }");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -101,7 +104,7 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
|
||||
// then
|
||||
exactlyTheseRbacGrantsAreReturned(
|
||||
result,
|
||||
"{ grant assumed role test_package#xxx00.admin to user pac-admin-xxx00@xxx.example.com by role test_customer#xxx.admin }");
|
||||
"{ grant role test_package#xxx00.admin to user pac-admin-xxx00@xxx.example.com by role test_customer#xxx.admin and assume }");
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +132,7 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
|
||||
assertThat(rbacGrantRepository.findAll())
|
||||
.extracting(RbacGrantEntity::toDisplay)
|
||||
.contains(
|
||||
"{ grant assumed role test_package#xxx00.admin to user pac-admin-zzz00@zzz.example.com by role test_customer#xxx.admin }");
|
||||
"{ grant role test_package#xxx00.admin to user pac-admin-zzz00@zzz.example.com by role test_customer#xxx.admin and assume }");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -167,7 +170,6 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
|
||||
// finally, we use the new user to make sure, no roles were granted
|
||||
context(given.arbitraryUser.getName(), null);
|
||||
assertThat(rbacGrantRepository.findAll())
|
||||
.extracting(RbacGrantEntity::toDisplay)
|
||||
.hasSize(0);
|
||||
});
|
||||
}
|
||||
@ -255,9 +257,9 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
|
||||
);
|
||||
|
||||
assumeThat(grantAttempt.caughtException()).isNull();
|
||||
assumeThat(rbacGrantRepository.findAll())
|
||||
.extracting(RbacGrantEntity::toDisplay)
|
||||
.contains("{ grant assumed role %s to user %s by role %s }".formatted(
|
||||
assumeThat(rawRbacGrantRepository.findAll())
|
||||
.extracting(RawRbacGrantEntity::toDisplay)
|
||||
.contains("{ grant role %s to user %s by role %s and assume }".formatted(
|
||||
with.grantedRole, with.granteeUserName, with.assumedRole
|
||||
));
|
||||
|
||||
|
@ -2,10 +2,13 @@ package net.hostsharing.hsadminng.rbac.rbacrole;
|
||||
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.Formula;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.data.annotation.Immutable;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Entity
|
||||
@Table(name = "rbacrole_ev")
|
||||
@ -35,4 +38,10 @@ public class RawRbacRoleEntity {
|
||||
|
||||
@Formula("objectTable||'#'||objectIdName||'.'||roleType")
|
||||
private String roleName;
|
||||
|
||||
@NotNull
|
||||
public static List<String> roleNamesOf(@NotNull final List<RawRbacRoleEntity> roles) {
|
||||
return roles.stream().map(RawRbacRoleEntity::getRoleName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
package net.hostsharing.hsadminng.rbac.rbacrole;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RawRbacRoleNameExtractor {
|
||||
|
||||
@NotNull
|
||||
public static List<String> roleNamesOf(@NotNull final List<RawRbacRoleEntity> roles) {
|
||||
return roles.stream().map(RawRbacRoleEntity::getRoleName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package net.hostsharing.hsadminng.rbac.rbacrole;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RbacRoleNameExtractor {
|
||||
|
||||
@NotNull
|
||||
public static List<String> roleNamesOf(@NotNull final List<RbacRoleEntity> roles) {
|
||||
return roles.stream().map(RbacRoleEntity::getRoleName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user