@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() ); }
@Bean public AuditorAware<String> auditorProvider() { return new AuditorAware<String>() { @Override public String getCurrentAuditor() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !authentication.isAuthenticated()) { return null; } return authentication.getPrincipal() instanceof User ? ((User) authentication.getPrincipal()).getLogin() : authentication.getPrincipal().toString(); } }; }
@Bean public AuditorAware<String> auditorAware() { return new AuditorAware<String>() { @Override public String getCurrentAuditor() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !authentication.isAuthenticated()) { return null; } return authentication.getName(); } }; }
@Bean public AuditorAware<String> auditorAwareBean() { return () -> { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || new AuthenticationTrustResolverImpl().isAnonymous(authentication)) { return "@SYSTEM"; } Object principal = authentication.getPrincipal(); if (principal instanceof String) { return (String) principal; } else if (principal instanceof UserDetails) { return ((UserDetails) principal).getUsername(); } else { return String.valueOf(principal); } }; }
/** * {@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 TargetManagement targetManagement, final AuditorAware<String> auditorProvider, final ApplicationEventPublisher eventPublisher, final ApplicationContext applicationContext, final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager, final TenantConfigurationManagement tenantConfigurationManagement, final SystemSecurityContext systemSecurityContext) { return new JpaDeploymentManagement(entityManager, actionRepository, distributionSetRepository, targetRepository, actionStatusRepository, targetManagement, auditorProvider, eventPublisher, applicationContext, afterCommit, virtualPropertyReplacer, txManager, tenantConfigurationManagement, systemSecurityContext); }
@Bean public AuditorAware<String> auditorAware() { return () -> { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !authentication.isAuthenticated()) { return "Anonymous"; } //TODO fix fetching user name return authentication.getPrincipal().toString(); }; }
@Bean public AuditorAware<User> auditorAware() { return new AuditorAware<User>() { @Override public User getCurrentAuditor() { System.out.println("\n\nJPAConfig.auditorAware().new AuditorAware() {...}.getCurrentAuditor()"); return UserUtil.getUser(); } }; }
/** * Creates a new {@link AbstractEntityInformation} from the given domain class. * * @param domainClass must not be {@literal null}. */ protected MybatisMetamodelEntityInformation(PersistentEntity<T, ?> persistentEntity, AuditorAware<?> auditorAware, AuditDateAware<?> auditDateAware, Class<T> domainClass) { super(persistentEntity, auditorAware, auditDateAware, domainClass); createdDateProperty = persistentEntity.getPersistentProperty(CreatedDate.class); lastModifiedDateProperty = persistentEntity.getPersistentProperty(LastModifiedDate.class); createdByProperty = persistentEntity.getPersistentProperty(CreatedBy.class); lastModifiedByProperty = persistentEntity.getPersistentProperty(LastModifiedBy.class); }
public MybatisRepositoryFactory(final MybatisMappingContext mappingContext, final SqlSessionTemplate sessionTemplate, final Dialect dialect, AuditorAware<?> auditorAware, AuditDateAware<?> auditDateAware) { Assert.notNull(sessionTemplate); Assert.notNull(dialect); this.mappingContext = mappingContext; this.sessionTemplate = sessionTemplate; this.dialect = dialect; this.auditorAware = auditorAware; this.auditDateAware = auditDateAware; }
/** * Creates a new {@link AbstractEntityInformation} from the given domain class. * * @param auditDateAware * @param domainClass must not be {@literal null}. */ protected MybatisEntityInformationSupport( PersistentEntity<T, ?> persistentEntity, AuditorAware<?> auditorAware, AuditDateAware<?> auditDateAware, Class<T> domainClass) { super(domainClass); this.persistentEntity = persistentEntity; this.auditorAware = auditorAware; this.auditDateAware = auditDateAware; }
public static <T, ID extends Serializable> MybatisEntityInformation<T, ID> getEntityInformation(MybatisMappingContext mappingContext, AuditorAware<?> auditorAware, AuditDateAware<?> auditDateAware, Class<T> domainClass) { Assert.notNull(domainClass); PersistentEntity<T, ?> persistentEntity = (PersistentEntity<T, ?>) mappingContext.getPersistentEntity(domainClass); if (Persistable.class.isAssignableFrom(domainClass)) { return new MybatisPersistableEntityInformation(persistentEntity, auditorAware, auditDateAware, domainClass); } return new MybatisMetamodelEntityInformation<T, ID>(persistentEntity, auditorAware, auditDateAware, domainClass); }
@Bean public AuditorAware<Long> auditorAware() { return new AuditorAware<Long>() { @Override public Long getCurrentAuditor() { return 1001L; } }; }
@Bean public AuditorAware<String> auditorProvider() { return new AuditorAware<String>() { @Override public String getCurrentAuditor() { return "nemo"; //TODO once authentication is working, make this return the real user } }; }
/** * 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); }
@Bean public AuditorAware<String> auditorProvider() { return () -> { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if ((authentication == null) || !authentication.isAuthenticated()) { return null; } return ((Client) authentication.getPrincipal()).getUsername(); }; }
JpaDeploymentManagement(final EntityManager entityManager, final ActionRepository actionRepository, final DistributionSetRepository distributionSetRepository, final TargetRepository targetRepository, final ActionStatusRepository actionStatusRepository, final TargetManagement targetManagement, final AuditorAware<String> auditorProvider, final ApplicationEventPublisher eventPublisher, final ApplicationContext applicationContext, final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager, final TenantConfigurationManagement tenantConfigurationManagement, final SystemSecurityContext systemSecurityContext) { this.entityManager = entityManager; this.actionRepository = actionRepository; this.distributionSetRepository = distributionSetRepository; this.targetRepository = targetRepository; this.actionStatusRepository = actionStatusRepository; this.targetManagement = targetManagement; this.auditorProvider = auditorProvider; this.eventPublisher = eventPublisher; this.applicationContext = applicationContext; this.afterCommit = afterCommit; this.virtualPropertyReplacer = virtualPropertyReplacer; this.txManager = txManager; onlineDsAssignmentStrategy = new OnlineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher, applicationContext, actionRepository, actionStatusRepository); offlineDsAssignmentStrategy = new OfflineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher, applicationContext, actionRepository, actionStatusRepository); this.tenantConfigurationManagement = tenantConfigurationManagement; this.systemSecurityContext = systemSecurityContext; }
@Autowired public SavedSnapshotService(final SavedSearchRepository<SavedSnapshot, SavedSnapshot.Builder> savedSnapshotRepository, final SharedToUserRepository sharedToUserRepository, final AuditorAware<UserEntity> userEntityAuditorAware, final TagNameFactory tagNameFactory) { super(savedSnapshotRepository, sharedToUserRepository, userEntityAuditorAware, tagNameFactory, SavedSnapshot.class); }
@Autowired public SavedQueryService(@SuppressWarnings("TypeMayBeWeakened") final SavedQueryRepository savedQueryRepository, final SharedToUserRepository sharedToUserRepository, final AuditorAware<UserEntity> userEntityAuditorAware, final TagNameFactory tagNameFactory) { super(savedQueryRepository, sharedToUserRepository, userEntityAuditorAware, tagNameFactory, SavedQuery.class); }
protected AbstractSavedSearchService(final SavedSearchRepository<T, B> crudRepository, final SharedToUserRepository sharedToUserRepository, final AuditorAware<UserEntity> userEntityAuditorAware, final TagNameFactory tagNameFactory, final Class<T> type) { this.crudRepository = crudRepository; this.sharedToUserRepository = sharedToUserRepository; this.userEntityAuditorAware = userEntityAuditorAware; this.tagNameFactory = tagNameFactory; this.type = type; }
@Bean public AuditorAware<String> auditorAware() { return new AuditorAware<String>() { public String getCurrentAuditor() { return TEST_AUDITOR; } }; }
@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(); } }; }
@Bean AuditorAware<String> auditorProvider() { return new AuditorAwareImpl(); }
@Bean public AuditorAware<Long> auditorAware() { return new AuditorAwareImpl(); }
@Bean public AuditorAware<AuditInformation> auditorAware() { return new AuditInformationAuditor(); }
@Bean AuditorAware<String> auditorProvider() { return new UsernameAuditorAware(); }
@Bean public AuditorAware<String> auditorAware() { return new AuditorAwareImpl(); }
@Bean public AuditorAware<String> auditorAware() { return () -> "user"; }
@Bean(name = "auditorAware") public AuditorAware<String> auditorAware() { return ()-> SecurityUtils.getCurrentUserUsername(); }
public void setAuditorAware(AuditorAware<?> auditorAware) { this.auditorAware = auditorAware; }
public AuditorAware platformAuditorAware() { return new PlatformAuditorAware(); }
@Bean(name = "platformAuditorAware") public abstract AuditorAware platformAuditorAware();
@Bean public AuditorAware<String> auditorProvider() { return new AuthenticationAuditorAware(); }
@Bean public AuditorAware<User> auditor() { return () -> SecurityUtil.currentUser(); }
@Bean public AuditorAware<String> myAuditorProvider() { return new SpringSecurityAuditorAware(); }
@Bean AuditorAware<String> auditorAware() { return new SpringSecurityAuditorAware(); }