Search in sources :

Example 1 with LdapOperationFailedException

use of org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException 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;
}
Also used : Entry(org.forgerock.opendj.ldap.Entry) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) LdapOperationFailedException(org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 2 with LdapOperationFailedException

use of org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException in project OpenAM by OpenRock.

the class CreateTaskTest method shouldHandleException.

@Test(expectedExceptions = DataLayerException.class)
public void shouldHandleException() throws Exception {
    doThrow(new LdapOperationFailedException("test")).when(mockAdapter).create(any(Connection.class), any(Token.class));
    task.execute(mockConnection, mockAdapter);
    verify(mockHandler).processError(any(CoreTokenException.class));
}
Also used : LdapOperationFailedException(org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException) Connection(org.forgerock.opendj.ldap.Connection) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 3 with LdapOperationFailedException

use of org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException in project OpenAM by OpenRock.

the class LdapAdapterTest method shouldThrowAllOtherExceptionsDuringDelete.

@Test
public void shouldThrowAllOtherExceptionsDuringDelete() throws Exception {
    // Given
    String tokenId = "badger";
    DN testDN = DN.rootDN();
    LdapException exception = LdapException.newLdapException(ResultCode.OTHER);
    given(mockConnection.delete(any(DeleteRequest.class))).willThrow(exception);
    given(mockConversion.generateTokenDN(anyString())).willReturn(testDN);
    // When / Then
    try {
        adapter.delete(mockConnection, tokenId);
        fail();
    } catch (LdapOperationFailedException e) {
    }
}
Also used : LdapOperationFailedException(org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException) DN(org.forgerock.opendj.ldap.DN) LdapException(org.forgerock.opendj.ldap.LdapException) DeleteRequest(org.forgerock.opendj.ldap.requests.DeleteRequest) Test(org.testng.annotations.Test)

Example 4 with LdapOperationFailedException

use of org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException in project OpenAM by OpenRock.

the class DeleteTaskTest method shouldHandleException.

@Test(expectedExceptions = DataLayerException.class)
public void shouldHandleException() throws Exception {
    doThrow(new LdapOperationFailedException("test")).when(mockAdapter).delete(any(Connection.class), anyString());
    task.execute(mockConnection, mockAdapter);
    verify(mockResultHandler).processError(any(CoreTokenException.class));
}
Also used : LdapOperationFailedException(org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException) Connection(org.forgerock.opendj.ldap.Connection) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Test(org.testng.annotations.Test)

Aggregations

LdapOperationFailedException (org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException)4 Test (org.testng.annotations.Test)3 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)2 Connection (org.forgerock.opendj.ldap.Connection)2 LdapException (org.forgerock.opendj.ldap.LdapException)2 Token (org.forgerock.openam.cts.api.tokens.Token)1 DN (org.forgerock.opendj.ldap.DN)1 Entry (org.forgerock.opendj.ldap.Entry)1 DeleteRequest (org.forgerock.opendj.ldap.requests.DeleteRequest)1 ModifyRequest (org.forgerock.opendj.ldap.requests.ModifyRequest)1 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)1