use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.
the class OpenDJUpgrader method findBaseDNs.
private List<DN> findBaseDNs() throws IOException {
final List<DN> baseDNs = new LinkedList<DN>();
final SearchRequest request = LDAPRequests.newSearchRequest("cn=backends,cn=config", SearchScope.WHOLE_SUBTREE, "(objectclass=ds-cfg-backend)", "ds-cfg-base-dn");
try (LDIFEntryReader reader = new LDIFEntryReader(new FileInputStream(installRoot + "/config/config.ldif"))) {
final EntryReader filteredReader = LDIF.search(reader, request);
while (filteredReader.hasNext()) {
final Entry entry = filteredReader.readEntry();
final Attribute values = entry.getAttribute("ds-cfg-base-dn");
if (values != null) {
for (final ByteString value : values) {
baseDNs.add(DN.valueOf(value.toString()));
}
}
}
}
return baseDNs;
}
use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.
the class SMSLdapObject method create.
/**
* Create an entry in the directory using the principal name
*/
private static void create(Principal p, String dn, Map attrs) throws SMSException, SSOException {
int retry = 0;
Entry entry = copyMapToEntry(attrs).setName(dn);
while (retry <= connNumRetry) {
debug.message("SMSLdapObject.create() retry: {}", retry);
try (Connection conn = getConnection(p)) {
conn.add(LDAPRequests.newAddRequest(entry));
debug.message("SMSLdapObject.create Successfully created entry: {}", dn);
break;
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (errorCode.equals(ResultCode.ENTRY_ALREADY_EXISTS) && retry > 0) {
// During install time and other times,
// this error gets throws due to unknown issue. Issue:
// Hence mask it.
debug.warning("SMSLdapObject.create() Entry Already Exists Error for DN {}", dn);
break;
}
if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
debug.error("SMSLdapObject.create() Error in creating: {} By Principal: {}", dn, p.getName(), e);
throw new SMSException(e, "sms-entry-cannot-create");
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
//ignored
}
}
}
}
use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.
the class LdapAdapter method update.
/**
* Update the Token based on whether there were any changes between the two.
*
* @param connection The non null connection to perform this call against.
* @param previous The non null previous Token to check against.
* @param updated The non null Token to update with.
* @return True if the token was updated, or false if there were no changes detected.
* @throws org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException If the operation failed for a known reason.
*/
public boolean update(Connection connection, Token previous, Token updated) throws LdapOperationFailedException {
Entry currentEntry = conversion.getEntry(updated);
LdapTokenAttributeConversion.stripObjectClass(currentEntry);
Entry previousEntry = conversion.getEntry(previous);
LdapTokenAttributeConversion.stripObjectClass(previousEntry);
ModifyRequest request = Entries.diffEntries(previousEntry, currentEntry);
request.addControl(TransactionIdControl.newControl(AuditRequestContext.createSubTransactionIdValue()));
// Test to see if there are any modifications
if (request.getModifications().isEmpty()) {
return false;
}
try {
processResult(connection.modify(request));
} catch (LdapException e) {
throw new LdapOperationFailedException(e.getResult());
}
return true;
}
use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.
the class LdapTokenAttributeConversionTest method shouldStripObjectClass.
@Test
public void shouldStripObjectClass() {
// Given
Entry entry = mock(Entry.class);
Attribute attribute = mock(Attribute.class);
given(entry.getAttribute(anyString())).willReturn(attribute);
AttributeDescription description = AttributeDescription.valueOf("badger");
given(attribute.getAttributeDescription()).willReturn(description);
// When
LdapTokenAttributeConversion.stripObjectClass(entry);
// Then
verify(entry).removeAttribute(description);
}
use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.
the class LdapTokenAttributeConversionTest method shouldAddObjectClass.
@Test
public void shouldAddObjectClass() {
// Given
Entry entry = mock(Entry.class);
given(entry.getAttribute(anyString())).willReturn(null);
// When
LdapTokenAttributeConversion.addObjectClass(entry);
// Then
verify(entry).addAttribute(anyString(), any());
}
Aggregations