Skip to content

Commit

Permalink
Fixed error on pool account resolution in case name contains numbers
Browse files Browse the repository at this point in the history
Fix for #28
  • Loading branch information
enricovianello committed Jul 14, 2020
1 parent 1e81cc8 commit 3dde960
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) Members of the EGEE Collaboration. 2006-2010.
* See http://www.eu-egee.org/partners/ for details on the copyright holders.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.glite.authz.pep.obligation.dfpmap;

import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DefaultFilenameFilter implements FilenameFilter {

private final String prefix;

/**
* RegExp pattern used to identify pool account names.
*
* Contains a single group match whose value is the pool account name prefix.
*
*/
private final Pattern poolAccountNamePattern =
Pattern.compile("^([a-zA-Z][a-zA-Z0-9._-]*?)[0-9]{3,3}$");

public DefaultFilenameFilter(String prefix) {
this.prefix = prefix;
}

@Override
public boolean accept(File dir, String name) {

Matcher nameMatcher = poolAccountNamePattern.matcher(name);

return nameMatcher.matches() && (prefix == null || prefix.equals(nameMatcher.group(1)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.glite.authz.pep.obligation.dfpmap;

import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DefaultPoolAccountResolver implements PoolAccountResolver{

/**
* Regexp pattern used to identify pool account names.
*
* Contains a single group match whose value is the pool account name prefix.
*
*/
private final Pattern poolAccountNamePattern_ = Pattern
.compile("^([a-zA-Z][a-zA-Z0-9._-]*?)[0-9]++$");
public class DefaultPoolAccountResolver implements PoolAccountResolver {

final File gridmapDir;

Expand All @@ -40,31 +27,16 @@ public DefaultPoolAccountResolver(final File gridmapDir) {
}

/**
* Gets a list of account files where the file names begin with the given
* prefix.
* Gets a list of account files where the file names begin with the given prefix.
*
* @param prefix
* prefix with which the file names should begin, may be null to
* signify all file names
* @param prefix prefix with which the file names should begin, may be null to signify all file
* names
*
* @return the selected account files
*/
public File[] getAccountFiles(final String prefix) {

return gridmapDir.listFiles(new FilenameFilter() {

public boolean accept(final File dir, final String name) {

Matcher nameMatcher = poolAccountNamePattern_.matcher(name);

if (nameMatcher.matches()) {
if (prefix == null || prefix.equals(nameMatcher.group(1))) {
return true;
}
}
return false;
}
});
return gridmapDir.listFiles(new DefaultFilenameFilter(prefix));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private File createTempGridMapDir() throws IOException {
temp.deleteOnExit();

for (int idx = 1; idx <= N_POOL; idx++) {
String lFileName = String.format("%s%02d", mAccountPrefix, idx);
String lFileName = String.format("%s%03d", mAccountPrefix, idx);
File f = new File(temp, lFileName);
f.createNewFile();
f.deleteOnExit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ private File createTempGridMapDir() throws IOException {
// populate with pool accounts
for (String prefix : prefixes) {
for (int i = 1; i <= N_POOL; i++) {
File f = new File(temp, prefix + "0" + i);
File f = new File(temp, prefix + "00" + i);
f.createNewFile();
f.deleteOnExit();
}
}
// create invalid files
for (String invalid : invalids) {
for (int i = 1; i <= N_POOL; i++) {
File f = new File(temp, invalid + "0" + i);
File f = new File(temp, invalid + "00" + i);
f.createNewFile();
f.deleteOnExit();
}
Expand Down

0 comments on commit 3dde960

Please sign in to comment.