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: JPAConfig.java From ElementVueSpringbootCodeTemplate with Apache License 2.0 | 6 votes |
@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 #2
Source File: PostServiceApplication.java From spring-microservice-sample with GNU General Public License v3.0 | 6 votes |
@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 #3
Source File: RepositoryApplicationConfiguration.java From hawkbit with Eclipse Public License 1.0 | 6 votes |
/** * {@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 |
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: JiwhizBlogWebApplication.java From JiwhizBlogWeb with Apache License 2.0 | 5 votes |
@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 #6
Source File: SpringletsDataJpaAuthenticationAuditorConfigurationTest.java From springlets with Apache License 2.0 | 5 votes |
/** * 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 #7
Source File: SecurityConfig.java From spring-content with Apache License 2.0 | 5 votes |
@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 #8
Source File: SavedSnapshotService.java From find with MIT License | 5 votes |
@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 #9
Source File: SavedQueryService.java From find with MIT License | 5 votes |
@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 #10
Source File: AbstractSavedSearchService.java From find with MIT License | 5 votes |
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 #11
Source File: RepositoryApplicationConfiguration.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
/** * {@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 #12
Source File: JpaDeploymentManagement.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
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 #13
Source File: DemoApplication.java From spring-webmvc-jwt-sample with GNU General Public License v3.0 | 5 votes |
@Bean public AuditorAware<User> auditor() { return () -> Optional.ofNullable(SecurityContextHolder.getContext()) .map(SecurityContext::getAuthentication) .filter(Authentication::isAuthenticated) .map(Authentication::getPrincipal) .map(User.class::cast); }
Example #14
Source File: MethodSecurityApplication.java From Spring with Apache License 2.0 | 5 votes |
@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 #15
Source File: AuditSecurityConfiguration.java From spring-security-samples with MIT License | 5 votes |
@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 #16
Source File: JiwhizBlogRepositoryTestApplication.java From JiwhizBlogWeb with Apache License 2.0 | 5 votes |
@Bean public AuditorAware<String> auditorAware() { return new AuditorAware<String>() { public String getCurrentAuditor() { return TEST_AUDITOR; } }; }
Example #17
Source File: TestConfiguration.java From hawkbit with Eclipse Public License 1.0 | 4 votes |
@Bean AuditorAware<String> auditorAware() { return new SpringSecurityAuditorAware(); }
Example #18
Source File: SecurityAutoConfiguration.java From hawkbit with Eclipse Public License 1.0 | 4 votes |
/** * Creates the auditor aware. * * @return the spring security auditor aware */ @Bean @ConditionalOnMissingBean public AuditorAware<String> auditorAware() { return new SpringSecurityAuditorAware(); }
Example #19
Source File: AuditingConfig.java From fullstop with Apache License 2.0 | 4 votes |
@Bean public AuditorAware auditorAware() { return new SpringSecurityAuditorAware(); }
Example #20
Source File: JpaConfig.java From fullstop with Apache License 2.0 | 4 votes |
@Bean AuditorAware<String> auditorAware() { return () -> "unit-test"; }
Example #21
Source File: MongoDbConfiguration.java From moserp with Apache License 2.0 | 4 votes |
@Bean public AuditorAware<String> myAuditorProvider() { return new SpringSecurityAuditorAware(); }
Example #22
Source File: PersistenceConfig.java From tutorials with MIT License | 4 votes |
@Bean("auditorProvider") public AuditorAware<String> auditorProvider() { return new AuditorAwareImpl(); }
Example #23
Source File: JdbcConfig.java From platform with Apache License 2.0 | 4 votes |
@Bean public AuditorAware<Long> auditorAware(Context context) { return new UserAuditorAware(context); }
Example #24
Source File: JpaConfig.java From angularjs-springmvc-sample-boot with Apache License 2.0 | 4 votes |
@Bean public AuditorAware<User> auditor() { return () -> SecurityUtil.currentUser(); }
Example #25
Source File: MybatisAuditingHandler.java From spring-data-mybatis with Apache License 2.0 | 4 votes |
/** * Setter to inject a {@code AuditorAware} component to retrieve the current auditor. * @param auditorAware must not be {@literal null}. */ public void setAuditorAware(AuditorAware<?> auditorAware) { Assert.notNull(auditorAware, "AuditorAware must not be null!"); this.auditorAware = Optional.of(auditorAware); }
Example #26
Source File: SpringletsDataJpaAuthenticationAuditorConfiguration.java From springlets with Apache License 2.0 | 4 votes |
@Bean public AuditorAware<String> auditorProvider() { return new AuthenticationAuditorAware(); }
Example #27
Source File: CoreJpaConfiguration.java From abixen-platform with GNU Lesser General Public License v2.1 | 4 votes |
public AuditorAware platformAuditorAware() { return new PlatformAuditorAware(); }
Example #28
Source File: EntityMetaObjectHandler.java From albedo with GNU Lesser General Public License v3.0 | 4 votes |
public EntityMetaObjectHandler(AuditorAware auditorAware) { Assert.isTrue(auditorAware != null, "auditorAware is not defined"); this.auditorAware = auditorAware; }
Example #29
Source File: ReactiveAuditingIT.java From sdn-rx with Apache License 2.0 | 4 votes |
@Bean public AuditorAware<String> auditorProvider() { return () -> Optional.of("A user"); }
Example #30
Source File: AuditConfiguration.java From code-examples with MIT License | 4 votes |
@Bean public AuditorAware<String> auditorAware() { return new EntityAuditorAware(); }