本文整理匯總了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();
};
}