org.apache.directory.api.ldap.model.schema.AttributeType Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.schema.AttributeType. 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: SearchParams.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Normalize the ReturningAttributes. It reads all the String from the returningAttributesString,
 * and grab the associated AttributeType from the schema to store it into the returningAttributes
 * Set.
 *
 * @param schemaManager The schema manager
 */
public void normalize( SchemaManager schemaManager )
{
    for ( String returnAttribute : returningAttributesStr )
    {
        try
        {
            String id = SchemaUtils.stripOptions( returnAttribute );
            Set<String> options = SchemaUtils.getOptions( returnAttribute );

            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
            AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType, options );

            returningAttributes.add( attrOptions );
        }
        catch ( LdapException ne )
        {
            if ( LOG.isWarnEnabled() )
            {
                LOG.warn( I18n.msg( I18n.MSG_13500_ATTRIBUTE_NOT_IN_SCHEMA, returnAttribute ) );
            }
            
            // Unknown attributes should be silently ignored, as RFC 2251 states
        }
    }
}
 
Example #2
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the contains() method
 */
@Test
public void testContains() throws Exception
{
    AttributeType at = TestEntryUtils.getIA5StringAttributeType();

    DefaultAttribute attr = new DefaultAttribute( at );

    attr.add( "Test  1" );
    attr.add( "Test  2" );
    attr.add( "Test  3" );

    assertTrue( attr.contains( "test 1" ) );
    assertTrue( attr.contains( "Test 2" ) );
    assertTrue( attr.contains( "TEST     3" ) );
}
 
Example #3
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void modify( ModifyOperationContext modifyContext ) throws LdapException
{
    Dn dn = modifyContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        modifyContext.setDn( new Dn( schemaManager, dn ) );
    }

    if ( modifyContext.getModItems() != null )
    {
        for ( Modification modification : modifyContext.getModItems() )
        {
            AttributeType attributeType = schemaManager.getAttributeType( modification.getAttribute().getId() );
            modification.apply( attributeType );
        }
    }

    next( modifyContext );
}
 
Example #4
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean contains( AttributeType attributeType, String... values )
{
    if ( attributeType == null )
    {
        return false;
    }

    Attribute attribute = attributes.get( attributeType.getOid() );

    if ( attribute != null )
    {
        return attribute.contains( values );
    }
    else
    {
        return false;
    }
}
 
Example #5
Source File: DefaultSchemaLoader.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
private void loadAttributeTypes( Attribute attributeTypes ) throws LdapException
{
    if ( attributeTypes == null )
    {
        return;
    }

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

        try
        {
            AttributeType attributeType = AT_DESCR_SCHEMA_PARSER.parse( desc );

            updateSchemas( attributeType );
        }
        catch ( ParseException pe )
        {
            throw new LdapException( pe );
        }
    }
}
 
Example #6
Source File: AttributeTypeDescriptionSchemaParserRelaxedTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Tests without EQUALITY
 * 
 * @throws ParseException
 */
@Test
public void testNoqualityMR() throws ParseException
{
    String value = "( 2.5.4.58 NAME 'attributeCertificateAttribute' " + "DESC 'attribute certificate use ;binary' "
        + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 ) ";
    AttributeType attributeType = parser.parse( value );

    assertEquals( "2.5.4.58", attributeType.getOid() );
    assertEquals( 1, attributeType.getNames().size() );
    assertEquals( "attributeCertificateAttribute", attributeType.getNames().get( 0 ) );
    assertEquals( "attribute certificate use ;binary", attributeType.getDescription() );
    assertNull( attributeType.getSuperiorOid() );
    assertNull( attributeType.getEqualityOid() );
    assertEquals( "1.3.6.1.4.1.1466.115.121.1.8", attributeType.getSyntaxOid() );
    assertEquals( UsageEnum.USER_APPLICATIONS, attributeType.getUsage() );
    assertEquals( 0, attributeType.getExtensions().size() );
}
 
Example #7
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Delete an existing AT referenced by some other OC
 */
@Test
public void testDeleteExistingAttributeTypeUsedByOC() throws Exception
{
    SchemaManager schemaManager = loadSchema( "Core" );

    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    // Try to delete an AT which is referenced by at least one OC
    // (modifiersName has one descendant : schemaModifiersName)
    AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( "cn" );

    // It should fail
    assertFalse( schemaManager.delete( attributeType ) );

    assertTrue( isAttributeTypePresent( schemaManager, "cn" ) );
    assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #8
Source File: StringValueAttributeTypeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the getNormValue method
 */
@Test
public void testGetNormalizedValue() throws LdapInvalidAttributeValueException
{
    AttributeType attribute = EntryUtils.getIA5StringAttributeType();

    Value sv = new Value( attribute, (String)null );

    assertTrue( sv.isSchemaAware() );
    assertNull( sv.getString() );
    assertTrue( sv.isSchemaAware() );

    sv = new Value( attribute, "" );
    assertTrue( sv.isSchemaAware() );
    assertEquals( 0, sv.compareTo( "  " ) );
    assertTrue( sv.isSchemaAware() );

    sv = new Value( attribute, "TEST" );
    assertTrue( sv.isSchemaAware() );
    assertEquals( 0, sv.compareTo( " test " ) );
}
 
Example #9
Source File: AttributeTypeRegistryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnregister() throws LdapException
{
    AttributeType at0 = new AttributeType( "1.1" );
    at0.addName( "t", "test", "Test", "T" );
    atRegistry.register( at0 );

    atRegistry.unregister( "1.1" );
    assertFalse( atRegistry.contains( "1.1" ) );
    assertFalse( atRegistry.contains( "t" ) );
    assertFalse( atRegistry.contains( "T" ) );
    assertFalse( atRegistry.contains( "tEsT" ) );

    try
    {
        atRegistry.getOidByName( "T" );
        fail();
    }
    catch ( LdapException ne )
    {
        assertTrue( true );
    }
}
 
Example #10
Source File: ProtectedItem_AttributeTypeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize name instances
 */
@BeforeEach
public void initNames() throws Exception
{
    Set<AttributeType> colA = new HashSet<AttributeType>();
    colA.add( new AttributeType( "aa" ) );
    colA.add( new AttributeType( "bb" ) );
    colA.add( new AttributeType( "cc" ) );
    Set<AttributeType> colB = new HashSet<AttributeType>();
    colB.add( new AttributeType( "aa" ) );
    colB.add( new AttributeType( "bb" ) );
    colB.add( new AttributeType( "cc" ) );
    Set<AttributeType> colC = new HashSet<AttributeType>();
    colC.add( new AttributeType( "bb" ) );
    colC.add( new AttributeType( "cc" ) );
    colC.add( new AttributeType( "dd" ) );

    attributeTypeA = new AttributeTypeItem( colA );
    attributeTypeACopy = new AttributeTypeItem( colA );
    attributeTypeB = new AttributeTypeItem( colB );
    attributeTypeC = new AttributeTypeItem( colC );
}
 
Example #11
Source File: ProtectedItem_AllAttributeValuesTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize name instances
 */
@BeforeEach
public void initNames() throws Exception
{
    Set<AttributeType> colA = new HashSet<AttributeType>();
    colA.add( new AttributeType( "aa" ) );
    colA.add( new AttributeType( "bb" ) );
    colA.add( new AttributeType( "cc" ) );
    Set<AttributeType> colB = new HashSet<AttributeType>();
    colB.add( new AttributeType( "aa" ) );
    colB.add( new AttributeType( "bb" ) );
    colB.add( new AttributeType( "cc" ) );
    Set<AttributeType> colC = new HashSet<AttributeType>();
    colC.add( new AttributeType( "bb" ) );
    colC.add( new AttributeType( "cc" ) );
    colC.add( new AttributeType( "dd" ) );

    allAttributeValuesA = new AllAttributeValuesItem( colA );
    allAttributeValuesACopy = new AllAttributeValuesItem( colA );
    allAttributeValuesB = new AllAttributeValuesItem( colB );
    allAttributeValuesC = new AllAttributeValuesItem( colC );
}
 
Example #12
Source File: BinaryValueAttributeTypeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the isValid method
 * 
 * The SyntaxChecker does not accept values longer than 5 chars.
 */
@Test
public void testIsValid() throws LdapInvalidAttributeValueException
{
    AttributeType attribute = EntryUtils.getBytesAttributeType();

    new Value( attribute, ( byte[] ) null );
    new Value( attribute, Strings.EMPTY_BYTES );
    new Value( attribute, new byte[]
        { 0x01, 0x02 } );

    try
    {
        new Value( attribute, new byte[]
            { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 } );
        fail();
    }
    catch ( LdapInvalidAttributeValueException liave )
    {
        assertTrue( true );
    }
}
 
Example #13
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean contains( AttributeType attributeType, String... values )
{
    if ( attributeType == null )
    {
        return false;
    }

    Attribute attribute = attributes.get( attributeType.getOid() );

    if ( attribute != null )
    {
        return attribute.contains( values );
    }
    else
    {
        return false;
    }
}
 
Example #14
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Try to inject an AttributeType which is Collective, and userApplication AT
 */
@Test
public void testAddAttributeTypeNoSupCollectiveUser() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.0" );
    attributeType.setEqualityOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setOrderingOid( null );
    attributeType.setSubstringOid( null );
    attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
    attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
    attributeType.setCollective( true );

    // It should not fail
    assertTrue( schemaManager.add( attributeType ) );

    assertTrue( isATPresent( schemaManager, "1.1.0" ) );
    assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #15
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 #16
Source File: MatchingRuleTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntegerMatch() throws Exception
{
    MatchingRule mr1 = schemaManager.lookupMatchingRuleRegistry( "integerMatch" );
    assertEquals( NumericNormalizer.class.getName(), mr1.getNormalizer().getClass().getName() );
    assertEquals( "1234567890", mr1.getNormalizer().normalize( " 1 234 567 890 " ) );
    //assertEquals( IntegerComparator.class.getName(), mr1.getLdapComparator().getClass().getName() );
    //assertEquals( 0, mr1.getLdapComparator().compare( " 1 234 567 890 ", "1234567890" ) );

    MatchingRule mr2 = schemaManager.lookupMatchingRuleRegistry( "integerOrderingMatch" );
    assertEquals( NumericNormalizer.class.getName(), mr2.getNormalizer().getClass().getName() );
    assertEquals( "1234567890", mr2.getNormalizer().normalize( " 1 234 567 890 " ) );
    assertEquals( IntegerComparator.class.getName(), mr2.getLdapComparator().getClass().getName() );
    assertEquals( 0, mr2.getLdapComparator().compare( 1234567890L, 1234567890L ) );
    assertTrue( mr2.getLdapComparator().compare( 123L, 234L ) < 0 );
    assertTrue( mr2.getLdapComparator().compare( 1234L, 234L ) > 0 );

    // test a real attribute type: uidNumber
    AttributeType at = schemaManager.lookupAttributeTypeRegistry( "uidNumber" );
    assertNotNull( at.getEquality() );
    assertEquals( NumericNormalizer.class.getName(), at.getEquality().getNormalizer().getClass().getName() );
    assertEquals( "123", at.getEquality().getNormalizer().normalize( " 1 2 3 " ) );
    //assertEquals( 0, at.getEquality().getLdapComparator().compare( " 1 2 3 ", "123" ) );
    assertNull( at.getSubstring() );
    assertNull( at.getOrdering() );
}
 
Example #17
Source File: FilteringOperationContext.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Tells if an attribute is present in the list of attribute to return
 * 
 * @param attribute The attribute we are looking for
 * @return true if the attribute is present
 */
public boolean contains( SchemaManager schemaManager, String attribute )
{
    if ( isNoAttributes() )
    {
        return false;
    }

    try
    {
        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute );

        return contains( schemaManager, attributeType );
    }
    catch ( LdapException le )
    {
        return false;
    }
}
 
Example #18
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Try to inject an AttributeType which is a NO-USER-MODIFICATION and is operational
 */
@Test
public void testAddAttributeTypeNoSupNoUserModificationOpAttr() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.0" );
    attributeType.setEqualityOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setOrderingOid( null );
    attributeType.setSubstringOid( null );
    attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
    attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );
    attributeType.setUserModifiable( false );

    // It should not fail
    assertTrue( schemaManager.add( attributeType ) );

    assertTrue( isATPresent( schemaManager, "1.1.0" ) );
    assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #19
Source File: FastOpenLdapSchemaParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testAttributeTypeParseWithDescQuotes() throws Exception
{
    String attributeTypeData = "# adding a comment  \n"
        + "attributetype ( 2.5.4.2 NAME 'knowledgeInformation'\n"
        + "        DESC 'RFC2256: \"knowledge\" information'\n"
        + "        EQUALITY caseIgnoreMatch\n"
        + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
    parser.parse( attributeTypeData );
    List<AttributeType> attributeTypeList = parser.getAttributeTypes();
    Map<String, AttributeType> attributeTypes = mapAttributeTypes( attributeTypeList );
    AttributeType type = attributeTypes.get( "2.5.4.2" );

    assertNotNull( type );
    assertEquals( "2.5.4.2", type.getOid() );
    assertEquals( "knowledgeInformation", type.getName() );
    assertEquals( "RFC2256: \"knowledge\" information", type.getDescription() );
    assertEquals( "1.3.6.1.4.1.1466.115.121.1.15", type.getSyntaxOid() );
    assertEquals( 32768, type.getSyntaxLength() );
}
 
Example #20
Source File: ValueSerializationTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringValueNoDataSerializationBytes() throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException
{
    byte[] buffer = new byte[128];

    int pos = sv3.serialize( buffer, 0 );

    Value svDeser = new Value( ( AttributeType ) null );

    int pos2 = svDeser.deserialize( buffer, 0 );

    assertEquals( pos, pos2 );
    assertEquals( sv3, svDeser );
}
 
Example #21
Source File: DefaultAttribute.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setUpId( String upId, AttributeType attributeType )
{
    String trimmed = Strings.trim( upId );

    if ( Strings.isEmpty( trimmed ) && ( attributeType == null ) )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13235_NULL_ID_WITH_NULL_AT_NOT_ALLOWED ) );
    }

    String newId = Strings.toLowerCaseAscii( trimmed );

    setUpIdInternal( upId, newId, attributeType );
}
 
Example #22
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private Set<String> getAllAllowed( Attribute objectClasses, Set<String> must ) throws LdapException
{
    Set<String> allowed = new HashSet<String>( must );

    // Add the 'ObjectClass' attribute ID
    allowed.add( SchemaConstants.OBJECT_CLASS_AT_OID );

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

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

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

                allowed.add( oid );
            }
        }
    }

    return allowed;
}
 
Example #23
Source File: ExtensibleNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ExtensibleNode object.
 * 
 * @param attributeType the attributeType used for the extensible assertion
 * @param value the value to match for
 * @param matchingRuleId the OID of the matching rule
 * @param dnAttributes the dn attributes
 */
public ExtensibleNode( AttributeType attributeType, Value value, String matchingRuleId, boolean dnAttributes )
{
    super( attributeType, AssertionType.EXTENSIBLE );

    this.value = value;
    this.matchingRuleId = matchingRuleId;
    this.dnAttributes = dnAttributes;
}
 
Example #24
Source File: AttributeTypeDescriptionSchemaParserRelaxedTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Tests NO-USER-MODIFICATION
 * 
 * @throws ParseException
 */
@Test
public void testNoUserModification() throws ParseException
{
    String value = null;
    AttributeType attributeType = null;

    // not NO-USER-MODIFICATION
    value = "( 1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' )";
    attributeType = parser.parse( value );
    assertTrue( attributeType.isUserModifiable() );

    // NO-USER-MODIFICATION
    value = "(1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' NO-USER-MODIFICATION USAGE directoryOperation )";
    attributeType = parser.parse( value );
    assertFalse( attributeType.isUserModifiable() );

    // NO-USER-MODIFICATION 
    value = "(1.1 SYNTAX 1.1 NO-USER-MODIFICATION USAGE directoryOperation )";
    attributeType = parser.parse( value );
    assertFalse( attributeType.isUserModifiable() );

    // ivalid
    value = "(1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' NO-USER-MODIFICATIO USAGE directoryOperation )";
    try
    {
        attributeType = parser.parse( value );
        fail( "Exception expected, invalid NO-USER-MODIFICATION value" );
    }
    catch ( ParseException pe )
    {
        // expected
    }
}
 
Example #25
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( CompareOperationContext compareContext ) throws LdapException
{
    Dn dn = compareContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        compareContext.setDn( new Dn( schemaManager, dn ) );
    }

    // Get the attributeType from the OID
    try
    {
        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( compareContext.getOid() );

        // Translate the value from binary to String if the AT is HR
        if ( attributeType.getSyntax().isHumanReadable() && ( !compareContext.getValue().isHumanReadable() ) )
        {
            compareContext.setValue( compareContext.getValue() );
        }

        compareContext.setAttributeType( attributeType );
    }
    catch ( LdapException le )
    {
        throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) );
    }

    return next( compareContext );
}
 
Example #26
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean remove( AttributeType attributeType, String... values ) throws LdapException
{
    if ( attributeType == null )
    {
        return false;
    }

    try
    {
        Attribute attribute = attributes.get( attributeType.getOid() );

        if ( attribute == null )
        {
            // Can't remove values from a not existing attribute !
            return false;
        }

        int nbOldValues = attribute.size();

        // Remove the values
        attribute.remove( values );

        if ( attribute.size() == 0 )
        {
            // No mare values, remove the attribute
            attributes.remove( attributeType.getOid() );

            return true;
        }

        return nbOldValues != attribute.size();
    }
    catch ( IllegalArgumentException iae )
    {
        LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
        return false;
    }
}
 
Example #27
Source File: DefaultAttributeTypeRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean hasDescendants( AttributeType ancestor ) throws LdapException
{
    String oid = ancestor.getOid();
    Set<AttributeType> descendants = oidToDescendantSet.get( oid );
    return ( descendants != null ) && !descendants.isEmpty();
}
 
Example #28
Source File: RestrictedByItemTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize maxValueCountItem instances
 */
@BeforeEach
public void initNames() throws Exception
{
    elemsA = new HashSet<RestrictedByElem>();
    elemsA.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "aa" ) ) );
    elemsA.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "bb" ) ) );
    elemsA.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "cc" ) ) );
    // Sets aren't ordered, so adding order must not matter
    elemsB = new HashSet<RestrictedByElem>();
    elemsB.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "bb" ) ) );
    elemsB.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "cc" ) ) );
    elemsB.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "aa" ) ) );
    elemsC = new HashSet<RestrictedByElem>();
    elemsC.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "aa" ) ) );
    elemsC.add( new RestrictedByElem( new AttributeType( "bb" ), new AttributeType( "bb" ) ) );
    elemsC.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "cc" ) ) );
    elemsD = new HashSet<RestrictedByElem>();
    elemsD.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "aa" ) ) );
    elemsD.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "bb" ) ) );
    elemsD.add( new RestrictedByElem( new AttributeType( "aa" ), new AttributeType( "dd" ) ) );
    restrictedByItemA = new RestrictedByItem( elemsA );
    restrictedByItemACopy = new RestrictedByItem( elemsA );
    restrictedByItemB = new RestrictedByItem( elemsB );
    restrictedByItemC = new RestrictedByItem( elemsC );
    restrictedByItemD = new RestrictedByItem( elemsD );
}
 
Example #29
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private Set<String> getAllAllowed( Attribute objectClasses, Set<String> must ) throws LdapException
{
    Set<String> allowed = new HashSet<String>( must );

    // Add the 'ObjectClass' attribute ID
    allowed.add( SchemaConstants.OBJECT_CLASS_AT_OID );

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

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

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

                allowed.add( oid );
            }
        }
    }

    return allowed;
}
 
Example #30
Source File: SchemaUtilsTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
public AttributeType[] getAttributeTypes()
{
    AttributeType[] ats = new AttributeType[5];

    ats[0] = new AttributeType( "2.5.4.41" );
    ats[0].addName( "name" );
    ats[0].setSyntax( getSyntaxes()[1] );
    ats[0].setSyntaxLength( 32768 );
    ats[0].setEquality( getMatchingRules()[0] );
    ats[0].setSubstring( getMatchingRules()[1] );

    // ( 2.5.4.3 NAME 'cn' SUP name )
    ats[1] = new AttributeType( "2.5.4.3" );
    ats[1].addName( "cn", "commonName" );

    ats[2] = new AttributeType( "2.5.4.41" );
    ats[2].addName( "name" );
    ats[2].setSyntax( getSyntaxes()[1] );
    ats[2].setSyntaxLength( 32768 );
    ats[2].setEquality( getMatchingRules()[0] );
    ats[2].setSubstring( getMatchingRules()[1] );

    ats[3] = new AttributeType( "2.5.4.41" );
    ats[3].addName( "name" );
    ats[3].setSyntax( getSyntaxes()[1] );
    ats[3].setSyntaxLength( 32768 );
    ats[3].setEquality( getMatchingRules()[0] );
    ats[3].setSubstring( getMatchingRules()[1] );

    ats[4] = new AttributeType( "2.5.4.41" );
    ats[4].addName( "name" );
    ats[4].setSyntax( getSyntaxes()[1] );
    ats[4].setSyntaxLength( 32768 );
    ats[4].setEquality( getMatchingRules()[0] );
    ats[4].setSubstring( getMatchingRules()[1] );

    return ats;
}