pingidentity / scim2

The UnboundID SCIM 2.0 SDK for Java
176 stars 72 forks source link

Add a mechanism to optionally permit semicolons in filtered attribute… #158

Closed lance-purple-unboundid closed 3 years ago

lance-purple-unboundid commented 3 years ago

… names.

This is needed by the Ping Directory REST API, in order to support filtering and retrieval of SCIM resources by LDAP attribute names, which may include semicolon-delimited attribute options (see RFC2251 section 4.1.5 for details).

JIRA issue: DS-37117

braveulysses commented 3 years ago

I wonder if we could try a slightly different approach? Using an enum to configure the Parser might limit us if a future need to custom-configure it arises:

  1. If you want to allow some character besides semicolon in the future, you have to define another enum value just for that character.
  2. ParserOptions are on/off flags. If you want to pass configuration to a ParserOption... I'm not sure that you could?

Maybe you could use something like a ParserConfig class, instead...

public final class ParserConfig
{
  private final Set<Character> allowedCharacters = new HashSet<>();

  public void setAdditionalAllowedCharacters(final Character... allowedCharacters)
  {
    Arrays.stream(allowedCharacters).filter(Objects::nonNull).forEach(this.allowedCharacters::add);
  }

  public void clearAdditionalAllowedCharacters()
  {
    allowedCharacters.clear();
  }

  public Set<Character> getAdditionalAllowedCharacters()
  {
    return allowedCharacters;
  }

  // It should be possible to use a regex Pattern to define the allowed characters instead 
  // of a Set<Character>, too

  // Other methods can be added as needed in the future
}

... then assign if to a ThreadLocal in Parser...

private static final ThreadLocal<ParserConfig> threadLocalConfig =
      ThreadLocal.withInitial(ParserConfig::new);

... and expose it to the API user with a public static ParserConfig getParserConfig() method on the Parser class.

public static ParserConfig getConfiguration()
{
  return Parser.threadLocalConfig.get();
}

Internally, the Parser class would call Parser.threadLocalConfig.get().getAdditionalAllowedCharacters() to get the set of additional allowed characters, if any.

braveulysses commented 3 years ago

One other thing: Can you add a blurb about this change to CHANGELOG.md?