private static void wrapAclPrincipal(StringBuilder buff, Property property,
AclScope scope, AclAccess access)
throws RepositoryException, IOException {
ValueImpl value;
while ((value = (ValueImpl) property.nextValue()) != null) {
Principal principal = (value instanceof PrincipalValue)
? ((PrincipalValue) value).getPrincipal()
: new Principal(value.toString().trim());
String name = stripRoles(principal.getName(), access);
if (!Strings.isNullOrEmpty(name)) {
buff.append("<").append(XML_PRINCIPAL);
if (principal.getPrincipalType() ==
SpiConstants.PrincipalType.UNQUALIFIED) {
// UNQUALIFIED is a special-case on the GSA to allow us to prevent the
// GSA from mistakeningly finding a domain in the principal name.
XmlUtils.xmlAppendAttr(ServletUtil.XMLTAG_PRINCIPALTYPE_ATTRIBUTE,
SpiConstants.PrincipalType.UNQUALIFIED.toString(), buff);
}
if (!Strings.isNullOrEmpty(principal.getNamespace())) {
XmlUtils.xmlAppendAttr(ServletUtil.XMLTAG_NAMESPACE_ATTRIBUTE,
principal.getNamespace(), buff);
}
// The GSA's default is EVERYTHING_CASE_SENSITIVE. No need to send the
// attribute when it is the default.
if (principal.getCaseSensitivityType()
!= SpiConstants.CaseSensitivityType.EVERYTHING_CASE_SENSITIVE) {
XmlUtils.xmlAppendAttr(
ServletUtil.XMLTAG_CASESENSITIVITYTYPE_ATTRIBUTE,
principal.getCaseSensitivityType().toString(), buff);
}
XmlUtils.xmlAppendAttr(XML_SCOPE, scope.toString(), buff);
XmlUtils.xmlAppendAttr(XML_ACCESS, access.toString(), buff);
buff.append(">");
XmlUtils.xmlAppendAttrValue(name, buff);