MIM 2016: Writing a custom Filter disconnector in C#

Use case

The plight of dealing with strange characters. One management agent that is very sensitive to this is the FIM/MIM service MA. I discovered some items which may pass your AD MA may fail when going to the Portal. And correctly so, the MA is built with best practice in mind. Here are some of characters that may throw of your Sync engine operation

  • Special characters visible to the eye e,g $,%,~
  • Special characters not visible to the eye e.g carriage returns, arrows, bullet points
  • Non-english language characters

What we want

To write a filter disconnector function that will

  • Enable us specify what is allowed
  • Specify if the search is case sensitive or not
  • Check for invalid characters in the DisplayName
  • Set the object to a disconnector

The Code

bool IMASynchronization.FilterForDisconnection(CSEntry csentry)

{

//

// TODO: write connector filter code

//

//throw new EntryPointNotImplementedException();

return finduserobjects(csentry);

}

private bool finduserobjects(CSEntry csentry)

{

bool chkifdnvalid = false;

bool chkifvalid = false;

// check Displayname

if (csentry[“displayName”].IsPresent)

{

chkifdnvalid = Findinvalidcharacter(csentry[“displayName”].Value.ToString());

}

if(chkifdnvalid == true)

{

chkifvalid = true;

}

return chkifvalid;

}

private static bool Findinvalidcharacter(string attribtochk)

{

string allowedChars = “abcdefghijkmnopqrstuvwxyz0123456789’@.,”;

int PositionOfChar = 0;

bool wehaveanInvalidxter = false;

string CleanspacefromAttribToChk = attribtochk.Replace(” “, “”);

foreach (char c in CleanspacefromAttribToChk)

{

PositionOfChar = 0;

PositionOfChar = allowedChars.IndexOf(c.ToString(), StringComparison.InvariantCultureIgnoreCase);

if (PositionOfChar < 0)

{

wehaveanInvalidxter = true;

}

}

return wehaveanInvalidxter;

}