Search in sources :

Example 11 with Modification

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);
    }
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Map(java.util.Map)

Example 12 with Modification

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);
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Modification(com.unboundid.ldap.sdk.Modification) ASN1OctetString(com.unboundid.asn1.ASN1OctetString)

Example 13 with Modification

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);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Modification(com.unboundid.ldap.sdk.Modification) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString)

Example 14 with Modification

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());
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with Modification

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());
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Modification (com.unboundid.ldap.sdk.Modification)19 Test (org.junit.Test)12 LdapKeyManager (com.gitblit.transport.ssh.LdapKeyManager)6 SshKey (com.gitblit.transport.ssh.SshKey)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 SearchResult (com.unboundid.ldap.sdk.SearchResult)3 ArrayList (java.util.ArrayList)2 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 Signature (java.security.Signature)1 ParseException (java.text.ParseException)1 LocalDateTime (java.time.LocalDateTime)1 Comparator (java.util.Comparator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)1 MappingException (org.gluu.persist.exception.mapping.MappingException)1 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)1 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)1