Java Code Examples for org.apache.directory.api.ldap.model.message.CompareRequest#setName()

The following examples show how to use org.apache.directory.api.ldap.model.message.CompareRequest#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( Dn dn, String attributeName, Value value ) throws LdapException
{
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( dn );
    compareRequest.setAttributeId( attributeName );

    if ( value.isHumanReadable() )
    {
        compareRequest.setAssertionValue( value.getString() );
    }
    else
    {
        compareRequest.setAssertionValue( value.getBytes() );
    }

    CompareResponse compareResponse = compare( compareRequest );

    return processResponse( compareResponse );
}
 
Example 2
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * This method uses the compare ldap func to assert audit record into the directory server's configured audit
 * logger.
 *
 * This is for one reason - to force the ldap server to maintain an audit trail on checkAccess api.
 *
 * Use proxy authz control (RFC4370) to assert the caller's id onto the record.
 *
 * @param connection is LdapConnection object used for all communication with host.
 * @param dn         contains address of distinguished name to begin ldap search
 * @param userDn     dn for user node
 * @param attribute  attribute used for compare
 * @return true if compare operation succeeds
 * @throws LdapException                thrown in the event of error in ldap client or server code.
 * @throws UnsupportedEncodingException in the event the server cannot perform the operation.
 */
protected boolean compareNode( LdapConnection connection, String dn, String userDn,
    Attribute attribute ) throws LdapException, UnsupportedEncodingException
{
    COUNTERS.incrementCompare();

    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( new Dn( dn ) );
    compareRequest.setAttributeId( attribute.getId() );
    compareRequest.setAssertionValue( attribute.getString() );

    // Assert the end user's dn onto the reqest using proxy authZ control so openldap can log who the user was (for authZ audit trail)
    ProxiedAuthz proxiedAuthzControl = new ProxiedAuthzImpl();
    proxiedAuthzControl.setAuthzId( "dn: " + userDn );
    compareRequest.addControl( proxiedAuthzControl );
    CompareResponse response = connection.compare( compareRequest );
    return response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS;
}
 
Example 3
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( Dn dn, String attributeName, String value ) throws LdapException
{
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( dn );
    compareRequest.setAttributeId( attributeName );
    compareRequest.setAssertionValue( value );

    CompareResponse compareResponse = compare( compareRequest );

    return processResponse( compareResponse );
}
 
Example 4
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( Dn dn, String attributeName, byte[] value ) throws LdapException
{
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( dn );
    compareRequest.setAttributeId( attributeName );
    compareRequest.setAssertionValue( value );

    CompareResponse compareResponse = compare( compareRequest );

    return processResponse( compareResponse );
}
 
Example 5
Source File: StoreCompareRequestEntryName.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<CompareRequest> container ) throws DecoderException
{
    CompareRequest compareRequest = container.getMessage();

    // Get the Value and store it in the CompareRequest
    TLV tlv = container.getCurrentTLV();

    // We have to handle the special case of a 0 length matched Dn
    if ( tlv.getLength() == 0 )
    {
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException( I18n.err( I18n.ERR_05119_NULL_ENTRY ) );
    }
    else
    {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString( dnBytes );

        try
        {
            Dn entry = new Dn( dnStr );
            compareRequest.setName( entry );
        }
        catch ( LdapInvalidDnException ine )
        {
            String msg = I18n.err( I18n.ERR_05113_INVALID_DN, dnStr, Strings.dumpBytes( dnBytes ) );
            LOG.error( I18n.err( I18n.ERR_05114_ERROR_MESSAGE, msg, ine.getMessage() ) );

            CompareResponseImpl response = new CompareResponseImpl( compareRequest.getMessageId() );
            throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                Dn.EMPTY_DN, ine );
        }
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05123_COMPARING_DN, compareRequest.getName() ) );
    }
}