implements REST API DELETE to /api/rbac-grants/{grantedRoleUuid}/{granteeUserUuid}:
This commit is contained in:
@ -60,4 +60,22 @@ public class RbacGrantController implements RbacgrantsApi {
|
||||
return ResponseEntity.created(uri).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<Void> revokeRoleFromUser(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID grantedRoleUuid,
|
||||
final UUID granteeUserUuid) {
|
||||
|
||||
context.setCurrentUser(currentUser);
|
||||
if (assumedRoles != null && !assumedRoles.isBlank()) {
|
||||
context.assumeRoles(assumedRoles);
|
||||
}
|
||||
|
||||
rbacGrantRepository.deleteByRbacGrantId(new RbacGrantId(granteeUserUuid, grantedRoleUuid));
|
||||
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,6 +53,10 @@ public class RbacGrantEntity {
|
||||
@Enumerated(EnumType.STRING)
|
||||
private RbacRoleType grantedRoleType;
|
||||
|
||||
RbacGrantId getRbacGrantId() {
|
||||
return new RbacGrantId(granteeUserUuid, grantedRoleUuid);
|
||||
}
|
||||
|
||||
public String toDisplay() {
|
||||
return "{ grant " + (assumed ? "assumed " : "") +
|
||||
"role " + grantedRoleIdName + " to user " + granteeUserName + " by role " + grantedByRoleIdName + " }";
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.hostsharing.hsadminng.rbac.rbacgrant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -10,6 +11,7 @@ import java.util.UUID;
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RbacGrantId implements Serializable {
|
||||
|
||||
private UUID granteeUserUuid;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.hostsharing.hsadminng.rbac.rbacgrant;
|
||||
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import java.util.List;
|
||||
@ -10,5 +12,11 @@ public interface RbacGrantRepository extends Repository<RbacGrantEntity, RbacGra
|
||||
|
||||
void save(final RbacGrantEntity grant);
|
||||
|
||||
void delete(final RbacGrantEntity grant);
|
||||
@Modifying
|
||||
@Query(value = """
|
||||
delete from RbacGrantEntity as g
|
||||
where g.grantedRoleUuid=:#{#rbacGrantId.grantedRoleUuid}
|
||||
and g.granteeUserUuid=:#{#rbacGrantId.granteeUserUuid}
|
||||
""")
|
||||
void deleteByRbacGrantId(RbacGrantId rbacGrantId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user