org.apache.directory.api.ldap.model.entry.Value Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.entry.Value. 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: ApiLdapModelOsgiTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Override
protected void useBundleClasses() throws Exception
{
    new Dn( "dc=example,dc=com" ); // uses FastDnParser
    new Dn( "cn=a+sn=b,dc=example,dc=com" ); // uses ComplexDnparser (antlr based)
    new Value( "foo" );
    new DefaultAttribute( "cn" );
    new DefaultEntry();

    AttributeUtils.toJndiAttribute( new DefaultAttribute( "cn" ) );
    
    new BindRequestImpl();

    new EqualityNode<String>( "cn", "foo" );

    new LdapUrl( "ldap://ldap.example.com:10389/dc=example,dc=com?objectclass" );

    new ObjectClassDescriptionSchemaParser()
        .parse( "( 2.5.6.0 NAME 'top' DESC 'top of the superclass chain' ABSTRACT MUST objectClass )" );
    
    SchemaObject schemaObject = new LdapSyntax( "1.2.3" );
    new Registries().getGlobalOidRegistry().register( schemaObject );
    new Registries().getLoadedSchemas();
}
 
Example #2
Source File: SearchResultEntryFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Encode the values recursively
 *
 * <pre>
 * 0x04 LL attributeValue
 * ...
 * 0x04 LL attributeValue
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 * @param values The iterator on the values
 */
private void encodeValues( Asn1Buffer buffer, Iterator<Value> values )
{
    if ( values.hasNext() )
    {
        Value value = values.next();

        encodeValues( buffer, values );

        // The value
        if ( value.isHumanReadable() )
        {
            BerValue.encodeOctetString( buffer, value.getString() );
        }
        else
        {
            BerValue.encodeOctetString( buffer, value.getBytes() );
        }
    }
}
 
Example #3
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * Method wraps ldap client to return multivalued attribute by name within a given entry and returns
 * as a list of strings.
 *
 * @param entry         contains the target ldap entry.
 * @param attributeName name of ldap attribute to retrieve.
 * @return List of type string containing attribute values.
 */
protected List<String> getAttributes( Entry entry, String attributeName )
{
    List<String> attrValues = new ArrayList<>();
    if ( entry != null )
    {
        Attribute attr = entry.get( attributeName );
        if ( attr != null )
        {
            for ( Value<?> value : attr )
            {
                attrValues.add( value.getString() );
            }
        }
        else
        {
            return null;
        }
    }

    return attrValues;
}
 
Example #4
Source File: Ava.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a schema aware Ava. The AttributeType and value will be checked accordingly
 * to the SchemaManager.
 * <p>
 * Note that the upValue should <b>not</b> be null or empty, or resolve
 * to an empty string after having trimmed it.
 *
 * @param schemaManager The SchemaManager instance
 * @param upType The User Provided type
 * @param value The value
 */
private void createAva( SchemaManager schemaManager, String upType, Value value )
{
    StringBuilder sb = new StringBuilder();

    normType = attributeType.getOid();
    this.upType = upType;
    this.value = value;
    
    sb.append( upType );
    sb.append( '=' );
    
    if ( value != null )
    {
        sb.append( Rdn.escapeValue( value.getString() ) );
    }
    
    upName = sb.toString();

    hashCode();
}
 
Example #5
Source File: AddRequestDsml.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Add a new value to the current attribute
 * 
 * @param value The value to be added
 * @throws LdapException If we can't add a new value
 */
public void addAttributeValue( Object value ) throws LdapException
{
    if ( value instanceof Value )
    {
        ( ( AddRequestDsml ) getDecorated() ).addAttributeValue( ( Value ) value );
    }
    else if ( value instanceof String )
    {
        ( ( AddRequestDsml ) getDecorated() ).addAttributeValue( ( String ) value );
    }
    else if ( value instanceof byte[] )
    {
        ( ( AddRequestDsml ) getDecorated() ).addAttributeValue( ( byte[] ) value );
    }
}
 
Example #6
Source File: DefaultSchemaLoader.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
private void loadLdapSyntaxes( Attribute ldapSyntaxes ) throws LdapException
{
    if ( ldapSyntaxes == null )
    {
        return;
    }

    for ( Value value : ldapSyntaxes )
    {
        String desc = value.getString();

        try
        {
            LdapSyntax ldapSyntax = LS_DESCR_SCHEMA_PARSER.parse( desc );

            updateSchemas( ldapSyntax );
        }
        catch ( ParseException pe )
        {
            throw new LdapException( pe );
        }
    }
}
 
Example #7
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
private Set<String> getAllMust( Attribute objectClasses ) throws LdapException
{
    Set<String> must = new HashSet<String>();

    // Loop on all objectclasses
    for ( Value<?> value : objectClasses )
    {
        String ocName = value.getString();
        ObjectClass oc = schemaManager.lookupObjectClassRegistry( ocName );

        List<AttributeType> types = oc.getMustAttributeTypes();

        // For each objectClass, loop on all MUST attributeTypes, if any
        if ( ( types != null ) && ( types.size() > 0 ) )
        {
            for ( AttributeType type : types )
            {
                must.add( type.getOid() );
            }
        }
    }

    return must;
}
 
Example #8
Source File: ParserUtils.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Indicates if the value needs to be encoded as Base64
 *
 * @param value the value to check
 * @return true if the value needs to be encoded as Base64
 */
public static boolean needsBase64Encoding( Object value )
{
    if ( value instanceof Value )
    {
        return false;
    }
    else if ( value instanceof byte[] )
    {
        return true;
    }
    else if ( value instanceof String )
    {
        return !LdifUtils.isLDIFSafe( ( String ) value );
    }

    return true;
}
 
Example #9
Source File: CompareRequestImpl.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public CompareRequest setAssertionValue( String value )
{
    this.attrVal = new Value( value );

    return this;
}
 
Example #10
Source File: LdapUserManager.java    From azkaban-ldap-usermanager with MIT License 5 votes vote down vote up
/**
 * Tests if the attribute contains a given value (case insensitive)
 *
 * @param expected the expected value
 * @param attribute the attribute encapsulating a list of values
 * @return a value indicating if the attribute contains a value which matches expected
 */
private boolean attributeContainsNormalized(String expected, Attribute attribute) {
    if (expected == null) {
        return false;
    }
    for (Value value : attribute) {
        if (value.toString().toLowerCase().equals(expected.toLowerCase())) {
            return true;
        }
    }
    return false;
}
 
Example #11
Source File: GreaterEqNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new GreaterOrEqual object.
 * 
 * @param attributeType the attributeType
 * @param value the value to test for
 * @throws LdapSchemaException If the AttributeType does not have an ORDERING MatchingRule
 */
public GreaterEqNode( AttributeType attributeType, Value value ) throws LdapSchemaException
{
    super( attributeType, value, AssertionType.GREATEREQ );

    // Check if the AttributeType has an Ordering MR
    if ( ( attributeType != null ) && ( attributeType.getOrdering() == null ) )
    {
        throw new LdapSchemaException( I18n.err( I18n.ERR_13301_NO_ORDERING_MR_FOR_AT, attributeType.getName() ) );
    }
}
 
Example #12
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private Value<?> convertToValue( String oid, Object value ) throws LdapException
{
    Value<?> val = null;

    AttributeType attributeType = directoryService.getSchemaManager().lookupAttributeTypeRegistry( oid );

    // make sure we add the request controls to operation
    if ( attributeType.getSyntax().isHumanReadable() )
    {
        if ( value instanceof String )
        {
            val = new StringValue( attributeType, ( String ) value );
        }
        else if ( value instanceof byte[] )
        {
            val = new StringValue( attributeType, Strings.utf8ToString( ( byte[] ) value ) );
        }
        else
        {
            throw new LdapException( I18n.err( I18n.ERR_309, oid ) );
        }
    }
    else
    {
        if ( value instanceof String )
        {
            val = new BinaryValue( attributeType, Strings.getBytesUtf8( ( String ) value ) );
        }
        else if ( value instanceof byte[] )
        {
            val = new BinaryValue( attributeType, ( byte[] ) value );
        }
        else
        {
            throw new LdapException( I18n.err( I18n.ERR_309, oid ) );
        }
    }

    return val;
}
 
Example #13
Source File: SearchResultEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 1 Attr 2 Value
 */
@Test
public void testResponseWith1Attr2Value()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput(
            SearchResultEntryTest.class.getResource( "response_with_1_attr_2_value.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse()
        .getDecorated() )
        .getCurrentSearchResultEntry();

    Entry entry = searchResultEntry.getEntry();
    assertEquals( 1, entry.size() );

    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );
    assertEquals( 2, attribute.size() );

    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "top", value.getString() );
    assertTrue( valueIterator.hasNext() );
    value = valueIterator.next();
    assertEquals( "domain", value.getString() );
    assertFalse( valueIterator.hasNext() );
}
 
Example #14
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private Value<?> convertToValue( String oid, Object value ) throws LdapException
{
    Value<?> val = null;

    AttributeType attributeType = directoryService.getSchemaManager().lookupAttributeTypeRegistry( oid );

    // make sure we add the request controls to operation
    if ( attributeType.getSyntax().isHumanReadable() )
    {
        if ( value instanceof String )
        {
            val = new StringValue( attributeType, ( String ) value );
        }
        else if ( value instanceof byte[] )
        {
            val = new StringValue( attributeType, Strings.utf8ToString( ( byte[] ) value ) );
        }
        else
        {
            throw new LdapException( I18n.err( I18n.ERR_309, oid ) );
        }
    }
    else
    {
        if ( value instanceof String )
        {
            val = new BinaryValue( attributeType, Strings.getBytesUtf8( ( String ) value ) );
        }
        else if ( value instanceof byte[] )
        {
            val = new BinaryValue( attributeType, ( byte[] ) value );
        }
        else
        {
            throw new LdapException( I18n.err( I18n.ERR_309, oid ) );
        }
    }

    return val;
}
 
Example #15
Source File: SearchResultEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 1 Attr 1 Base64 Value
 */
@Test
public void testResponseWith1Attr1Base64Value()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( SearchResultEntryTest.class.getResource( "response_with_1_attr_1_base64_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse()
        .getDecorated() )
        .getCurrentSearchResultEntry();

    Entry entry = searchResultEntry.getEntry();
    assertEquals( 1, entry.size() );

    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "cn", attribute.getUpId() );
    assertEquals( 1, attribute.size() );

    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();

    String expected = new String( new byte[]
        { 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', 'L', ( byte ) 0xc3, ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n',
            'y' }, StandardCharsets.UTF_8 );
    assertEquals( expected, value.getString() );
}
 
Example #16
Source File: SearchResultEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 1 Attr 1 Value
 */
@Test
public void testResponseWith1Attr1Value()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput(
            SearchResultEntryTest.class.getResource( "response_with_1_attr_1_value.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse()
        .getDecorated() )
        .getCurrentSearchResultEntry();

    Entry entry = searchResultEntry.getEntry();
    assertEquals( 1, entry.size() );

    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "dc", attribute.getUpId() );

    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "example", value.getString() );
}
 
Example #17
Source File: Rdn.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * A constructor that constructs a schema aware Rdn from a type and a value.
 * <p>
 * The string attribute values are not interpreted as RFC 414 formatted Rdn
 * strings. That is, the values are used literally (not parsed) and assumed
 * to be un-escaped.
  *
 * @param schemaManager the schema manager
 * @param upType the user provided type of the Rdn
 * @param upValue the user provided value of the Rdn
 * @throws LdapInvalidDnException if the Rdn is invalid
 * @throws LdapInvalidAttributeValueException  If the given AttributeType or value are invalid
 */
public Rdn( SchemaManager schemaManager, String upType, String upValue ) throws LdapInvalidDnException, LdapInvalidAttributeValueException
{
    if ( schemaManager != null )
    {
        AttributeType attributeType = schemaManager.getAttributeType( upType );
        addAVA( schemaManager, upType, new Value( attributeType, upValue ) );
    }
    else
    {
        addAVA( schemaManager, upType, new Value( upValue ) );
    }

    StringBuilder sb = new StringBuilder();
    sb.append( upType ).append( '=' ).append( upValue );
    upName = sb.toString();
    
    sb.setLength( 0 );
    sb.append( ava.getNormType() ).append( '=' );
    
    Value value = ava.getValue();
    
    if ( value != null )
    {
        sb.append( value.getNormalized() );
    }
    
    normName = sb.toString();
    normalized = true;

    hashCode();
}
 
Example #18
Source File: CompareRequestImpl.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public CompareRequest setAssertionValue( byte[] value )
{
    if ( value != null )
    {
        this.attrVal = new Value( value );
    }
    else
    {
        this.attrVal = null;
    }

    return this;
}
 
Example #19
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Check a String attribute to see if there is some byte[] value in it.
 *
 * If this is the case, try to change it to a String value.
 */
private boolean checkHumanReadable( Attribute attribute ) throws LdapException
{
    boolean isModified = false;

    // Loop on each values
    for ( Value<?> value : attribute )
    {
        if ( value instanceof StringValue )
        {
            continue;
        }
        else if ( value instanceof BinaryValue )
        {
            // we have a byte[] value. It should be a String UTF-8 encoded
            // Let's transform it
            try
            {
                String valStr = new String( value.getBytes(), "UTF-8" );
                attribute.remove( value );
                attribute.add( valStr );
                isModified = true;
            }
            catch ( UnsupportedEncodingException uee )
            {
                throw new LdapException( I18n.err( I18n.ERR_281 ) );
            }
        }
        else
        {
            throw new LdapException( I18n.err( I18n.ERR_282 ) );
        }
    }

    return isModified;
}
 
Example #20
Source File: AttributeUtilsTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the replacement by modification of an attribute in an empty entry.
 * 
 * As we are replacing a non existing attribute, it should not change the entry.
 *
 * @throws LdapException
 */
@Test
public void testApplyModifyAttributeModification() throws LdapException
{
    Entry entry = new DefaultEntry();
    entry.put( "cn", "test" );
    entry.put( "ou", "apache", "acme corp" );

    Attribute newOu = new DefaultAttribute( "ou", "Big Company", "directory" );

    Modification modification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, newOu );

    AttributeUtils.applyModification( entry, modification );

    assertEquals( 2, entry.size() );

    assertNotNull( entry.get( "cn" ) );
    assertNotNull( entry.get( "ou" ) );

    Attribute modifiedAttr = entry.get( "ou" );

    assertTrue( modifiedAttr.size() != 0 );

    Set<String> expectedValues = new HashSet<String>();
    expectedValues.add( "Big Company" );
    expectedValues.add( "directory" );

    for ( Value value : modifiedAttr )
    {
        String valueStr = value.getString();

        assertTrue( expectedValues.contains( valueStr ) );

        expectedValues.remove( valueStr );
    }

    assertEquals( 0, expectedValues.size() );
}
 
Example #21
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void init( DirectoryService directoryService ) throws LdapException
{
    super.init( directoryService );
    nexus = directoryService.getPartitionNexus();
    Value<?> attr = nexus.getRootDse( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
    subschemSubentryDn = directoryService.getDnFactory().create( attr.getString() );
}
 
Example #22
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private LdapReferralException buildReferralException( Entry parentEntry, Dn childDn ) throws LdapException
{
    // Get the Ref attributeType
    Attribute refs = parentEntry.get( SchemaConstants.REF_AT );

    List<String> urls = new ArrayList<String>();

    try
    {
        // manage each Referral, building the correct URL for each of them
        for ( Value<?> url : refs )
        {
            // we have to replace the parent by the referral
            LdapUrl ldapUrl = new LdapUrl( url.getString() );

            // We have a problem with the Dn : we can't use the UpName,
            // as we may have some spaces around the ',' and '+'.
            // So we have to take the Rdn one by one, and create a
            // new Dn with the type and value UP form

            Dn urlDn = ldapUrl.getDn().add( childDn );

            ldapUrl.setDn( urlDn );
            urls.add( ldapUrl.toString() );
        }
    }
    catch ( LdapURLEncodingException luee )
    {
        throw new LdapOperationErrorException( luee.getMessage(), luee );
    }

    // Return with an exception
    LdapReferralException lre = new LdapReferralException( urls );
    lre.setRemainingDn( childDn );
    lre.setResolvedDn( parentEntry.getDn() );
    lre.setResolvedObject( parentEntry );

    return lre;
}
 
Example #23
Source File: LDAPApi.java    From mamute with Apache License 2.0 5 votes vote down vote up
private List<String> getGroups(Entry user) {
	List<String> groupCns = new ArrayList<>();
	if (isNotEmpty(groupAttr)) {
		Attribute grpEntry = user.get(groupAttr);
		if (grpEntry != null) {
			for (Value<?> grp : grpEntry) {
				groupCns.add(grp.getString());
			}
		}
	}
	return groupCns;
}
 
Example #24
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Check the entry attributes syntax, using the syntaxCheckers
 */
private void assertSyntaxes( Entry entry ) throws LdapException
{
    // First, loop on all attributes
    for ( Attribute attribute : entry )
    {
        AttributeType attributeType = attribute.getAttributeType();
        SyntaxChecker syntaxChecker = attributeType.getSyntax().getSyntaxChecker();

        if ( syntaxChecker instanceof OctetStringSyntaxChecker )
        {
            // This is a speedup : no need to check the syntax of any value
            // if all the syntaxes are accepted...
            continue;
        }

        // Then loop on all values
        for ( Value<?> value : attribute )
        {
            if ( value.isSchemaAware() )
            {
                // No need to validate something which is already ok
                continue;
            }

            try
            {
                syntaxChecker.assertSyntax( value.getValue() );
            }
            catch ( Exception ne )
            {
                String message = I18n.err( I18n.ERR_280, value.getString(), attribute.getUpId() );
                LOG.info( message );

                throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, message );
            }
        }
    }
}
 
Example #25
Source File: Ava.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Construct an Ava. The type and value are normalized :
 * <ul>
 *   <li> the type is trimmed and lowercased </li>
 *   <li> the value is trimmed </li>
 * </ul>
 * <p>
 * Note that the upValue should <b>not</b> be null or empty, or resolved
 * to an empty string after having trimmed it.
 *
 * @param schemaManager The SchemaManager
 * @param upType The User Provided type
 * @param normType The normalized type
 * @param value The value
 * 
 * @throws LdapInvalidDnException If the given type or value are invalid
 */
// WARNING : The protection level is left unspecified intentionally.
// We need this method to be visible from the DnParser class, but not
// from outside this package.
/* Unspecified protection */Ava( SchemaManager schemaManager, String upType, String normType, Value value )
    throws LdapInvalidDnException
{
    StringBuilder sb = new StringBuilder();

    this.upType = upType;
    this.normType = normType;
    this.value = value;
    
    sb.append( upType );
    sb.append( '=' );
    
    if ( ( value != null ) && ( value.getString() != null ) )
    {
        sb.append( value.getString() );
    }
    
    upName = sb.toString();

    if ( schemaManager != null )
    {
        apply( schemaManager );
    }

    hashCode();
}
 
Example #26
Source File: Rdn.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
private void buildNormRdn( StringBuilder sb, Ava ava )
{
    sb.append( ava.getNormType() );
    
    sb.append( '=' );
    
    Value val = ava.getValue();
    
    if ( ( val != null ) && ( val.getNormalized() != null ) ) 
    {
        sb.append( ava.getValue().getNormalized() );
    }
}
 
Example #27
Source File: AttributeValueAssertion.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to render an object which can be a String or a byte[]
 *
 * @param object the Object to render
 * @return A string representing the object
 */
public static String dumpObject( Object object )
{
    if ( object != null )
    {
        if ( object instanceof String )
        {
            return ( String ) object;
        }
        else if ( object instanceof byte[] )
        {
            return Strings.dumpBytes( ( byte[] ) object );
        }
        else if ( object instanceof Value )
        {
            return ( ( Value ) object ).getString();
        }
        else
        {
            return "<unknown type>";
        }
    }
    else
    {
        return "";
    }
}
 
Example #28
Source File: LdifAnonymizerTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnonymizerModifyBinaryOptionAttribute() throws LdapException, IOException
{
    String ldif = 
        "dn: cn=Acme certificate,o=Acme,c=US,ou=IT Infrastructure,o=acme.com\n" +
        "changetype: modify\n" +
        "replace: certificateRevocationList;binary\n" +
        "certificateRevocationList;binary::YmxhaCBibGFo\n" +
        "-";

    LdifAnonymizer anonymizer = new LdifAnonymizer( schemaManager );
    anonymizer.addNamingContext( "o=acme.com" );
    String result = anonymizer.anonymize( ldif );
    
    List<LdifEntry> entries = ldifReader.parseLdif( result );
    
    assertEquals( 1, entries.size() );
    
    LdifEntry entry = entries.get( 0 );
    assertTrue( entry.isChangeModify() );
    assertEquals( 1, entry.getModifications().size() );
    
    Modification modification = entry.getModifications().get( 0 );
    assertEquals( ModificationOperation.REPLACE_ATTRIBUTE, modification.getOperation() );

    Attribute attribute = modification.getAttribute();
    assertEquals( "certificateRevocationList;binary", attribute.getUpId() );
    assertEquals( 1, attribute.size() );
    
    for ( Value value : attribute )
    {
        String str = value.getString();
        
        // We can only test the length and the fact the values are not equal (as the vale has been anonymized)
        assertNotSame( 0, value.length() );
        assertEquals( str.length(), value.length() );
    }
}
 
Example #29
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private boolean getObjectClasses( Attribute objectClasses, List<ObjectClass> result ) throws LdapException
{
    Set<String> ocSeen = new HashSet<String>();

    // We must select all the ObjectClasses, except 'top',
    // but including all the inherited ObjectClasses
    boolean hasExtensibleObject = false;

    for ( Value<?> objectClass : objectClasses )
    {
        String objectClassName = objectClass.getString();

        if ( SchemaConstants.TOP_OC.equals( objectClassName ) )
        {
            continue;
        }

        if ( SchemaConstants.EXTENSIBLE_OBJECT_OC.equalsIgnoreCase( objectClassName ) )
        {
            hasExtensibleObject = true;
        }

        ObjectClass oc = schemaManager.lookupObjectClassRegistry( objectClassName );

        // Add all unseen objectClasses to the list, except 'top'
        if ( !ocSeen.contains( oc.getOid() ) )
        {
            ocSeen.add( oc.getOid() );
            result.add( oc );
        }

        // Find all current OC parents
        getSuperiors( oc, ocSeen, result );
    }

    return hasExtensibleObject;
}
 
Example #30
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Value<?> getRootDseValue( AttributeType attributeType )
{
    Value<?> value = rootDse.get( attributeType ).get();

    return value.clone();
}