當前位置: 首頁>>代碼示例>>Java>>正文


Java AuditorAware類代碼示例

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

}
 
開發者ID:hantsy,項目名稱:spring-microservice-sample,代碼行數:20,代碼來源:DataJpaConfig.java

示例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();
        }
    };
}
 
開發者ID:yuexine,項目名稱:loafer,代碼行數:17,代碼來源:JPAAuditorConfiguration.java

示例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();
        }
    };
}
 
開發者ID:weechang,項目名稱:Taroco,代碼行數:16,代碼來源:ApiGateWayApplication.java

示例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);
    }
  };
}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:20,代碼來源:WebSecurityConfiguration.java

示例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);
}
 
開發者ID:hatunet,項目名稱:spring-data-mybatis,代碼行數:15,代碼來源:MybatisMetamodelEntityInformation.java

示例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);
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:21,代碼來源:RepositoryApplicationConfiguration.java

示例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();
    };
}
 
開發者ID:rozidan,項目名稱:project-template,代碼行數:13,代碼來源:AuditingConfig.java

示例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();
		}
	};
}
 
開發者ID:xwjie,項目名稱:ElementVueSpringbootCodeTemplate,代碼行數:13,代碼來源:JPAConfig.java

示例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;
}
 
開發者ID:hatunet,項目名稱:spring-data-mybatis,代碼行數:14,代碼來源:MybatisRepositoryFactory.java

示例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;
}
 
開發者ID:hatunet,項目名稱:spring-data-mybatis,代碼行數:16,代碼來源:MybatisEntityInformationSupport.java

示例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);
}
 
開發者ID:hatunet,項目名稱:spring-data-mybatis,代碼行數:13,代碼來源:MybatisEntityInformationSupport.java

示例12: auditorAware

import org.springframework.data.domain.AuditorAware; //導入依賴的package包/類
@Bean
public AuditorAware<Long> auditorAware() {
    return new AuditorAware<Long>() {
        @Override
        public Long getCurrentAuditor() {
            return 1001L;
        }
    };
}
 
開發者ID:hatunet,項目名稱:spring-data-mybatis,代碼行數:10,代碼來源:TestConfig.java

示例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
        }
    };
}
 
開發者ID:EMBL-EBI-SUBS-OLD,項目名稱:subs,代碼行數:10,代碼來源:RestRepositoryConfig.java

示例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();
  };
}
 
開發者ID:ImmobilienScout24,項目名稱:switchman,代碼行數:14,代碼來源:Persistence.java


注:本文中的org.springframework.data.domain.AuditorAware類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。