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 2a6a823
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 @@ -18,20 +18,8 @@
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 +28,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));
}

}

0 comments on commit 2a6a823

Please sign in to comment.