-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Muryginds/muryginds
Muryginds
- Loading branch information
Showing
213 changed files
with
3,931 additions
and
4,974 deletions.
There are no files selected for viewing
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
4 changes: 2 additions & 2 deletions
4
...in/java/ru/ylab/annotation/Auditable.java → ...in/java/io/ylab/annotation/Auditable.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
2 changes: 1 addition & 1 deletion
2
...ain/java/ru/ylab/annotation/Loggable.java → ...ain/java/io/ylab/annotation/Loggable.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
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,62 @@ | ||
package io.ylab.aspect; | ||
|
||
import io.ylab.annotation.Auditable; | ||
import io.ylab.dto.response.UserDto; | ||
import io.ylab.entity.AuditionEvent; | ||
import io.ylab.service.AuditionEventService; | ||
import io.ylab.service.UserService; | ||
import io.ylab.utils.CurrentUserUtils; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.AfterReturning; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Aspect | ||
@Component | ||
@RequiredArgsConstructor | ||
public class AuditableAspect { | ||
private final AuditionEventService auditionEventService; | ||
private final UserService userService; | ||
|
||
@Pointcut("execution(io.ylab.dto.response.UserDto io.ylab.service.AccountService.registerUser(..))" + | ||
"|| execution(io.ylab.dto.response.UserDto io.ylab.service.LoginService.authorize(..))") | ||
public void unauthorizedUserMethodPointcut() { | ||
} | ||
|
||
@Pointcut("@annotation(io.ylab.annotation.Auditable) && execution(* *(..))") | ||
public void auditableMethod() { | ||
} | ||
|
||
@AfterReturning("auditableMethod() && !unauthorizedUserMethodPointcut()") | ||
public void auditableMethodAdvice(JoinPoint joinPoint) { | ||
var methodName = joinPoint.getSignature().getName(); | ||
log.info("AUDITING " + methodName); | ||
var type = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(Auditable.class).eventType(); | ||
var user = CurrentUserUtils.getCurrentUser(); | ||
var event = AuditionEvent.builder() | ||
.user(user) | ||
.eventType(type) | ||
.message("Method '%s' was called".formatted(methodName)) | ||
.build(); | ||
auditionEventService.save(event); | ||
} | ||
|
||
@AfterReturning(value = "auditableMethod() && unauthorizedUserMethodPointcut()", returning = "userDto") | ||
public void auditableRegisterUserAdvice(JoinPoint joinPoint, UserDto userDto) { | ||
var methodName = joinPoint.getSignature().getName(); | ||
log.info("AUDITING " + methodName); | ||
var type = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(Auditable.class).eventType(); | ||
var user = userService.getUserById(userDto.getId()); | ||
var event = AuditionEvent.builder() | ||
.user(user) | ||
.eventType(type) | ||
.message("Method '%s' was called".formatted(methodName)) | ||
.build(); | ||
auditionEventService.save(event); | ||
} | ||
} |
8 changes: 5 additions & 3 deletions
8
...n/java/ru/ylab/aspect/LoggableAspect.java → ...n/java/io/ylab/aspect/LoggableAspect.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
22 changes: 22 additions & 0 deletions
22
src/main/java/io/ylab/configuration/ApplicationConfig.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,22 @@ | ||
package io.ylab.configuration; | ||
|
||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; | ||
import org.springframework.core.io.ClassPathResource; | ||
|
||
import java.util.Objects; | ||
|
||
@Configuration | ||
public class ApplicationConfig { | ||
|
||
@Bean | ||
public static PropertySourcesPlaceholderConfigurer yamlPropertiesConfigurer() { | ||
var configurer = new PropertySourcesPlaceholderConfigurer(); | ||
var factoryBean = new YamlPropertiesFactoryBean(); | ||
factoryBean.setResources(new ClassPathResource("application.yaml")); | ||
configurer.setProperties(Objects.requireNonNull(factoryBean.getObject())); | ||
return configurer; | ||
} | ||
} |
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 io.ylab.configuration; | ||
|
||
import io.ylab.configuration.property.DataSourceProperties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.datasource.DriverManagerDataSource; | ||
import org.springframework.jdbc.datasource.init.DataSourceInitializer; | ||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class DatabaseConfig { | ||
private final DataSourceProperties properties; | ||
|
||
@Bean | ||
public DataSource dataSource() { | ||
DriverManagerDataSource dataSource = new DriverManagerDataSource(); | ||
dataSource.setUrl(properties.getUrl()); | ||
dataSource.setUsername(properties.getUsername()); | ||
dataSource.setPassword(properties.getPassword()); | ||
dataSource.setDriverClassName(properties.getDriverClassName()); | ||
return dataSource; | ||
} | ||
|
||
@Bean | ||
public JdbcTemplate jdbcTemplate(DataSource dataSource) { | ||
return new JdbcTemplate(dataSource); | ||
} | ||
|
||
@Bean | ||
public DataSourceInitializer dataSourceInitializer(DataSource dataSource) { | ||
var initializer = new DataSourceInitializer(); | ||
initializer.setDataSource(dataSource); | ||
initializer.setDatabasePopulator(databasePopulator()); | ||
return initializer; | ||
} | ||
|
||
private ResourceDatabasePopulator databasePopulator() { | ||
var populator = new ResourceDatabasePopulator(); | ||
populator.addScript(new ClassPathResource(properties.getInitScript())); | ||
return populator; | ||
} | ||
} |
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,26 @@ | ||
package io.ylab.configuration; | ||
|
||
import io.ylab.configuration.property.MigrationProperties; | ||
import liquibase.integration.spring.SpringLiquibase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class LiquibaseConfig { | ||
private final MigrationProperties migrationProperties; | ||
private final DataSource dataSource; | ||
|
||
@Bean | ||
public SpringLiquibase liquibase() { | ||
SpringLiquibase liquibase = new SpringLiquibase(); | ||
liquibase.setDataSource(dataSource); | ||
liquibase.setChangeLog(migrationProperties.getChangeLog()); | ||
liquibase.setDefaultSchema(migrationProperties.getDefaultSchema()); | ||
liquibase.setLiquibaseSchema(migrationProperties.getLiquibaseSchema()); | ||
return liquibase; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/io/ylab/configuration/MainWebAppInitializer.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,22 @@ | ||
package io.ylab.configuration; | ||
|
||
import org.springframework.lang.NonNull; | ||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; | ||
|
||
public class MainWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { | ||
|
||
@Override | ||
protected @NonNull String[] getServletMappings() { | ||
return new String[]{"/"}; | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getRootConfigClasses() { | ||
return new Class[0]; | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getServletConfigClasses() { | ||
return new Class[] {SecurityConfig.class, WebConfig.class}; | ||
} | ||
} |
Oops, something went wrong.