I have my own SimplePrincipal and SimpleGroup classes. I solved the problem implementing equal method as it does JBoss in SimplePrincipal:
if (!(another instanceof Principal)) {
return false;
}
String anotherName = ((Principal) another).getName();
boolean equals = false;
if (name == null){ equals = anotherName ==
null;}
else
{equals =
name.equals(anotherName);}
return equals;