-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piotr Belke
authored and
Piotr Belke
committed
Sep 25, 2024
1 parent
4d52d98
commit fc53b85
Showing
49 changed files
with
876 additions
and
25 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/PoliciesController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.consdata.kouncil.datamasking; | ||
|
||
import com.consdata.kouncil.datamasking.dto.PolicyDto; | ||
import com.consdata.kouncil.model.admin.SystemFunctionName.Fields; | ||
import java.util.List; | ||
import javax.annotation.security.RolesAllowed; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@AllArgsConstructor | ||
public class PoliciesController { | ||
|
||
private final PoliciesService policyService; | ||
|
||
@RolesAllowed({Fields.DATA_MASKING_POLICIES}) | ||
@GetMapping(path = "/api/policies") | ||
public List<PolicyDto> getPolicies() { | ||
return policyService.getPolicies(); | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/PoliciesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.consdata.kouncil.datamasking; | ||
|
||
import com.consdata.kouncil.datamasking.converter.PolicyDtoConverter; | ||
import com.consdata.kouncil.datamasking.dto.PolicyDto; | ||
import com.consdata.kouncil.model.datamasking.Policy; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
@AllArgsConstructor | ||
public class PoliciesService { | ||
|
||
private final PolicyRepository policyRepository; | ||
|
||
public List<PolicyDto> getPolicies(){ | ||
Iterable<Policy> all = policyRepository.findAll(); | ||
List<PolicyDto> policies = new ArrayList<>(); | ||
all.forEach(policy -> policies.add(PolicyDtoConverter.convertToDto(policy))); | ||
return policies; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/PolicyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.consdata.kouncil.datamasking; | ||
|
||
import com.consdata.kouncil.model.datamasking.Policy; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface PolicyRepository extends CrudRepository<Policy, Long> { | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...-backend/src/main/java/com/consdata/kouncil/datamasking/converter/PolicyDtoConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.consdata.kouncil.datamasking.converter; | ||
|
||
import com.consdata.kouncil.datamasking.dto.PolicyDto; | ||
import com.consdata.kouncil.model.datamasking.Policy; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.beans.BeanUtils; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class PolicyDtoConverter { | ||
|
||
public static PolicyDto convertToDto(Policy policy) { | ||
PolicyDto policyDto = new PolicyDto(); | ||
BeanUtils.copyProperties(policy, policyDto); | ||
return policyDto; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.consdata.kouncil.datamasking.dto; | ||
|
||
import com.consdata.kouncil.model.datamasking.MaskingType; | ||
import java.util.Set; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class PolicyDto { | ||
|
||
private Long id; | ||
private String name; | ||
private MaskingType type; | ||
private Set<String> fields; | ||
private Set<String> resources; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ public enum FunctionGroup { | |
CONSUMER_GROUP, | ||
SCHEMA_REGISTRY, | ||
CLUSTER, | ||
ADMIN | ||
ADMIN, | ||
DATA_MASKING | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/MaskingType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.consdata.kouncil.model.datamasking; | ||
|
||
public enum MaskingType { | ||
|
||
ALL, | ||
FIRST_5, | ||
LAST_5 | ||
} |
48 changes: 48 additions & 0 deletions
48
kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/Policy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.consdata.kouncil.model.datamasking; | ||
|
||
import java.util.Set; | ||
import javax.persistence.CollectionTable; | ||
import javax.persistence.Column; | ||
import javax.persistence.ElementCollection; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.SequenceGenerator; | ||
import javax.persistence.Table; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Table(name = "POLICY") | ||
@Getter | ||
@Setter | ||
public class Policy { | ||
|
||
@Id | ||
@Column(name = "ID") | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_POLICY_GEN") | ||
@SequenceGenerator(name = "SEQ_POLICY_GEN", sequenceName = "SEQ_POLICY", initialValue = 1, allocationSize = 1) | ||
private Long id; | ||
|
||
@Column(name = "NAME") | ||
private String name; | ||
|
||
@Column(name = "MASKING_TYPE") | ||
@Enumerated(EnumType.STRING) | ||
private MaskingType type; | ||
|
||
@ElementCollection | ||
@CollectionTable(name = "POLICY_FIELDS", joinColumns = @JoinColumn(name = "POLICY_ID")) | ||
@Column(name = "FIELD") | ||
private Set<String> fields; | ||
|
||
|
||
@ElementCollection | ||
@CollectionTable(name = "POLICY_RESOURCES", joinColumns = @JoinColumn(name = "POLICY_ID")) | ||
@Column(name = "RESOURCES") | ||
private Set<String> resources; | ||
} |
35 changes: 35 additions & 0 deletions
35
kouncil-backend/src/main/resources/db/migration/V7__data_masking.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
create table policy | ||
( | ||
id bigint not null primary key, | ||
name varchar(255), | ||
masking_type varchar(255) | ||
); | ||
create table policy_fields | ||
( | ||
policy_id bigint not null | ||
constraint fkq4ltt72s1qqgpolry1fnmy67b references policy, | ||
field varchar(255) | ||
); | ||
|
||
create table policy_resources | ||
( | ||
policy_id bigint not null | ||
constraint fkk7ao2gxpd7peapqwu27wj9dng references policy, | ||
resources varchar(255) | ||
); | ||
|
||
CREATE SEQUENCE SEQ_POLICY MINVALUE 1 START WITH 1 INCREMENT BY 1 CACHE 10; | ||
|
||
insert into system_function(id, name, label, function_group) | ||
VALUES (nextval('SEQ_SYSTEM_FUNCTION'), 'DATA_MASKING_POLICIES', 'Policies list', 'DATA_MASKING'), | ||
(nextval('SEQ_SYSTEM_FUNCTION'), 'DATA_MASKING_POLICY_CREATE', 'Create new policy', | ||
'DATA_MASKING'), | ||
(nextval('SEQ_SYSTEM_FUNCTION'), 'DATA_MASKING_POLICY_DETAILS', 'View policy details', | ||
'DATA_MASKING'), | ||
(nextval('SEQ_SYSTEM_FUNCTION'), 'DATA_MASKING_POLICY_UPDATE', 'Update policy', | ||
'DATA_MASKING'), | ||
(nextval('SEQ_SYSTEM_FUNCTION'), 'DATA_MASKING_POLICY_DELETE', 'Delete policy', | ||
'DATA_MASKING') | ||
; | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.