Java Code Examples for org.apache.directory.api.ldap.model.entry.Attribute#contains()
The following examples show how to use
org.apache.directory.api.ldap.model.entry.Attribute#contains() .
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: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 7 votes |
/** * Checks to see if an attribute is required by as determined from an entry's * set of objectClass attribute values. * * @return true if the objectClass values require the attribute, false otherwise * @throws Exception if the attribute is not recognized */ private void assertAllAttributesAllowed( Dn dn, Entry entry, Set<String> allowed ) throws LdapException { // Never check the attributes if the extensibleObject objectClass is // declared for this entry Attribute objectClass = entry.get( OBJECT_CLASS_AT ); if ( objectClass.contains( SchemaConstants.EXTENSIBLE_OBJECT_OC ) ) { return; } for ( Attribute attribute : entry ) { String attrOid = attribute.getAttributeType().getOid(); AttributeType attributeType = attribute.getAttributeType(); if ( !attributeType.isCollective() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) && !allowed.contains( attrOid ) ) { throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_277, attribute.getUpId(), dn.getName() ) ); } } }
Example 2
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * Checks to see if an attribute is required by as determined from an entry's * set of objectClass attribute values. * * @return true if the objectClass values require the attribute, false otherwise * @throws Exception if the attribute is not recognized */ private void assertAllAttributesAllowed( Dn dn, Entry entry, Set<String> allowed ) throws LdapException { // Never check the attributes if the extensibleObject objectClass is // declared for this entry Attribute objectClass = entry.get( OBJECT_CLASS_AT ); if ( objectClass.contains( SchemaConstants.EXTENSIBLE_OBJECT_OC ) ) { return; } for ( Attribute attribute : entry ) { String attrOid = attribute.getAttributeType().getOid(); AttributeType attributeType = attribute.getAttributeType(); if ( !attributeType.isCollective() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) && !allowed.contains( attrOid ) ) { throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_277, attribute.getUpId(), dn.getName() ) ); } } }
Example 3
Source File: DefaultPartitionNexus.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public boolean compare( CompareOperationContext compareContext ) throws LdapException { Attribute attr = compareContext.getOriginalEntry().get( compareContext.getAttributeType() ); // complain if the attribute being compared does not exist in the entry if ( attr == null ) { throw new LdapNoSuchAttributeException(); } // see first if simple match without normalization succeeds if ( attr.contains( compareContext.getValue() ) ) { return true; } // now must apply normalization to all values (attr and in request) to compare /* * Get ahold of the normalizer for the attribute and normalize the request * assertion value for comparisons with normalized attribute values. Loop * through all values looking for a match. */ Normalizer normalizer = compareContext.getAttributeType().getEquality().getNormalizer(); Value<?> reqVal = normalizer.normalize( compareContext.getValue() ); for ( Value<?> value : attr ) { Value<?> attrValObj = normalizer.normalize( value ); if ( attrValObj.equals( reqVal ) ) { return true; } } return false; }
Example 4
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
private void assertRdn( Dn dn, Entry entry ) throws LdapException { for ( Ava atav : dn.getRdn() ) { Attribute attribute = entry.get( atav.getNormType() ); if ( ( attribute == null ) || ( !attribute.contains( atav.getNormValue() ) ) ) { String message = I18n.err( I18n.ERR_62, dn, atav.getType() ); LOG.error( message ); throw new LdapSchemaViolationException( ResultCodeEnum.NOT_ALLOWED_ON_RDN, message ); } } }
Example 5
Source File: DefaultPartitionNexus.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public boolean compare( CompareOperationContext compareContext ) throws LdapException { Attribute attr = compareContext.getOriginalEntry().get( compareContext.getAttributeType() ); // complain if the attribute being compared does not exist in the entry if ( attr == null ) { throw new LdapNoSuchAttributeException(); } // see first if simple match without normalization succeeds if ( attr.contains( compareContext.getValue() ) ) { return true; } // now must apply normalization to all values (attr and in request) to compare /* * Get ahold of the normalizer for the attribute and normalize the request * assertion value for comparisons with normalized attribute values. Loop * through all values looking for a match. */ Normalizer normalizer = compareContext.getAttributeType().getEquality().getNormalizer(); Value<?> reqVal = normalizer.normalize( compareContext.getValue() ); for ( Value<?> value : attr ) { Value<?> attrValObj = normalizer.normalize( value ); if ( attrValObj.equals( reqVal ) ) { return true; } } return false; }
Example 6
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
private void assertRdn( Dn dn, Entry entry ) throws LdapException { for ( Ava atav : dn.getRdn() ) { Attribute attribute = entry.get( atav.getNormType() ); if ( ( attribute == null ) || ( !attribute.contains( atav.getNormValue() ) ) ) { String message = I18n.err( I18n.ERR_62, dn, atav.getType() ); LOG.error( message ); throw new LdapSchemaViolationException( ResultCodeEnum.NOT_ALLOWED_ON_RDN, message ); } } }
Example 7
Source File: SchemaAwareLdifReaderTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
@Test public void testLdifParserRFC2849Sample5() throws Exception, Exception { String ldif = "version: 1\n" + "dn: cn=Horatio Jensen, ou=Product Testing, dc=airius, dc=com\n" + "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n" + "cn: Horatio Jensen\n" + "cn: Horatio N Jensen\n" + "sn: Jensen\n" + "uid: hjensen\n" + "telephonenumber: +1 408 555 1212\n" + "jpegphoto:< file:" + HJENSEN_JPEG_FILE.getAbsolutePath() + "\n"; LdifReader reader = new LdifReader( schemaManager ); List<LdifEntry> entries = reader.parseLdif( ldif ); reader.close(); String[][] values = { { "dn", "cn=Horatio Jensen, ou=Product Testing, dc=airius, dc=com" }, { "objectclass", "top" }, { "objectclass", "person" }, { "objectclass", "organizationalPerson" }, { "cn", "Horatio Jensen" }, { "cn", "Horatio N Jensen" }, { "sn", "Jensen" }, { "uid", "hjensen" }, { "telephonenumber", "+1 408 555 1212" }, { "jpegphoto", null } }; assertEquals( 1, entries.size() ); // Entry 1 LdifEntry entry = entries.get( 0 ); assertTrue( entry.isLdifContent() ); for ( int i = 0; i < values.length; i++ ) { if ( "dn".equalsIgnoreCase( values[i][0] ) ) { assertEquals( values[i][1], entry.getDn().getName() ); } else if ( "jpegphoto".equalsIgnoreCase( values[i][0] ) ) { // We can't have a jpegPhoto with a null value assertNull( entry.get( values[i][0] ) ); } else { Attribute attr = entry.get( values[i][0] ); if ( attr.contains( values[i][1] ) ) { assertTrue( true ); } else { assertTrue( attr.contains( values[i][1].getBytes( StandardCharsets.UTF_8 ) ) ); } } } }