Skip to content

Commit

Permalink
IKC-409 Data masking policies list
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Belke authored and Piotr Belke committed Sep 25, 2024
1 parent 4d52d98 commit fc53b85
Show file tree
Hide file tree
Showing 49 changed files with 876 additions and 25 deletions.
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();

}
}
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;
}
}
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> {

}
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;
}
}
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum FunctionGroup {
CONSUMER_GROUP,
SCHEMA_REGISTRY,
CLUSTER,
ADMIN
ADMIN,
DATA_MASKING
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public enum SystemFunctionName {
@FieldNameConstants.Include USER_GROUPS_LIST,
@FieldNameConstants.Include USER_GROUP_CREATE,
@FieldNameConstants.Include USER_GROUP_UPDATE,
@FieldNameConstants.Include USER_GROUP_DELETE
@FieldNameConstants.Include USER_GROUP_DELETE,

//data masking
@FieldNameConstants.Include DATA_MASKING_POLICIES,
@FieldNameConstants.Include DATA_MASKING_POLICY_CREATE,
@FieldNameConstants.Include DATA_MASKING_POLICY_DETAILS,
@FieldNameConstants.Include DATA_MASKING_POLICY_UPDATE,
@FieldNameConstants.Include DATA_MASKING_POLICY_DELETE

}
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
}
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;
}
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;
2 changes: 2 additions & 0 deletions kouncil-frontend/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"common-model": "libs/common-model",
"common-servers": "libs/common-servers",
"common-utils": "libs/common-utils",
"feat-breadcrumb": "libs/feat-breadcrumb",
"feat-confirm": "libs/feat-confirm",
"feat-data-masking": "libs/feat-data-masking",
"feat-favourites": "libs/feat-favourites",
"feat-no-data": "libs/feat-no-data",
"feat-notifications": "libs/feat-notifications",
Expand Down
16 changes: 16 additions & 0 deletions kouncil-frontend/apps/kouncil/src/app/app-factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import {
UserGroupService,
UserGroupsService
} from '@app/feat-user-groups';
import {
DataMaskingPoliciesBackendService,
DataMaskingPoliciesDemoService,
DataMaskingPoliciesService
} from '@app/feat-data-masking';

export function topicsServiceFactory(http: HttpClient): TopicsService {
switch (environment.backend) {
Expand Down Expand Up @@ -153,3 +158,14 @@ export function userGroupServiceFactory(http: HttpClient): UserGroupService {
return new UserGroupDemoService();
}
}

export function dataMaskingPoliciesServiceFactory(http: HttpClient): DataMaskingPoliciesService {
switch (environment.backend) {
case Backend.SERVER: {
return new DataMaskingPoliciesBackendService(http);
}
case Backend.DEMO:
default:
return new DataMaskingPoliciesDemoService();
}
}
14 changes: 11 additions & 3 deletions kouncil-frontend/apps/kouncil/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {MatDividerModule} from '@angular/material/divider';
import {MatIconModule} from '@angular/material/icon';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';
import {BreadcrumbComponent} from './breadcrumb/breadcrumb.component';
import {MatDialogModule} from '@angular/material/dialog';
import {MatSnackBarModule} from '@angular/material/snack-bar';
import {BrokerComponent} from './broker/broker.component';
Expand Down Expand Up @@ -63,6 +62,7 @@ import {FeatTopicsModule, TopicsService} from '@app/feat-topics';
import {
clusterServiceFactory,
clustersServiceFactory,
dataMaskingPoliciesServiceFactory,
functionsServiceFactory,
resendServiceFactory,
schemaRegistryServiceFactory,
Expand Down Expand Up @@ -115,6 +115,8 @@ import {
} from '@app/feat-user-groups';
import {RX_STOMP_CONFIG} from './rx-stomp.config';
import {FeatNotificationsModule, RxStompService} from '@app/feat-notifications';
import {DataMaskingPoliciesService, FeatDataMaskingModule} from '@app/feat-data-masking';
import {FeatBreadcrumbModule} from '@app/feat-breadcrumb';

export const BASE_URL = new InjectionToken('BASE_URL');

Expand Down Expand Up @@ -169,7 +171,6 @@ export function authServiceFactory(http: HttpClient, baseUrl: string): AuthServi
ConsumerGroupComponent,
TopicPartitionsComponent,
TopicPaginationComponent,
BreadcrumbComponent,
BrokerComponent,
MessageViewComponent,
FileSizePipe,
Expand Down Expand Up @@ -232,7 +233,9 @@ export function authServiceFactory(http: HttpClient, baseUrl: string): AuthServi
FeatTopicFormModule,
FeatClustersModule,
FeatUserGroupsModule,
FeatNotificationsModule
FeatNotificationsModule,
FeatDataMaskingModule,
FeatBreadcrumbModule
],
providers: [
{
Expand Down Expand Up @@ -339,6 +342,11 @@ export function authServiceFactory(http: HttpClient, baseUrl: string): AuthServi
provide: UserGroupService,
useFactory: userGroupServiceFactory,
deps: [HttpClient]
},
{
provide: DataMaskingPoliciesService,
useFactory: dataMaskingPoliciesServiceFactory,
deps: [HttpClient]
}
],
bootstrap: [AppComponent]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
ClustersComponent
} from '@app/feat-clusters';
import {UserGroupsComponent, UserGroupsFunctionsMatrixComponent} from '@app/feat-user-groups';
import {DataMaskingPoliciesComponent} from '@app/feat-data-masking';

@Injectable()
export class ReloadingRouterStrategy extends RouteReuseStrategy {
Expand Down Expand Up @@ -202,6 +203,14 @@ const routes: Routes = [
data: {
roles: [SystemFunctionName.USER_GROUPS]
}
},
{
path: 'data-masking-policies',
component: DataMaskingPoliciesComponent,
canActivate: [AuthGuard],
data: {
roles: [SystemFunctionName.DATA_MASKING_POLICIES]
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ import {SidebarState} from './sidebar-state';
<div
*ngIf="(isAuthenticated$ | async)
&& authService.canAccess([SystemFunctionName.CLUSTER_LIST, SystemFunctionName.USER_GROUPS_LIST, SystemFunctionName.USER_GROUPS])"
&& authService.canAccess([
SystemFunctionName.CLUSTER_LIST,
SystemFunctionName.USER_GROUPS_LIST,
SystemFunctionName.USER_GROUPS,
SystemFunctionName.DATA_MASKING_POLICIES
])"
class="menu-grouping-separator"></div>
<app-sidebar-menu-item [label]="'Clusters'" [icon]="'storage'" [routeLink]="'/clusters'"
Expand All @@ -51,6 +56,11 @@ import {SidebarState} from './sidebar-state';
*ngIf="(isAuthenticated$ | async) && authService.canAccess([SystemFunctionName.USER_GROUPS])">
</app-sidebar-menu-item>
<app-sidebar-menu-item [label]="'Data masking policies'" [icon]="'policy'"
[routeLink]="'/data-masking-policies'"
*ngIf="(isAuthenticated$ | async) && authService.canAccess([SystemFunctionName.DATA_MASKING_POLICIES])">
</app-sidebar-menu-item>
<div class="toggle-sidebar-container">
<button mat-icon-button class="toggle-sidebar-btn" (click)="changeState()">
<mat-icon class="material-symbols-outlined toggle-sidebar-btn-icon">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export enum SystemFunctionName {
CLUSTER_CREATE = 'CLUSTER_CREATE',
CLUSTER_UPDATE = 'CLUSTER_UPDATE',
CLUSTER_DETAILS = 'CLUSTER_DETAILS',
CLUSTER_DELETE = 'CLUSTER_DELETE'
CLUSTER_DELETE = 'CLUSTER_DELETE',

DATA_MASKING_POLICIES = 'DATA_MASKING_POLICIES',
DATA_MASKING_POLICY_CREATE = 'DATA_MASKING_POLICY_CREATE',
DATA_MASKING_POLICY_DETAILS = 'DATA_MASKING_POLICY_DETAILS',
DATA_MASKING_POLICY_UPDATE = 'DATA_MASKING_POLICY_UPDATE',
DATA_MASKING_POLICY_DELETE = 'DATA_MASKING_POLICY_DELETE'

}
Loading

0 comments on commit fc53b85

Please sign in to comment.