本文整理汇总了Java中org.springframework.data.domain.AuditorAware类的典型用法代码示例。如果您正苦于以下问题:Java AuditorAware类的具体用法?Java AuditorAware怎么用?Java AuditorAware使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuditorAware类属于org.springframework.data.domain包,在下文中一共展示了AuditorAware类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: auditorAware
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
@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()
);
}
示例2: auditorProvider
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
@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();
}
};
}
示例3: auditorAware
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
@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();
}
};
}
示例4: auditorAwareBean
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
@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);
}
};
}
示例5: MybatisMetamodelEntityInformation
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
/**
* 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);
}
示例6: deploymentManagement
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
/**
* {@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);
}
示例7: auditorAware
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
@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();
};
}
示例8: auditorAware
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
@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();
}
};
}
示例9: MybatisRepositoryFactory
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
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;
}
示例10: MybatisEntityInformationSupport
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
/**
* 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;
}
示例11: getEntityInformation
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
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);
}
示例12: auditorAware
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
@Bean
public AuditorAware<Long> auditorAware() {
return new AuditorAware<Long>() {
@Override
public Long getCurrentAuditor() {
return 1001L;
}
};
}
示例13: auditorProvider
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
@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
}
};
}
示例14: testAuthenticationAuditorAware
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
/**
* 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);
}
开发者ID:DISID,项目名称:springlets,代码行数:15,代码来源:SpringletsDataJpaAuthenticationAuditorConfigurationTest.java
示例15: auditorProvider
import org.springframework.data.domain.AuditorAware; //导入依赖的package包/类
@Bean
public AuditorAware<String> auditorProvider() {
return
() -> {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if ((authentication == null) || !authentication.isAuthenticated()) {
return null;
}
return ((Client) authentication.getPrincipal()).getUsername();
};
}