Commit fc46175e9986a9ad965ba6c319620a5b5a9e70cf

Authored by Volodymyr Babak
Committed by Andrew Shvayka
1 parent c1b5fd5c

Renamed env variabled. Added sync

... ... @@ -51,9 +51,9 @@ public class BasicOAuth2ClientMapper extends AbstractOAuth2ClientMapper implemen
51 51 String firstName = getStringAttributeByKey(attributes, config.getBasic().getFirstNameAttributeKey());
52 52 oauth2User.setFirstName(firstName);
53 53 }
54   - if (!StringUtils.isEmpty(config.getBasic().getCustomerNameStrategyPattern())) {
  54 + if (!StringUtils.isEmpty(config.getBasic().getCustomerNamePattern())) {
55 55 StrSubstitutor sub = new StrSubstitutor(attributes, START_PLACEHOLDER_PREFIX, END_PLACEHOLDER_PREFIX);
56   - String customerName = sub.replace(config.getBasic().getCustomerNameStrategyPattern());
  56 + String customerName = sub.replace(config.getBasic().getCustomerNamePattern());
57 57 oauth2User.setCustomerName(customerName);
58 58 }
59 59 return getOrCreateSecurityUserFromOAuth2User(oauth2User, config.getBasic().isAllowUserCreation());
... ... @@ -68,7 +68,7 @@ public class BasicOAuth2ClientMapper extends AbstractOAuth2ClientMapper implemen
68 68 return email.substring(email .indexOf("@") + 1);
69 69 case CUSTOM_TENANT_STRATEGY:
70 70 StrSubstitutor sub = new StrSubstitutor(attributes, START_PLACEHOLDER_PREFIX, END_PLACEHOLDER_PREFIX);
71   - return sub.replace(config.getBasic().getTenantNameStrategyPattern());
  71 + return sub.replace(config.getBasic().getTenantNamePattern());
72 72 default:
73 73 throw new RuntimeException("Tenant Name Strategy with type " + config.getBasic().getTenantNameStrategy() + " is not supported!");
74 74 }
... ... @@ -78,7 +78,6 @@ public class BasicOAuth2ClientMapper extends AbstractOAuth2ClientMapper implemen
78 78 String result = null;
79 79 try {
80 80 result = (String) attributes.get(key);
81   -
82 81 } catch (Exception e) {
83 82 log.warn("Can't convert attribute to String by key " + key);
84 83 }
... ...
... ... @@ -41,7 +41,7 @@ public class CustomOAuth2ClientMapper extends AbstractOAuth2ClientMapper impleme
41 41 return getOrCreateSecurityUserFromOAuth2User(oauth2User, config.getBasic().isAllowUserCreation());
42 42 }
43 43
44   - public OAuth2User getOAuth2User(OAuth2AuthenticationToken token, OAuth2ClientMapperConfig.CustomOAuth2ClientMapperConfig custom) {
  44 + private synchronized OAuth2User getOAuth2User(OAuth2AuthenticationToken token, OAuth2ClientMapperConfig.CustomOAuth2ClientMapperConfig custom) {
45 45 if (!StringUtils.isEmpty(custom.getUsername()) && !StringUtils.isEmpty(custom.getPassword())) {
46 46 restTemplateBuilder = restTemplateBuilder.basicAuthentication(custom.getUsername(), custom.getPassword());
47 47 }
... ...
... ... @@ -126,8 +126,8 @@ security:
126 126 firstNameAttributeKey: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_FIRST_NAME_ATTRIBUTE_KEY:}"
127 127 lastNameAttributeKey: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_LAST_NAME_ATTRIBUTE_KEY:}"
128 128 tenantNameStrategy: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_TENANT_NAME_STRATEGY:domain}" # domain, email or custom
129   - tenantNameStrategyPattern: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_TENANT_NAME_STRATEGY_PATTERN:}"
130   - customerNameStrategyPattern: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_CUSTOMER_NAME_STRATEGY_PATTERN:}"
  129 + tenantNamePattern: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_TENANT_NAME_PATTERN:}" # %{attribute_key} as placeholder for attributes value by key
  130 + customerNamePattern: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_CUSTOMER_NAME_PATTERN:}" # %{attribute_key} as placeholder for attributes value by key
131 131 custom:
132 132 url: "${SECURITY_OAUTH2_DEFAULT_MAPPER_CUSTOM_URL:}"
133 133 username: "${SECURITY_OAUTH2_DEFAULT_MAPPER_CUSTOM_USERNAME:}"
... ...
... ... @@ -31,8 +31,8 @@ public class OAuth2ClientMapperConfig {
31 31 private String firstNameAttributeKey;
32 32 private String lastNameAttributeKey;
33 33 private String tenantNameStrategy;
34   - private String tenantNameStrategyPattern;
35   - private String customerNameStrategyPattern;
  34 + private String tenantNamePattern;
  35 + private String customerNamePattern;
36 36 }
37 37
38 38 @Data
... ...