sync source code with article
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.hibernate.audit;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("auditorProvider")
|
||||
public class AuditorAwareImpl implements AuditorAware<String> {
|
||||
|
||||
@Override
|
||||
public String getCurrentAuditor() {
|
||||
return Optional.ofNullable(SecurityContextHolder.getContext())
|
||||
.map(e -> e.getAuthentication())
|
||||
.map(Authentication::getName)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,7 +46,7 @@ import com.google.common.base.Preconditions;
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@EnableJpaRepositories(basePackages = { "com.baeldung.persistence" }, transactionManagerRef = "jpaTransactionManager")
|
||||
@EnableJpaAuditing
|
||||
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
|
||||
@PropertySource({ "classpath:persistence-h2.properties" })
|
||||
@ComponentScan({ "com.baeldung.persistence" })
|
||||
public class PersistenceConfig {
|
||||
|
||||
Reference in New Issue
Block a user