Skip to content

Commit f8ff33a

Browse files
committed
omnisessio: accept tabs in config file
Motivation: Admins like to format config files with tabs, however omnisessio config parser accepts only strings. Modification: Update omnisessio config passer to split files by any whitespace characters, including tabs. Result: omnisessio config can use tabs as a field separator Fixes: #7881 Acked-by: Marina Sahakyan Acked-by: Dmitry Litvintsev Target: master Require-book: no Require-notes: yes
1 parent c08a1bd commit f8ff33a

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

modules/gplazma2-omnisession/src/main/java/org/dcache/gplazma/omnisession/ConfigurationParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* dCache - http://www.dcache.org/
22
*
3-
* Copyright (C) 2021-2025 Deutsches Elektronen-Synchrotron
3+
* Copyright (C) 2021 - 2025 Deutsches Elektronen-Synchrotron
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Affero General Public License as
@@ -22,6 +22,7 @@
2222
import static org.dcache.util.ByteSizeParser.Whitespace.NOT_ALLOWED;
2323
import static org.dcache.util.Exceptions.genericCheck;
2424

25+
import com.google.common.base.CharMatcher;
2526
import com.google.common.base.Splitter;
2627
import diskCacheV111.util.FsPath;
2728
import java.util.ArrayList;
@@ -89,7 +90,7 @@ public void accept(String rawLine) throws UnrecoverableParsingException {
8990
}
9091

9192
try {
92-
if (line.startsWith("DEFAULT ")) {
93+
if (line.startsWith("DEFAULT")) {
9394
checkBadLine(defaultAttributes.isEmpty(), "\"DEFAULT\" is already defined.");
9495
List<LoginAttribute> attributes = parseAttributes(line.substring(8));
9596
defaultAttributes = Optional.of(attributes);
@@ -125,7 +126,7 @@ private List<LoginAttribute> parseAttributes(String description) throws BadLineE
125126
boolean isReadOnly = false;
126127
Set<Class<? extends LoginAttribute>> addedAttributes = new HashSet<>();
127128

128-
for (String attr : Splitter.on(' ').omitEmptyStrings().split(description)) {
129+
for (String attr : Splitter.on(CharMatcher.whitespace()).trimResults().omitEmptyStrings().split(description)) {
129130
try {
130131
if (attr.equals("read-only")) {
131132
checkBadLine(!isReadOnly, "already defined 'read-only'");

modules/gplazma2-omnisession/src/main/java/org/dcache/gplazma/omnisession/PrincipalPredicates.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* dCache - http://www.dcache.org/
22
*
3-
* Copyright (C) 2021 Deutsches Elektronen-Synchrotron
3+
* Copyright (C) 2021 - 2025 Deutsches Elektronen-Synchrotron
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Affero General Public License as
@@ -45,7 +45,7 @@
4545
public class PrincipalPredicates {
4646

4747
private static final Pattern PRINCIPAL_PREDICATE =
48-
Pattern.compile("^(?<type>[^:]+):(?<value>([^\"][^ ]*)|(\"[^\"]*\"?)) *");
48+
Pattern.compile("^(?<type>[^:]+):(?<value>([^\"][^ \t]*)|(\"[^\"]*\"?)) *");
4949
private static final Map<String, TestablePrincipal> TESTABLE_PRINCIPAL_BY_LABEL;
5050

5151
static {

modules/gplazma2-omnisession/src/test/java/org/dcache/gplazma/omnisession/ConfigurationParserTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* dCache - http://www.dcache.org/
22
*
3-
* Copyright (C) 2021 Deutsches Elektronen-Synchrotron
3+
* Copyright (C) 2021 - 2025 Deutsches Elektronen-Synchrotron
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Affero General Public License as
@@ -82,6 +82,17 @@ public void shouldAcceptEmptyLine() throws Exception {
8282
new HomeDirectory("/")));
8383
}
8484

85+
@Test
86+
public void shouldAcceptTabs() throws Exception {
87+
// line with tabs
88+
givenConfig("username:paul root:/ home:/");
89+
90+
var loginAttributes = attributesFor(aSetOfPrincipals().withUsername("paul"));
91+
92+
assertThat(loginAttributes, containsInAnyOrder(new RootDirectory("/"),
93+
new HomeDirectory("/")));
94+
}
95+
8596
@Test(expected = AuthenticationException.class)
8697
public void shouldNotMatchWithWrongUsername() throws Exception {
8798
givenConfig("username:paul root:/ home:/");

0 commit comments

Comments
 (0)