Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main service #1

Merged
merged 53 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
bdf8676
Added env variables for sensitive data
ReallyWeirdCat Nov 22, 2024
eaf69f0
Removed retarded comment
ReallyWeirdCat Nov 22, 2024
7236bba
new db
maxdo1511 Nov 23, 2024
a82d977
Merge remote-tracking branch 'origin/MainService' into MainService
maxdo1511 Nov 23, 2024
ff2cb2f
fix db
maxdo1511 Nov 23, 2024
1a44188
add permissions and fix db
maxdo1511 Nov 23, 2024
8b44384
Event implemented
ReallyWeirdCat Nov 23, 2024
64d99fb
University implemented
ReallyWeirdCat Nov 23, 2024
ede2c90
Institute implemented
ReallyWeirdCat Nov 23, 2024
16f5cfb
user service modify
maxdo1511 Nov 23, 2024
33feba0
Studygroup, studygroupevent, major, faculty implemented
ReallyWeirdCat Nov 23, 2024
6d27924
REST conventions
maxdo1511 Nov 23, 2024
19cb4a2
Fixed some stuff in UserAuthController and UserController
ReallyWeirdCat Nov 23, 2024
237808a
add group service, controller and repo
maxdo1511 Nov 23, 2024
b6f446e
groups
maxdo1511 Nov 23, 2024
61b0969
Partial implementation of getInstituteInfoResponse + service & contro…
ReallyWeirdCat Nov 23, 2024
c3e176e
group service
maxdo1511 Nov 23, 2024
0bb8c45
getInstituteInfo method implemented
ReallyWeirdCat Nov 23, 2024
79b4f5f
getcourses request
ReallyWeirdCat Nov 24, 2024
30a68d4
fix
maxdo1511 Nov 24, 2024
c45721f
todo
maxdo1511 Nov 24, 2024
19c9627
Attach/detach user from course methods
ReallyWeirdCat Nov 24, 2024
23df27f
Course todo completed
ReallyWeirdCat Nov 24, 2024
9a2811f
course learning resource
maxdo1511 Nov 24, 2024
18a6d7a
Made controller use models instead of path variables in post/delete m…
ReallyWeirdCat Nov 24, 2024
f531055
audit is the best
maxdo1511 Nov 24, 2024
f665b69
Merge branch 'main' of github.com:EspadaKomanda/IPTIP1CHack into Main…
ReallyWeirdCat Nov 24, 2024
9344b55
Update maven.yml
ReallyWeirdCat Nov 24, 2024
7b49374
Update maven.yml
ReallyWeirdCat Nov 24, 2024
b8469d8
Update maven.yml
ReallyWeirdCat Nov 24, 2024
5f0e69a
Update maven.yml
ReallyWeirdCat Nov 24, 2024
bd3652f
Update maven.yml
ReallyWeirdCat Nov 24, 2024
6c38ce8
Potential workflow fix
ReallyWeirdCat Nov 24, 2024
e40c68a
Disabled updating dependency graph
ReallyWeirdCat Nov 24, 2024
af59a7d
study groups and course learning resource
maxdo1511 Nov 24, 2024
7e9db71
fix table_helper_service
maxdo1511 Nov 25, 2024
446fc62
fix controller dtos
maxdo1511 Nov 25, 2024
733891e
add course resources
maxdo1511 Nov 25, 2024
0602841
universities institutes majors and faculties + resources
maxdo1511 Nov 25, 2024
04b55ed
fix courseLearning requests
maxdo1511 Nov 25, 2024
004d770
StudyGroupEventController related stuff
ReallyWeirdCat Nov 25, 2024
7b12db8
Merge remote-tracking branch 'refs/remotes/origin/MainService' into M…
ReallyWeirdCat Nov 25, 2024
9b2fb6b
ForbiddenException added
maxdo1511 Nov 25, 2024
ae7bf17
fix
maxdo1511 Nov 25, 2024
b8c29c0
(Partial) EventController
ReallyWeirdCat Nov 25, 2024
a00aef5
ModifyEvent method
ReallyWeirdCat Nov 25, 2024
76362e8
Delete method for eventcontroller
ReallyWeirdCat Nov 25, 2024
f9be4f3
Event controller complete
ReallyWeirdCat Nov 25, 2024
2018062
todo specification
ReallyWeirdCat Nov 25, 2024
8a27607
user courses
maxdo1511 Nov 25, 2024
9a1b158
fix for method in eventcontroller and repository
ReallyWeirdCat Nov 26, 2024
a41a4af
Merge remote-tracking branch 'refs/remotes/origin/MainService' into M…
ReallyWeirdCat Nov 26, 2024
e858352
fix
maxdo1511 Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
working-directory: MainService
run: mvn -B package -DskipTests

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
#- name: Update dependency graph
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
# with:
# working-directory: MainService
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package ru.espada.ep.iptip.audit;

import jakarta.persistence.Table;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import org.aspectj.lang.annotation.Pointcut;

import java.lang.reflect.Field;

@Aspect
@Component
public class AuditAspect {

private AuditService auditService;

// Определяем точку соединения для всех методов save и delete в репозиториях
@Pointcut("execution(* org.springframework.data.repository.CrudRepository+.save(..)) || execution(* org.springframework.data.repository.CrudRepository+.delete(..))")
public void repositoryMethods() {}

@Before("repositoryMethods()")
public void logBeforeRepositoryMethod(JoinPoint joinPoint) {
Object entity = joinPoint.getArgs()[0];
if (entity instanceof Auditable auditableEntity) {
String methodName = joinPoint.getSignature().getName();
if (methodName.equals("delete")) {
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = userDetails.getUsername();
auditService.logDelete(auditableEntity, username);
}
}
}

@After("repositoryMethods()")
public void logAfterRepositoryMethod(JoinPoint joinPoint) {
Object entity = joinPoint.getArgs()[0];
if (entity instanceof Auditable auditableEntity) {
String methodName = joinPoint.getSignature().getName();
if (methodName.equals("save")) {
auditService.logSave(auditableEntity);
}
}
}

@Autowired
public void setAuditService(AuditService auditService) {
this.auditService = auditService;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ru.espada.ep.iptip.audit;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import ru.espada.ep.iptip.audit.entity.AuditEntity;

import java.util.List;

@RestController
@RequestMapping("/audit")
@SecurityRequirement(name = "JWT")
public class AuditController {


private AuditService auditService;

@GetMapping("/{page}")
@PreAuthorize("hasPermission(null, 'audit.view')")
public List<AuditEntity> getAudits(@PathVariable int page) {
return auditService.getAudits(page);
}

@Autowired
public void setAuditServiceImpl(AuditService auditService) {
this.auditService = auditService;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.espada.ep.iptip.audit;

import ru.espada.ep.iptip.audit.entity.AuditEntity;

import java.util.List;

public interface AuditService {
void logSave(Auditable entity);

void logDelete(Auditable auditableEntity, String username);

List<AuditEntity> getAudits(int page);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package ru.espada.ep.iptip.audit;

import jakarta.persistence.Table;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import ru.espada.ep.iptip.audit.entity.AuditEntity;
import ru.espada.ep.iptip.audit.entity.AuditRepository;

import java.lang.reflect.Field;
import java.util.List;

@Service
public class AuditServiceImpl implements AuditService {

private AuditRepository auditRepository;
@Value("${audit.page-size:10}")
private int pageSize;

@Override
@Async
public void logSave(Auditable auditableEntity) {
Table table = auditableEntity.getClass().getAnnotation(Table.class);

try {
Field idField = auditableEntity.getClass().getDeclaredField("id");
idField.setAccessible(true);
Object id = null;
try {
id = idField.get(auditableEntity);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}

String operation = "UPDATE";
if (!auditRepository.existsByEntityId((Long) id)) {
operation = "CREATE";
}

AuditEntity auditEntity = AuditEntity.builder()
.entityId((Long) id)
.inTable(table.name())
.event(operation)
.who(auditableEntity.getModifiedBy())
.time(auditableEntity.getModifiedAt())
.build();

auditRepository.save(auditEntity);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}

@Override
@Async
public void logDelete(Auditable auditableEntity, String username) {
Table table = auditableEntity.getClass().getAnnotation(Table.class);
try {
Field idField = auditableEntity.getClass().getDeclaredField("id");
idField.setAccessible(true);
Object id = null;
try {
id = idField.get(auditableEntity);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}

String operation = "DELETE";

AuditEntity auditEntity = AuditEntity.builder()
.entityId((Long) id)
.inTable(table.name())
.event(operation)
.who(auditableEntity.getModifiedBy())
.time(auditableEntity.getModifiedAt())
.build();

auditRepository.save(auditEntity);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}

@Override
public List<AuditEntity> getAudits(int page) {
Pageable pageable = PageRequest.of(page, pageSize);
return auditRepository.findAll(pageable).toList();
}

@Autowired
public void setAuditRepository(AuditRepository auditRepository) {
this.auditRepository = auditRepository;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ru.espada.ep.iptip.audit.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import ru.espada.ep.iptip.user.permission.annotation.Permission;

import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Table(name = "t_audit")
@Permission(children = {}, value = "audit", isStart = true)
public class AuditEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String inTable;
private Long entityId;
private String event;
private String who;
private Date time;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.espada.ep.iptip.audit.entity;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AuditRepository extends JpaRepository<AuditEntity, Long> {
boolean existsByEntityId(Long id);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.espada.ep.iptip.s3;
package ru.espada.ep.iptip.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand Down
Loading