/** * Create a list of string from a multivalued attribute's values * * @param attr The Attribute to read * @return The list of values as Strings */ private List<String> getStrings( Attribute attr ) { if ( attr == null ) { return EMPTY_LIST; } List<String> strings = new ArrayList<>( attr.size() ); for ( Value value : attr ) { strings.add( value.getValue() ); } return strings; }
/** * Create a list of string from a multivalued attribute's values * * @param attr The Attribute to read * @return The list of values as Strings */ private List<String> getStrings( Attribute attr ) { if ( attr == null ) { return EMPTY_LIST; } List<String> strings = new ArrayList<>( attr.size() ); for ( Value value : attr ) { strings.add( value.getValue() ); } return strings; }
/** * Create a list of string from a multivalued attribute's values * * @param attr The Attribute to read * @return The list of values as Strings */ private List<String> getStrings( Attribute attr ) { if ( attr == null ) { return EMPTY_LIST; } List<String> strings = new ArrayList<>( attr.size() ); for ( Value value : attr ) { strings.add( value.getValue() ); } return strings; }
private static void addAttribute( Entry attrs, String id ) throws LdapException { Attribute attr = schemaSubentry.get( id ); if ( ( attr != null ) && ( attr.size() > 0 ) ) { attrs.put( attr ); } }
/** * Indicates if the given Root DSE corresponds to an ApacheDS server. * * @param rootDse the Root DSE * @return <code>true</code> if this is an ApacheDS server, * <code>false</code> if not. * @throws LdapInvalidAttributeValueException If the vendorName attribute contains an invalid value */ private boolean isApacheDs( Entry rootDse ) throws LdapInvalidAttributeValueException { if ( rootDse != null ) { Attribute vendorNameAttribute = rootDse.get( SchemaConstants.VENDOR_NAME_AT ); if ( ( vendorNameAttribute != null ) && vendorNameAttribute.size() == 1 ) { return DEFAULT_APACHEDS_VENDOR_NAME.equalsIgnoreCase( vendorNameAttribute.getString() ); } } return false; }
/** * Indicates if the given Root DSE corresponds to an ApacheDS server. * * @param rootDse the Root DSE * @return <code>true</code> if this is an ApacheDS server, * <code>false</code> if not. * @throws LdapInvalidAttributeValueException If the vendorName attribute contains an invalid value */ private boolean isApacheDs( Entry rootDse ) throws LdapInvalidAttributeValueException { if ( rootDse != null ) { Attribute vendorNameAttribute = rootDse.get( SchemaConstants.VENDOR_NAME_AT ); if ( ( vendorNameAttribute != null ) && vendorNameAttribute.size() == 1 ) { return DEFAULT_APACHEDS_VENDOR_NAME.equalsIgnoreCase( vendorNameAttribute.getString() ); } } return false; }
/** * Indicates if the given Root DSE corresponds to an ApacheDS server. * * @param rootDse the Root DSE * @return <code>true</code> if this is an ApacheDS server, * <code>false</code> if not. * @throws LdapInvalidAttributeValueException If the vendorName attribute contains an invalid value */ private boolean isApacheDs( Entry rootDse ) throws LdapInvalidAttributeValueException { if ( rootDse != null ) { Attribute vendorNameAttribute = rootDse.get( SchemaConstants.VENDOR_NAME_AT ); if ( ( vendorNameAttribute != null ) && vendorNameAttribute.size() == 1 ) { return DEFAULT_APACHEDS_VENDOR_NAME.equalsIgnoreCase( vendorNameAttribute.getString() ); } } return false; }
/** * Given a collection of {@link java.util.Properties}, convert to raw data name-value format and load into ldap * modification set in preparation for ldap add. * * @param props contains {@link java.util.Properties} targeted for adding to ldap. * @param entry contains ldap entry to pull attrs from. * @param attrName contains the name of the ldap attribute to be added. * @throws LdapException If we weren't able to add the properies into the entry */ protected void loadProperties( Properties props, Entry entry, String attrName ) throws LdapException { if ( ( props != null ) && ( props.size() > 0 ) ) { Attribute attr = new DefaultAttribute( attrName ); for ( Enumeration<?> e = props.propertyNames(); e.hasMoreElements(); ) { // This LDAP attr is stored as a name-value pair separated by a ':'. String key = ( String ) e.nextElement(); String val = props.getProperty( key ); String prop = key + GlobalIds.PROP_SEP + val; attr.add( prop ); } if ( attr.size() != 0 ) { entry.add( attr ); } } }
private void applyAttributes(Map<String, Object> props, Entry entry) throws LdapInvalidAttributeValueException { for (Attribute attr: entry.getAttributes()) { if (attr.isHumanReadable()) { final Object propValue; // for multivalue properties, store as collection if (attr.size() > 1) { List<String> values = new ArrayList(); for (Value<?> value : attr) { values.add(value.getString()); } propValue = values; } else { propValue = attr.getString(); } props.put(attr.getId(), propValue); } } }
public LdapComparatorDescription[] parseComparators( Attribute attr ) throws LdapInvalidAttributeValueException { if ( attr == null || attr.size() == 0 ) { return EMPTY_COMPARATORS; } LdapComparatorDescription[] comparatorDescriptions = new LdapComparatorDescription[attr.size()]; int pos = 0; for ( Value value : attr ) { try { comparatorDescriptions[pos++] = comparatorParser.parse( value.getValue() ); } catch ( ParseException e ) { LdapInvalidAttributeValueException iave = new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_407, value.getValue() ) ); iave.initCause( e ); throw iave; } } return comparatorDescriptions; }
public NormalizerDescription[] parseNormalizers( Attribute attr ) throws LdapInvalidAttributeValueException { if ( attr == null || attr.size() == 0 ) { return EMPTY_NORMALIZERS; } NormalizerDescription[] normalizerDescriptions = new NormalizerDescription[attr.size()]; int pos = 0; for ( Value value : attr ) { try { normalizerDescriptions[pos++] = normalizerParser.parse( value.getValue() ); } catch ( ParseException e ) { LdapInvalidAttributeValueException iave = new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_406, value.getValue() ) ); iave.initCause( e ); throw iave; } } return normalizerDescriptions; }
@Override public Map<String, Object> transformSearchResult(SearchCursor cursor) throws IOException { LOG.debug(name); cursor.forEach(response -> { if (response instanceof SearchResultEntry) { Entry resultEntry = ((SearchResultEntry) response).getEntry(); String dn = resultEntry.getDn().toString(); LOG.debug("\tEntryDN {}", dn); DeepMap dnBranch = reqBranch.getBranch(dn.toLowerCase()); dnBranch.put(DISTINGUISH_NAME, dn); resultEntry.forEach(attr -> { // Since there might be multiple attributes with the same name, it is required to collect all their values (i.e. memberUid in group) if (attr.size() > 1) { List<Object> list = new ArrayList<>(); attr.iterator().forEachRemaining(list::add); String join = StringUtils.join(list, ","); dnBranch.put(attr.getId() + "", join); LOG.debug("\t\tAttr {} : {} ", attr.getId(), join); } else { dnBranch.put(attr.getId() + "", attr.get() + ""); LOG.debug("\t\tAttr {}", attr); } }); } }); return reqBranch.getRoot(); }
/** * Given a collection of RBAC roles, {@link UserRole}, convert to raw data format and load into ldap modification * set in preparation for ldap modify. * * @param list contains List of type {@link UserRole} targeted for updating into ldap. * @param mods contains ldap modification set containing RBAC role assignments in raw ldap format to be updated. * @throws LdapInvalidAttributeValueException */ private void loadUserRoles( List<UserRole> list, List<Modification> mods ) throws LdapInvalidAttributeValueException { Attribute userRoleData = new DefaultAttribute( GlobalIds.USER_ROLE_DATA ); Attribute userRoleAssign = new DefaultAttribute( USER_ROLE_ASSIGN ); if ( list != null ) { for ( UserRole userRole : list ) { userRoleData.add( userRole.getRawData() ); userRoleAssign.add( userRole.getName() ); } if ( userRoleData.size() != 0 ) { mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, userRoleData ) ); mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, userRoleAssign ) ); } } }
if ( userAdminRoleData.size() != 0 )
/** * Convert a ServerEntry into a BasicAttributes. The Dn is lost * during this conversion, as the Attributes object does not store * this element. * * @param entry The entry to convert * @return An instance of a AttributesImpl() object */ public static Attributes toBasicAttributes( Entry entry ) { if ( entry == null ) { return null; } Attributes attributes = new BasicAttributes( true ); for ( Attribute attribute : entry.getAttributes() ) { AttributeType attributeType = attribute.getAttributeType(); Attribute attr = entry.get( attributeType ); // Deal with a special case : an entry without any ObjectClass if ( attributeType.getOid().equals( SchemaConstants.OBJECT_CLASS_AT_OID ) && attr.size() == 0 ) { // We don't have any objectClass, just dismiss this element continue; } attributes.put( toBasicAttribute( attr ) ); } return attributes; }
/** * Given a collection of RBAC roles, {@link UserRole}, convert to raw data format and load into ldap attribute * set in preparation for ldap add. * * @param list contains List of type {@link UserRole} targeted for adding to ldap. * @param entry ldap entry containing attributes mapping to RBAC role assignments in raw ldap format. * @throws LdapException */ private void loadUserRoles( List<UserRole> list, Entry entry ) throws LdapException { if ( list != null ) { Attribute userRoleData = new DefaultAttribute( GlobalIds.USER_ROLE_DATA ); Attribute userRoleAssign = new DefaultAttribute( USER_ROLE_ASSIGN ); for ( UserRole userRole : list ) { userRoleData.add( userRole.getRawData() ); userRoleAssign.add( userRole.getName() ); } if ( userRoleData.size() != 0 ) { entry.add( userRoleData, userRoleAssign ); } } }
/** * Given a collection of ARBAC roles, {@link UserAdminRole}, convert to raw data format and load into ldap * attribute set in preparation for ldap add. * * @param list contains List of type {@link UserAdminRole} targeted for adding to ldap. * @param entry collection of ldap attributes containing ARBAC role assignments in raw ldap format. * @throws LdapException */ private void loadUserAdminRoles( List<UserAdminRole> list, Entry entry ) throws LdapException { if ( list != null ) { Attribute userAdminRoleData = new DefaultAttribute( GlobalIds.USER_ADMINROLE_DATA ); Attribute userAdminRoleAssign = new DefaultAttribute( GlobalIds.USER_ADMINROLE_ASSIGN ); for ( UserAdminRole userRole : list ) { userAdminRoleData.add( userRole.getRawData() ); userAdminRoleAssign.add( userRole.getName() ); } if ( userAdminRoleData.size() != 0 ) { entry.add( userAdminRoleData ); entry.add( userAdminRoleAssign ); } } }
/** * Get the administrativePoint role */ private void checkAdministrativeRole( OperationContext opContext, Dn apDn ) throws LdapException { CoreSession session = opContext.getSession(); LookupOperationContext lookupContext = new LookupOperationContext( session, apDn, SchemaConstants.ALL_ATTRIBUTES_ARRAY ); lookupContext.setPartition( opContext.getPartition() ); lookupContext.setTransaction( opContext.getTransaction() ); Entry administrationPoint = directoryService.getPartitionNexus().lookup( lookupContext ); // The administrativeRole AT must exist and not be null Attribute administrativeRole = administrationPoint.get( directoryService.getAtProvider() .getAdministrativeRole() ); // check that administrativeRole has something valid in it for us if ( ( administrativeRole == null ) || ( administrativeRole.size() <= 0 ) ) { LOG.error( "The entry on {} is not an AdministrativePoint", apDn ); throw new LdapNoSuchAttributeException( I18n.err( I18n.ERR_306, apDn ) ); } }