Skip to content

Commit db8e168

Browse files
authored
chore: Use configured delimiter to split entries (#967)
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
1 parent 5503f99 commit db8e168

6 files changed

Lines changed: 33 additions & 18 deletions

File tree

assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,17 @@ che.oauth2.gitlab.clientsecret_filepath=NULL
669669
che.oauth2.gitlab.clientsecret_filepath_2=NULL
670670

671671
### Advanced authorization
672-
# Comma separated list of users allowed to access Che.
672+
# Separated list of users allowed to access Che. Delimiter is defined by the delimiter property.
673673
che.infra.kubernetes.advanced_authorization.allow_users=NULL
674674

675-
# Comma separated list of groups of users allowed to access Che.
675+
# Separated list of groups of users allowed to access Che. Delimiter is defined by the delimiter property.
676676
che.infra.kubernetes.advanced_authorization.allow_groups=NULL
677677

678-
# Comma separated list of users denied to access Che.
678+
# Separated list of users denied to access Che. Delimiter is defined by the delimiter property.
679679
che.infra.kubernetes.advanced_authorization.deny_users=NULL
680680

681-
# Comma separated list of groups of users denied to access Che.
681+
# Separated list of groups of users denied to access Che. Delimiter is defined by the delimiter property.
682682
che.infra.kubernetes.advanced_authorization.deny_groups=NULL
683+
684+
# Delimiter used to split entries in advanced authorization lists (allow_users, allow_groups, deny_users, deny_groups).
685+
che.infra.kubernetes.advanced_authorization.delimiter=,

core/commons/che-core-commons-lang/src/main/java/org/eclipse/che/commons/lang/StringUtils.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2023 Red Hat, Inc.
2+
* Copyright (c) 2012-2026 Red Hat, Inc.
33
* This program and the accompanying materials are made
44
* available under the terms of the Eclipse Public License 2.0
55
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -101,8 +101,19 @@ public static int lastIndexOf(CharSequence s, char c, int start, int end) {
101101

102102
/** Parse string to set of strings. String should be comma separated. Whitespaces are trimmed. */
103103
public static Set<String> strToSet(String str) {
104+
return strToSet(str, ",");
105+
}
106+
107+
/**
108+
* Parse string to set of strings using the specified separator. Whitespaces are trimmed.
109+
*
110+
* @param str the string to parse
111+
* @param delimiter the delimiter to split on
112+
* @return set of strings
113+
*/
114+
public static Set<String> strToSet(String str, String delimiter) {
104115
if (!isNullOrEmpty(str)) {
105-
return Sets.newHashSet(Splitter.on(",").trimResults().omitEmptyStrings().split(str));
116+
return Sets.newHashSet(Splitter.on(delimiter).trimResults().omitEmptyStrings().split(str));
106117
} else {
107118
return Collections.emptySet();
108119
}

infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/authorization/KubernetesOIDCAuthorizationCheckerImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public KubernetesOIDCAuthorizationCheckerImpl(
3636
@Nullable @Named("che.infra.kubernetes.advanced_authorization.allow_groups")
3737
String allowGroups,
3838
@Nullable @Named("che.infra.kubernetes.advanced_authorization.deny_users") String denyUsers,
39-
@Nullable @Named("che.infra.kubernetes.advanced_authorization.deny_groups")
40-
String denyGroups) {
41-
this.allowUsers = strToSet(allowUsers);
42-
this.allowGroups = strToSet(allowGroups);
43-
this.denyUsers = strToSet(denyUsers);
44-
this.denyGroups = strToSet(denyGroups);
39+
@Nullable @Named("che.infra.kubernetes.advanced_authorization.deny_groups") String denyGroups,
40+
@Named("che.infra.kubernetes.advanced_authorization.delimiter") String delimiter) {
41+
this.allowUsers = strToSet(allowUsers, delimiter);
42+
this.allowGroups = strToSet(allowGroups, delimiter);
43+
this.denyUsers = strToSet(denyUsers, delimiter);
44+
this.denyGroups = strToSet(denyGroups, delimiter);
4545
}
4646

4747
public boolean isAuthorized(Subject subject) {

infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/authorization/KubernetesAuthorizationCheckerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void advancedAuthorization(
4242
// give
4343
KubernetesOIDCAuthorizationCheckerImpl authorizationChecker =
4444
new KubernetesOIDCAuthorizationCheckerImpl(
45-
allowedUsers, allowedGroups, deniedUsers, deniedGroups);
45+
allowedUsers, allowedGroups, deniedUsers, deniedGroups, ",");
4646

4747
// when
4848
boolean isAuthorized = authorizationChecker.isAuthorized(subject);

infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/authorization/OpenShiftAuthorizationCheckerImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ public OpenShiftAuthorizationCheckerImpl(
4444
String allowGroups,
4545
@Nullable @Named("che.infra.kubernetes.advanced_authorization.deny_users") String denyUsers,
4646
@Nullable @Named("che.infra.kubernetes.advanced_authorization.deny_groups") String denyGroups,
47+
@Named("che.infra.kubernetes.advanced_authorization.delimiter") String delimiter,
4748
CheServerKubernetesClientFactory cheServerKubernetesClientFactory) {
48-
this.allowUsers = strToSet(allowUsers);
49-
this.allowGroups = strToSet(allowGroups);
50-
this.denyUsers = strToSet(denyUsers);
51-
this.denyGroups = strToSet(denyGroups);
49+
this.allowUsers = strToSet(allowUsers, delimiter);
50+
this.allowGroups = strToSet(allowGroups, delimiter);
51+
this.denyUsers = strToSet(denyUsers, delimiter);
52+
this.denyGroups = strToSet(denyGroups, delimiter);
5253
this.cheServerKubernetesClientFactory = cheServerKubernetesClientFactory;
5354
}
5455

infrastructures/openshift/src/test/java/org/eclipse/che/workspace/infrastructure/openshift/authorization/OpenShiftAuthorizationCheckerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void advancedAuthorization(
8484
// give
8585
OpenShiftAuthorizationCheckerImpl authorizationChecker =
8686
new OpenShiftAuthorizationCheckerImpl(
87-
allowedUsers, allowedGroups, deniedUsers, deniedGroups, clientFactory);
87+
allowedUsers, allowedGroups, deniedUsers, deniedGroups, ",", clientFactory);
8888
groups.forEach(group -> client.resources(Group.class).create(group));
8989

9090
// when

0 commit comments

Comments
 (0)