Java Code Examples for org.springframework.data.domain.AuditorAware

The following examples show how to use org.springframework.data.domain.AuditorAware. These examples are extracted from open source projects. 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
@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
@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
/**
 * {@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
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
@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 Project: Spring   Source File: MethodSecurityApplication.java    License: 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
@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 Project: spring-content   Source File: SecurityConfig.java    License: 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
/**
 * 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 Project: find   Source File: SavedSnapshotService.java    License: 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 Project: find   Source File: SavedQueryService.java    License: 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 Project: find   Source File: AbstractSavedSearchService.java    License: 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
/**
 * {@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 Project: hawkbit   Source File: JpaDeploymentManagement.java    License: 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
@Bean
public AuditorAware<String> auditorAware() {
    return new AuditorAware<String>() {
        public String getCurrentAuditor() {
            return TEST_AUDITOR;
        }
    };
}
 
Example 16
Source Project: JiwhizBlogWeb   Source File: JiwhizBlogWebApplication.java    License: 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 Project: sdn-rx   Source File: AuditingIT.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorProvider() {
	return () -> Optional.of("A user");
}
 
Example 18
Source Project: sdn-rx   Source File: ReactiveAuditingIT.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorProvider() {
	return () -> Optional.of("A user");
}
 
Example 19
Source Project: code-examples   Source File: AuditConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorAware() {
    return new EntityAuditorAware();
}
 
Example 20
@Bean
public AuditorAware<Long> auditorProvider(){
    return new SpringSecurityAuditAwareImpl();
}
 
Example 21
/**
 * 增加审计记录,根据登录用户补充创建人、修改人
 */
@Bean
@ConditionalOnMissingBean
public AuditorAware auditorAware() {
    return new JpaAuditingAwareImpl();
}
 
Example 22
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example 23
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example 24
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example 25
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example 26
@Bean
public AuditorAware<String> auditorProvider() {
    return new AuditorAwareImpl(securityUtil);
}
 
Example 27
public EntityMetaObjectHandler(AuditorAware auditorAware) {
	Assert.isTrue(auditorAware != null, "auditorAware is not defined");
	this.auditorAware = auditorAware;
}
 
Example 28
Source Project: spring-data   Source File: ArangoTestConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public AuditorAware<Person> auditorProvider() {
	return new AuditorProvider();
}
 
Example 29
Source Project: zhcet-web   Source File: AuthBeans.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
AuditorAware<String> auditorAware() {
    return new Auditor();
}
 
Example 30
Source Project: galeb   Source File: JpaConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public AuditorAware<String> auditorAware() {
    return new SpringSecurityAuditorAware();
}