public List<String> getAttributes(Entry entry, String attName) { List<String> values = new ArrayList<>(); javax.naming.directory.Attribute att = AttributeUtils.toAttributes(entry).get(attName); if (att == null) { return values; } try { NamingEnumeration<?> list = att.getAll(); while (list.hasMore()) { values.add(list.next().toString()); } } catch (NamingException e) { log.warn("Error while processing LDAP attribute {}, result could be incomplete!", attName, e); } return values; }
/** * Convert an Attributes as LDIF * * @param attrs the Attributes to convert * @param length The ldif line length * @return the corresponding LDIF code as a String * @throws LdapException If a naming exception is encountered. */ public static String convertToLdif( Attributes attrs, int length ) throws LdapException { return convertAttributesToLdif( AttributeUtils.toEntry( attrs, null ), length ); }
parseNumber( bytes, pos ); if ( !parseNumber( bytes, pos ) ) if ( !parseNumber( bytes, pos ) )
parseOptions( str, pos ); parseOID( str, pos ); parseOptions( str, pos );
/** * Converts modification items. * * @param modificationItems * an array of modification items * @return * an array of converted modifications * @throws LdapInvalidAttributeValueException */ private Modification[] convertModificationItems( ModificationItem[] modificationItems ) throws LdapInvalidAttributeValueException { if ( modificationItems != null ) { List<Modification> modifications = new ArrayList<Modification>(); for ( ModificationItem modificationItem : modificationItems ) { Modification modification = new DefaultModification(); modification.setAttribute( AttributeUtils.toApiAttribute( modificationItem.getAttribute() ) ); modification.setOperation( convertModificationOperation( modificationItem.getModificationOp() ) ); modifications.add( modification ); } return modifications.toArray( new Modification[0] ); } else { return null; } }
String matchingRuleId = AttributeUtils.parseAttribute( filterBytes, pos, false, relaxed ); String matchingRuleId = AttributeUtils.parseAttribute( filterBytes, pos, false, relaxed );
/** * Converts an {@link Entry} to an {@link Attributes}. * * @param entry * the {@link Entry} to convert * @return * the equivalent {@link Attributes} */ public static Attributes toAttributes( Entry entry ) { if ( entry != null ) { Attributes attributes = new BasicAttributes( true ); // Looping on attributes for ( Iterator<Attribute> attributeIterator = entry.iterator(); attributeIterator.hasNext(); ) { Attribute entryAttribute = attributeIterator.next(); attributes.put( toJndiAttribute( entryAttribute ) ); } return attributes; } return null; }
AttributeUtils.applyModification( clonedEntry, modification );
/** * Defines the Administration point and administrative role for the TriggerExecution specific point * @param apCtx The administrative point context * @throws NamingException If the operation failed */ public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException { Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } ); Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT ); if ( administrativeRole == null || !AttributeUtils.containsValueCaseIgnore( administrativeRole, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) ) { Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA, true ); apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
parseOptions( str, pos ); parseOID( str, pos ); parseOptions( str, pos );
Attribute entryAttribute = toApiAttribute( attr );
String matchingRuleId = AttributeUtils.parseAttribute( filterBytes, pos, false, relaxed ); String matchingRuleId = AttributeUtils.parseAttribute( filterBytes, pos, false, relaxed );
/** * Converts an {@link Entry} to an {@link Attributes}. * * @param entry * the {@link Entry} to convert * @return * the equivalent {@link Attributes} */ public static Attributes toAttributes( Entry entry ) { if ( entry != null ) { Attributes attributes = new BasicAttributes( true ); // Looping on attributes for ( Iterator<Attribute> attributeIterator = entry.iterator(); attributeIterator.hasNext(); ) { Attribute entryAttribute = attributeIterator.next(); attributes.put( toJndiAttribute( entryAttribute ) ); } return attributes; } return null; }
AttributeUtils.applyModification( clonedEntry, modification );
/** * Defines the Administration point and administrative role for the TriggerExecution specific point * @param apCtx The administrative point context * @throws NamingException If the operation failed */ public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException { Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } ); Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT ); if ( administrativeRole == null || !AttributeUtils.containsValueCaseIgnore( administrativeRole, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) ) { Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA, true ); apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
parseOptions( str, pos ); parseOID( str, pos ); parseOptions( str, pos );
/** * Convert an Attributes as LDIF * * @param attrs the Attributes to convert * @param length The ldif line length * @return the corresponding LDIF code as a String * @throws LdapException If a naming exception is encountered. */ public static String convertToLdif( Attributes attrs, int length ) throws LdapException { return convertAttributesToLdif( AttributeUtils.toEntry( attrs, null ), length ); }
/** * Convert a LDIF String to a JNDI attributes. * * @param ldif The LDIF string containing an attribute value * @return An Attributes instance * @exception LdapLdifException If the LDIF String cannot be converted to an Attributes */ public static Attributes getJndiAttributesFromLdif( String ldif ) throws LdapLdifException { try ( LdifAttributesReader reader = new LdifAttributesReader() ) { return AttributeUtils.toAttributes( reader.parseEntry( ldif ) ); } catch ( IOException ioe ) { throw new LdapLdifException( ioe.getMessage(), ioe ); } }
Attribute entryAttribute = toApiAttribute( attr );
parseNumber( str, pos ); if ( !parseNumber( str, pos ) ) if ( !parseNumber( str, pos ) )