SocialsConfig.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package jnpf.socials.config;
  2. import org.springframework.boot.context.properties.ConfigurationProperties;
  3. import org.springframework.stereotype.Component;
  4. import java.util.*;
  5. import java.util.stream.Collectors;
  6. /**
  7. * 流程设计
  8. *
  9. * @author JNPF开发平台组
  10. * @version V3.4.2
  11. * @copyright 引迈信息技术有限公司
  12. * @date 2022/9/6 14:58:23
  13. */
  14. @Component
  15. @ConfigurationProperties(prefix = SocialsConfig.PREFIX)
  16. public class SocialsConfig {
  17. public static final String PREFIX = "socials";
  18. private boolean socialsEnabled = false;
  19. private List<CustomAuthConfig> config;
  20. private Map<String, CustomAuthConfig> socialMap;
  21. public SocialsConfig() {
  22. }
  23. public SocialsConfig(List<CustomAuthConfig> config, Map<String, CustomAuthConfig> socialMap) {
  24. this.config = config;
  25. this.socialMap = socialMap.entrySet().stream()
  26. .filter(item -> item.getValue().isEnabled())
  27. .collect(Collectors.toMap(
  28. Map.Entry::getKey,
  29. Map.Entry::getValue,
  30. (oldValue, newValue) -> oldValue,
  31. LinkedHashMap::new
  32. ));
  33. }
  34. public boolean isSocialsEnabled() {
  35. return socialsEnabled;
  36. }
  37. public void setSocialsEnabled(boolean socialsEnabled) {
  38. this.socialsEnabled = socialsEnabled;
  39. }
  40. public void setConfig(List<CustomAuthConfig> config) {
  41. this.config = config;
  42. this.socialMap = new HashMap<>();
  43. config.stream().forEach(item -> {
  44. this.socialMap.put(item.getProvider(), item);
  45. });
  46. }
  47. public List<CustomAuthConfig> getConfig() {
  48. return config;
  49. }
  50. public Map<String, CustomAuthConfig> getSocialMap() {
  51. return socialMap;
  52. }
  53. @Deprecated
  54. public static class Config {
  55. private String provider;
  56. private String clientId;
  57. private String clientSecret;
  58. private String agentId;
  59. //企业ID
  60. private String corpId;
  61. //企微应用登录类型
  62. //ServiceApp:服务商登录;CorpApp:企业自建/代开发应用登录
  63. private String loginType;
  64. public Config() {
  65. }
  66. @Override
  67. public boolean equals(Object o) {
  68. if (this == o) return true;
  69. if (o == null || getClass() != o.getClass()) return false;
  70. Config config = (Config) o;
  71. return Objects.equals(provider, config.provider) && Objects.equals(clientId, config.clientId) && Objects.equals(clientSecret, config.clientSecret) && Objects.equals(agentId, config.agentId);
  72. }
  73. @Override
  74. public int hashCode() {
  75. return Objects.hash(provider, clientId, clientSecret, agentId);
  76. }
  77. @Override
  78. public String toString() {
  79. return "Config{" +
  80. "provider='" + provider + '\'' +
  81. ", clientId='" + clientId + '\'' +
  82. ", clientSecret='" + clientSecret + '\'' +
  83. ", agentId='" + agentId + '\'' +
  84. ", corpId='" + corpId + '\'' +
  85. ", loginType='" + loginType + '\'' +
  86. '}';
  87. }
  88. public String getProvider() {
  89. return provider;
  90. }
  91. public void setProvider(String provider) {
  92. this.provider = provider;
  93. }
  94. public String getClientId() {
  95. return clientId;
  96. }
  97. public void setClientId(String clientId) {
  98. this.clientId = clientId;
  99. }
  100. public String getClientSecret() {
  101. return clientSecret;
  102. }
  103. public void setClientSecret(String clientSecret) {
  104. this.clientSecret = clientSecret;
  105. }
  106. public String getAgentId() {
  107. return agentId;
  108. }
  109. public String getCorpId() {
  110. return corpId;
  111. }
  112. public void setCorpId(String corpId) {
  113. this.corpId = corpId;
  114. }
  115. public String getLoginType() {
  116. return loginType;
  117. }
  118. public void setLoginType(String loginType) {
  119. this.loginType = loginType;
  120. }
  121. public void setAgentId(String agentId) {
  122. this.agentId = agentId;
  123. }
  124. public Config(String provider, String clientId, String clientSecret, String agentId) {
  125. this.provider = provider;
  126. this.clientId = clientId;
  127. this.clientSecret = clientSecret;
  128. this.agentId = agentId;
  129. }
  130. }
  131. }