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

The following examples show how to use org.apache.directory.api.ldap.model.message.CompareRequest#setAssertionValue() . 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: Dsmlv2Grammar.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( Dsmlv2Container container ) throws XmlPullParserException
{
    CompareRequest compareRequest = ( CompareRequest ) container.getBatchRequest().getCurrentRequest();

    XmlPullParser xpp = container.getParser();

    try
    {
        // We have to catch the type Attribute Value before going to the next Text node
        String typeValue = ParserUtils.getXsiTypeAttributeValue( xpp );

        // Getting the value
        String nextText = xpp.nextText();

        if ( !Strings.isEmpty( nextText ) )
        {
            if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
            {
                compareRequest.setAssertionValue( Base64.decode( nextText.trim().toCharArray() ) );
            }
            else
            {
                compareRequest.setAssertionValue( nextText.trim() );
            }
        }
    }
    catch ( IOException ioe )
    {
        throw new XmlPullParserException( I18n.err( I18n.ERR_03008_UNEXPECTED_ERROR, ioe.getMessage() ), xpp, ioe );
    }
}
 
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, 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 5
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 6
Source File: StoreCompareRequestAssertionValue.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<CompareRequest> container )
{
    // Get the CompareRequest Object
    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 value
    if ( tlv.getLength() == 0 )
    {
        compareRequest.setAssertionValue( "" );
    }
    else
    {
        if ( container.isBinary( compareRequest.getAttributeId() ) )
        {
            compareRequest.setAssertionValue( tlv.getValue().getData() );

            if ( LOG.isDebugEnabled() )
            {
                LOG.debug( I18n.msg( I18n.MSG_05121_COMPARING_ATTRIBUTE_VALUE, 
                    Strings.dumpBytes( compareRequest.getAssertionValue().getBytes() ) ) );
            }
        }
        else
        {
            compareRequest.setAssertionValue( Strings.utf8ToString( tlv.getValue().getData() ) );

            if ( LOG.isDebugEnabled() )
            {
                LOG.debug( I18n.msg( I18n.MSG_05121_COMPARING_ATTRIBUTE_VALUE, compareRequest.getAssertionValue() ) );
            }
        }
    }

    // We can have an END transition
    container.setGrammarEndAllowed( true );
}