SecurityAttributes principalAttrs = principal.getSecurityAttributes();
for (AttributeDef attrDef : entity.getAttributeDefinitions())
{
if (attrDef.isMapped() && !attrDef.isMultiValue())
{
Attribute attr = entity.getAttribute(attrDef.getName());
if (attr == null)
{
if (!syncAll)
{
// if principal has attr: remove it
SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName());
if (principalAttr != null)
{
if (logger.isDebugEnabled())
{
logger.debug("Removing attribute "+principalAttr.getName()+" for principal "+principal.getName()+".");
}
principalAttrs.removeAttribute(principalAttr.getName());
updated = true;
}
}
}
else if (syncAll)
{
SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName(), true);
if (logger.isDebugEnabled())
{
logger.debug("Adding attribute "+principalAttr.getName()+" for principal "+principal.getName()+". Value: "+attr.getValue());
}
principalAttr.setStringValue(attr.getValue());
updated = true;
}
else
{
SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName(), true);
if (!StringUtils.equals(principalAttr.getStringValue(), attr.getValue()))
{
if (logger.isDebugEnabled())
{
logger.debug("Updating attribute "+principalAttr.getName()+" for principal "+principal.getName()+". Old value: "+(principalAttr.getStringValue())+" new value: "+attr.getValue());
}
principalAttr.setStringValue(attr.getValue());
updated = true;
}
}
}
}