AuditorConfig.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright 2019-2020 Zheng Jie
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package me.zhengjie.config;
  17. import me.zhengjie.utils.SecurityUtils;
  18. import org.springframework.data.domain.AuditorAware;
  19. import org.springframework.stereotype.Component;
  20. import java.util.Optional;
  21. /**
  22. * @description : 设置审计
  23. * @author : Dong ZhaoYang
  24. * @date : 2019/10/28
  25. */
  26. @Component("auditorAware")
  27. public class AuditorConfig implements AuditorAware<String> {
  28. /**
  29. * 返回操作员标志信息
  30. *
  31. * @return /
  32. */
  33. @Override
  34. public Optional<String> getCurrentAuditor() {
  35. try {
  36. // 这里应根据实际业务情况获取具体信息
  37. return Optional.of(SecurityUtils.getCurrentUsername());
  38. }catch (Exception ignored){}
  39. // 用户定时任务,或者无Token调用的情况
  40. return Optional.of("System");
  41. }
  42. }