org.springframework.data.domain.AuditorAware Java Examples

The following examples show how to use org.springframework.data.domain.AuditorAware. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PostServiceApplication.java    From spring-microservice-sample with GNU General Public License v3.0 6 votes vote down vote up
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public AuditorAware<Username> auditorAware() {

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    log.debug("current authentication:" + authentication);

    if (authentication == null || !authentication.isAuthenticated()) {
        return () -> Optional.<Username>empty();
    }

    return () -> Optional.of(
        Username.builder()
            .username(((UserDetails) authentication.getPrincipal()).getUsername())
            .build()
    );

}
 
Example #2
Source File: JPAConfig.java    From ElementVueSpringbootCodeTemplate with Apache License 2.0 6 votes vote down vote up
@Bean
public AuditorAware<User> auditorAware() {
	return new AuditorAware<User>() {

		@Override
		public User getCurrentAuditor() {
			//System.out.println("\n\nJPAConfig.auditorAware().new AuditorAware() {...}.getCurrentAuditor()");

			// 后台任务,不需要登录
			// TODO 后台创建的生活,可能就会为空
			if (JPAThreadLocal.background()){
				return null;
			}
			else {
				return UserUtil.getUser();
			}
		}
	};
}
 
Example #3
Source File: RepositoryApplicationConfiguration.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@link JpaDeploymentManagement} bean.
 *
 * @return a new {@link DeploymentManagement}
 */
@Bean
@ConditionalOnMissingBean
DeploymentManagement deploymentManagement(final EntityManager entityManager,
        final ActionRepository actionRepository, final DistributionSetRepository distributionSetRepository,
        final TargetRepository targetRepository, final ActionStatusRepository actionStatusRepository,
        final AuditorAware<String> auditorProvider, final EventPublisherHolder eventPublisherHolder,
        final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
        final PlatformTransactionManager txManager,
        final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
        final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware,
        final JpaProperties properties, final RepositoryProperties repositoryProperties) {
    return new JpaDeploymentManagement(entityManager, actionRepository, distributionSetRepository, targetRepository,
            actionStatusRepository, auditorProvider, eventPublisherHolder, afterCommit, virtualPropertyReplacer,
            txManager, tenantConfigurationManagement, quotaManagement, systemSecurityContext, tenantAware,
            properties.getDatabase(), repositoryProperties);
}
 
Example #4
Source File: JpaSoftwareModuleManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
public JpaSoftwareModuleManagement(final EntityManager entityManager,
        final DistributionSetRepository distributionSetRepository,
        final SoftwareModuleRepository softwareModuleRepository,
        final SoftwareModuleMetadataRepository softwareModuleMetadataRepository,
        final SoftwareModuleTypeRepository softwareModuleTypeRepository,
        final NoCountPagingRepository criteriaNoCountDao, final AuditorAware<String> auditorProvider,
        final ArtifactManagement artifactManagement, final QuotaManagement quotaManagement,
        final VirtualPropertyReplacer virtualPropertyReplacer, final Database database) {
    this.entityManager = entityManager;
    this.distributionSetRepository = distributionSetRepository;
    this.softwareModuleRepository = softwareModuleRepository;
    this.softwareModuleMetadataRepository = softwareModuleMetadataRepository;
    this.softwareModuleTypeRepository = softwareModuleTypeRepository;
    this.criteriaNoCountDao = criteriaNoCountDao;
    this.auditorProvider = auditorProvider;
    this.artifactManagement = artifactManagement;
    this.quotaManagement = quotaManagement;
    this.virtualPropertyReplacer = virtualPropertyReplacer;
    this.database = database;
}
 
Example #5
Source File: AuditSecurityConfiguration.java    From spring-security-samples with MIT License 5 votes vote down vote up
@Bean
AuditorAware<Author> auditorAware(AuthorRepository repo) {
	// Lookup Author instance corresponding to logged in user
	return () -> Optional.ofNullable(SecurityContextHolder.getContext())
			.map(SecurityContext::getAuthentication)
			.filter(Authentication::isAuthenticated)
			.map(Authentication::getName)
			.flatMap(repo::findByName);
}
 
Example #6
Source File: MethodSecurityApplication.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
AuditorAware<String> auditor() {
	return () -> {
		SecurityContext context = SecurityContextHolder.getContext();
		Authentication authentication = context.getAuthentication();
		if (null != authentication) {
			return Optional.ofNullable(authentication.getName());
		}
		return Optional.empty();
	};
}
 
Example #7
Source File: DemoApplication.java    From spring-webmvc-jwt-sample with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public AuditorAware<User> auditor() {
    return () -> Optional.ofNullable(SecurityContextHolder.getContext())
        .map(SecurityContext::getAuthentication)
        .filter(Authentication::isAuthenticated)
        .map(Authentication::getPrincipal)
        .map(User.class::cast);
}
 
Example #8
Source File: SecurityConfig.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@Bean
public AuditorAware<String> folderAuditor() {
	return new AuditorAware<String>() {
		@Override
		public Optional<String> getCurrentAuditor() {
			return Optional.ofNullable(SecurityContextHolder.getContext())
					.map(SecurityContext::getAuthentication)
					.filter(Authentication::isAuthenticated)
					.map(Authentication::getPrincipal)
					.map((u) -> ((User)u).getUsername());
		}
	};
}
 
Example #9
Source File: SpringletsDataJpaAuthenticationAuditorConfigurationTest.java    From springlets with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link io.springlets.data.jpa.config.SpringletsDataJpaAuthenticationAuditorConfiguration#authenticationAuditorAware()}.
 */
@Test
public void testAuthenticationAuditorAware() {
  // Setup

  // Exercise
  AuditorAware<String> authenticationAuditorAware = configuration.auditorProvider();

  // Verify
  assertThat(authenticationAuditorAware).isNotNull()
      .isInstanceOf(AuthenticationAuditorAware.class);
}
 
Example #10
Source File: SavedSnapshotService.java    From find with MIT License 5 votes vote down vote up
@Autowired
public SavedSnapshotService(final SavedSearchRepository<SavedSnapshot, SavedSnapshot.Builder> savedSnapshotRepository,
                            final SharedToUserRepository sharedToUserRepository,
                            final SharedToEveryoneRepository sharedToEveryoneRepository,
                            final AuditorAware<UserEntity> userEntityAuditorAware,
                            final TagNameFactory tagNameFactory,
                            final IdolDocumentsService documentsService,
                            final FieldTextParser fieldTextParser,
                            final ObjectFactory<IdolQueryRestrictionsBuilder> queryRestrictionsBuilderFactory) {
    super(savedSnapshotRepository, sharedToUserRepository, sharedToEveryoneRepository, userEntityAuditorAware, tagNameFactory, SavedSnapshot.class);
    this.documentsService = documentsService;
    this.fieldTextParser = fieldTextParser;
    this.queryRestrictionsBuilderFactory = queryRestrictionsBuilderFactory;
}
 
Example #11
Source File: SavedQueryService.java    From find with MIT License 5 votes vote down vote up
@Autowired
public SavedQueryService(@SuppressWarnings("TypeMayBeWeakened") final SavedQueryRepository savedQueryRepository,
                         final SharedToUserRepository sharedToUserRepository,
                         final SharedToEveryoneRepository sharedToEveryoneRepository,
                         final AuditorAware<UserEntity> userEntityAuditorAware,
                         final TagNameFactory tagNameFactory) {
    super(savedQueryRepository, sharedToUserRepository, sharedToEveryoneRepository, userEntityAuditorAware, tagNameFactory, SavedQuery.class);
}
 
Example #12
Source File: AbstractSavedSearchService.java    From find with MIT License 5 votes vote down vote up
protected AbstractSavedSearchService(final SavedSearchRepository<T, B> crudRepository,
                                     final SharedToUserRepository sharedToUserRepository,
                                     final SharedToEveryoneRepository sharedToEveryoneRepository,
                                     final AuditorAware<UserEntity> userEntityAuditorAware,
                                     final TagNameFactory tagNameFactory,
                                     final Class<T> type) {
    this.crudRepository = crudRepository;
    this.sharedToUserRepository = sharedToUserRepository;
    this.sharedToEveryoneRepository = sharedToEveryoneRepository;
    this.userEntityAuditorAware = userEntityAuditorAware;
    this.tagNameFactory = tagNameFactory;
    this.type = type;
}
 
Example #13
Source File: RepositoryApplicationConfiguration.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@link JpaSoftwareModuleManagement} bean.
 *
 * @return a new {@link SoftwareModuleManagement}
 */
@Bean
@ConditionalOnMissingBean
SoftwareModuleManagement softwareModuleManagement(final EntityManager entityManager,
        final DistributionSetRepository distributionSetRepository,
        final SoftwareModuleRepository softwareModuleRepository,
        final SoftwareModuleMetadataRepository softwareModuleMetadataRepository,
        final SoftwareModuleTypeRepository softwareModuleTypeRepository,
        final NoCountPagingRepository criteriaNoCountDao, final AuditorAware<String> auditorProvider,
        final ArtifactManagement artifactManagement, final QuotaManagement quotaManagement,
        final VirtualPropertyReplacer virtualPropertyReplacer, final JpaProperties properties) {
    return new JpaSoftwareModuleManagement(entityManager, distributionSetRepository, softwareModuleRepository,
            softwareModuleMetadataRepository, softwareModuleTypeRepository, criteriaNoCountDao, auditorProvider,
            artifactManagement, quotaManagement, virtualPropertyReplacer, properties.getDatabase());
}
 
Example #14
Source File: JpaDeploymentManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
protected JpaDeploymentManagement(final EntityManager entityManager, final ActionRepository actionRepository,
        final DistributionSetRepository distributionSetRepository, final TargetRepository targetRepository,
        final ActionStatusRepository actionStatusRepository, final AuditorAware<String> auditorProvider,
        final EventPublisherHolder eventPublisherHolder, final AfterTransactionCommitExecutor afterCommit,
        final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
        final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
        final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware, final Database database,
        final RepositoryProperties repositoryProperties) {
    super(actionRepository, repositoryProperties);
    this.entityManager = entityManager;
    this.distributionSetRepository = distributionSetRepository;
    this.targetRepository = targetRepository;
    this.actionStatusRepository = actionStatusRepository;
    this.auditorProvider = auditorProvider;
    this.virtualPropertyReplacer = virtualPropertyReplacer;
    this.txManager = txManager;
    onlineDsAssignmentStrategy = new OnlineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisherHolder,
            actionRepository, actionStatusRepository, quotaManagement, this::isMultiAssignmentsEnabled);
    offlineDsAssignmentStrategy = new OfflineDsAssignmentStrategy(targetRepository, afterCommit,
            eventPublisherHolder, actionRepository, actionStatusRepository, quotaManagement,
            this::isMultiAssignmentsEnabled);
    this.tenantConfigurationManagement = tenantConfigurationManagement;
    this.quotaManagement = quotaManagement;
    this.systemSecurityContext = systemSecurityContext;
    this.tenantAware = tenantAware;
    this.database = database;
    retryTemplate = createRetryTemplate();
}
 
Example #15
Source File: JiwhizBlogRepositoryTestApplication.java    From JiwhizBlogWeb with Apache License 2.0 5 votes vote down vote up
@Bean
public AuditorAware<String> auditorAware() {
    return new AuditorAware<String>() {
        public String getCurrentAuditor() {
            return TEST_AUDITOR;
        }
    };
}
 
Example #16
Source File: JiwhizBlogWebApplication.java    From JiwhizBlogWeb with Apache License 2.0 5 votes vote down vote up
@Bean
public AuditorAware<String> auditorAware() {
    return new AuditorAware<String>() {
        public String getCurrentAuditor() {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

            if (authentication == null || !authentication.isAuthenticated()) {
              return null;
            }

            return authentication.getName();
        }
    };
}
 
Example #17
Source File: AuditingIT.java    From sdn-rx with Apache License 2.0 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorProvider() {
	return () -> Optional.of("A user");
}
 
Example #18
Source File: ReactiveAuditingIT.java    From sdn-rx with Apache License 2.0 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorProvider() {
	return () -> Optional.of("A user");
}
 
Example #19
Source File: AuditConfiguration.java    From code-examples with MIT License 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorAware() {
    return new EntityAuditorAware();
}
 
Example #20
Source File: AuditingConfig.java    From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 4 votes vote down vote up
@Bean
public AuditorAware<Long> auditorProvider(){
    return new SpringSecurityAuditAwareImpl();
}
 
Example #21
Source File: ShiroBaseConfigure.java    From ueboot with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * 增加审计记录,根据登录用户补充创建人、修改人
 */
@Bean
@ConditionalOnMissingBean
public AuditorAware auditorAware() {
    return new JpaAuditingAwareImpl();
}
 
Example #22
Source File: JpaAuditConfig.java    From production-ready-microservices-starter with MIT License 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example #23
Source File: JpaAuditConfig.java    From production-ready-microservices-starter with MIT License 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example #24
Source File: JpaAuditConfig.java    From production-ready-microservices-starter with MIT License 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example #25
Source File: JpaAuditConfig.java    From production-ready-microservices-starter with MIT License 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example #26
Source File: JpaAuditConfig.java    From production-ready-microservices-starter with MIT License 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example #27
Source File: EntityMetaObjectHandler.java    From albedo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public EntityMetaObjectHandler(AuditorAware auditorAware) {
	Assert.isTrue(auditorAware != null, "auditorAware is not defined");
	this.auditorAware = auditorAware;
}
 
Example #28
Source File: ArangoTestConfiguration.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Bean
public AuditorAware<Person> auditorProvider() {
	return new AuditorProvider();
}
 
Example #29
Source File: AuthBeans.java    From zhcet-web with Apache License 2.0 4 votes vote down vote up
@Bean
AuditorAware<String> auditorAware() {
    return new Auditor();
}
 
Example #30
Source File: JpaConfig.java    From galeb with Apache License 2.0 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorAware() {
    return new SpringSecurityAuditorAware();
}