use of com.unboundid.ldap.sdk.Modification in project zm-mailbox by Zimbra.
the class UBIDModificationList method replaceAll.
void replaceAll(Map<String, Object> attrs) {
for (Map.Entry<String, Object> attr : attrs.entrySet()) {
String attrName = attr.getKey();
Object attrValue = attr.getValue();
Modification mod = null;
if (attrValue == null) {
mod = new Modification(ModificationType.DELETE, attrName);
} else if (attrValue instanceof String) {
if (((String) attrValue).isEmpty()) {
mod = new Modification(ModificationType.DELETE, attrName);
} else {
mod = new Modification(ModificationType.REPLACE, attrName, (String) attrValue);
}
} else if (attrValue instanceof String[]) {
mod = new Modification(ModificationType.REPLACE, attrName, (String[]) attrValue);
}
modList.add(mod);
}
}
use of com.unboundid.ldap.sdk.Modification in project zm-mailbox by Zimbra.
the class UBIDModificationList method addAttr.
@Override
public void addAttr(String name, String[] value, Entry entry, boolean containsBinaryData, boolean isBinaryTransfer) {
String[] currentValues = entry.getMultiAttr(name, false, true);
List<ASN1OctetString> valuesToAdd = null;
for (int i = 0; i < value.length; i++) {
if (LdapUtil.contains(currentValues, value[i])) {
continue;
}
if (valuesToAdd == null) {
valuesToAdd = new ArrayList<ASN1OctetString>();
}
valuesToAdd.add(UBIDUtil.newASN1OctetString(containsBinaryData, value[i]));
}
if (valuesToAdd != null) {
String transferAttrName = LdapUtil.attrNameToBinaryTransferAttrName(isBinaryTransfer, name);
Modification mod = new Modification(ModificationType.ADD, transferAttrName, valuesToAdd.toArray(new ASN1OctetString[valuesToAdd.size()]));
modList.add(mod);
}
}
use of com.unboundid.ldap.sdk.Modification in project zm-mailbox by Zimbra.
the class UBIDModificationList method modifyAttr.
@Override
public void modifyAttr(String name, String[] value, boolean containsBinaryData, boolean isBinaryTransfer) {
List<ASN1OctetString> valuesToMod = new ArrayList<ASN1OctetString>();
for (int i = 0; i < value.length; i++) {
valuesToMod.add(UBIDUtil.newASN1OctetString(containsBinaryData, value[i]));
}
String transferAttrName = LdapUtil.attrNameToBinaryTransferAttrName(isBinaryTransfer, name);
Modification mod = new Modification(ModificationType.REPLACE, transferAttrName, valuesToMod.toArray(new ASN1OctetString[valuesToMod.size()]));
modList.add(mod);
}
use of com.unboundid.ldap.sdk.Modification in project cas by apereo.
the class BaseLdapConsentRepositoryTests method verifyAllConsentDecisionsAreFoundForSingleUser.
@Test
public void verifyAllConsentDecisionsAreFoundForSingleUser() throws Exception {
final ConsentDecision decision = BUILDER.build(SVC, REG_SVC, USER_CN, ATTR);
decision.setId(1);
final Modification mod = new Modification(ModificationType.ADD, ATTR_NAME, MAPPER.writeValueAsString(decision));
assertEquals(ResultCode.SUCCESS, getConnection().modify(USER_DN, mod).getResultCode());
final ConsentDecision decision2 = BUILDER.build(SVC, REG_SVC, USER2_CN, ATTR);
decision2.setId(2);
final Modification mod2 = new Modification(ModificationType.ADD, ATTR_NAME, MAPPER.writeValueAsString(decision2));
assertEquals(ResultCode.SUCCESS, getConnection().modify(USER2_DN, mod2).getResultCode());
final Collection<ConsentDecision> d = this.repository.findConsentDecisions(USER_CN);
assertNotNull(d);
assertEquals(1, d.size());
assertEquals(USER_CN, d.iterator().next().getPrincipal());
}
use of com.unboundid.ldap.sdk.Modification in project cas by apereo.
the class BaseLdapConsentRepositoryTests method verifyConsentDecisionIsFound.
@Test
public void verifyConsentDecisionIsFound() throws Exception {
final ConsentDecision decision = BUILDER.build(SVC, REG_SVC, USER_CN, ATTR);
decision.setId(1);
final Modification mod = new Modification(ModificationType.ADD, ATTR_NAME, MAPPER.writeValueAsString(decision));
assertEquals(ResultCode.SUCCESS, getConnection().modify(USER_DN, mod).getResultCode());
final ConsentDecision d = this.repository.findConsentDecision(SVC, REG_SVC, CoreAuthenticationTestUtils.getAuthentication(USER_CN));
assertNotNull(d);
assertEquals(USER_CN, d.getPrincipal());
}
Aggregations