} else { try { return new Dn(dn).getNormName(); } catch (LdapInvalidDnException e) { LOG.debug("Invalid DN", e);
final Entry e = it.next(); ldapEntry.setDn(e.getDn().getName()); ldapEntry.setBindPrincipal(e.getDn().getName()); for (Attribute attribute : e.getAttributes()) { if (activeDirectory && "userPrincipalName".equalsIgnoreCase(attribute.getId())) { ldapEntry.setBindPrincipal(attribute.getString()); if (attribute.isHumanReadable()) { ldapEntry.put(attribute.getId(), Joiner.on(", ").join(attribute.iterator())); if ("memberOf".equalsIgnoreCase(attribute.getId()) || "isMemberOf".equalsIgnoreCase(attribute.getId())) { for (Value<?> group : attribute) { groupDns.add(group.getString());
LOG.error( I18n.err( I18n.ERR_05301_INVALID_PREVIOUS_DN ) ); throw new DecoderException( I18n.err( I18n.ERR_05302_PREVIOUS_DN_NOT_ALLOWED ) ); previousDn = new Dn( Strings.utf8ToString( value.getData() ) ); LOG.error( I18n.err( I18n.ERR_05303_BAD_PREVIOUS_DN, Strings.dumpBytes( value.getData() ) ) ); throw new DecoderException( I18n.err( I18n.ERR_05304_FAILED_TO_DECODE_PREVIOUS_DN ), ine );
private void addMemberToRoleOrGroup(final CoreSession session, final String dn, final String memberDN, final String attributeName) throws LdapException { final Entry entry = session.lookup(new Dn(dn), attributeName); Attribute attribute = entry.get(attributeName); if (attribute == null) { entry.add(attributeName, memberDN); attribute = entry.get(attributeName); } else { attribute.add(memberDN); } final ModifyRequestImpl modifyRequestImpl = new ModifyRequestImpl(); modifyRequestImpl.setName(entry.getDn()); modifyRequestImpl.replace(attribute); session.modify(modifyRequestImpl); }
private Dn getDn( Object obj ) throws LdapInvalidDnException { Dn dn; if ( obj instanceof Dn ) { dn = ( Dn ) obj; dn = dn.isSchemaAware() ? dn : new Dn( schemaManager, dn ); } else if ( obj instanceof String ) { dn = new Dn( schemaManager, ( String ) obj ); } else { throw new IllegalStateException( I18n.err( I18n.ERR_13720_CANNOT_HANDLE_DN_COMPARISONS, obj == null ? null : obj.getClass() ) ); } return dn; }
sb.append( " Entry : '" ).append( name.toString() ).append( "'\n" ); sb.append( " Attribute description : '" ).append( attrId ).append( "'\n" ); sb.append( " Attribute value : '" ); if ( attrVal.isHumanReadable() ) sb.append( attrVal.getValue() ); byte[] binVal = attrVal.getBytes(); sb.append( Strings.utf8ToString( binVal ) ).append( '/' ).append( Strings.dumpBytes( binVal ) ) .append( "'\n" );
@NotNull private ExternalIdentity createIdentity(@NotNull Entry entry, @Nullable String id, boolean isGroup) throws LdapInvalidAttributeValueException { LdapProviderConfig.Identity cfg = isGroup ? config.getGroupConfig() : config.getUserConfig(); if (id == null) { String idAttribute = cfg.getIdAttribute(); Attribute attr = entry.get(idAttribute); if (attr == null) { throw new LdapInvalidAttributeValueException(ResultCodeEnum.CONSTRAINT_VIOLATION, "no value found for attribute '" + idAttribute + "' for entry " + entry); } id = attr.getString(); } String extId = config.getUseUidForExtId() ? id : entry.getDn().getName(); ExternalIdentityRef ref = new ExternalIdentityRef(extId, this.getName()); String path = cfg.makeDnPath() ? createDNPath(entry.getDn()) : null; LdapIdentity identity = isGroup ? new LdapGroup(this, ref, id, path, entry) : new LdapUser(this, ref, id, path, entry); Map<String, Object> props = identity.getProperties(); applyAttributes(props, entry); return identity; }
private void removeMemberFromRoleOrGroup(final CoreSession session, final String dn, final String memberDN, final String attributeName) throws LdapException { final Entry entry = session.lookup(new Dn(dn), attributeName); final Attribute attribute = entry.get(attributeName); if (attribute != null) { attribute.remove(memberDN); final ModifyRequestImpl modifyRequestImpl = new ModifyRequestImpl(); modifyRequestImpl.setName(entry.getDn()); modifyRequestImpl.replace(attribute); session.modify(modifyRequestImpl); } }
private void denormalizeEntryOpAttrs( Entry entry ) throws LdapException { if ( directoryService.isDenormalizeOpAttrsEnabled() ) { Attribute attr = entry.get( SchemaConstants.CREATORS_NAME_AT ); if ( attr != null ) { Dn creatorsName = dnFactory.create( attr.getString() ); attr.clear(); attr.add( denormalizeTypes( creatorsName ).getName() ); } attr = entry.get( SchemaConstants.MODIFIERS_NAME_AT ); if ( attr != null ) { Dn modifiersName = dnFactory.create( attr.getString() ); attr.clear(); attr.add( denormalizeTypes( modifiersName ).getName() ); } attr = entry.get( ApacheSchemaConstants.SCHEMA_MODIFIERS_NAME_AT ); if ( attr != null ) { Dn modifiersName = dnFactory.create( attr.getString() ); attr.clear(); attr.add( denormalizeTypes( modifiersName ).getName() ); } } }
Attribute oc = entry.get( objectClassAT ); String oid = schemaManager.getObjectClassRegistry().getOidByName( value.getValue() ); if ( oc.contains( MetaSchemaConstants.META_SCHEMA_OC ) ) if ( oc.contains( SchemaConstants.ORGANIZATIONAL_UNIT_OC ) ) if ( deleteContext.getDn().size() != 3 ) String ouValue = deleteContext.getDn().getRdn().getValue(); ouValue = Strings.toLowerCaseAscii( Strings.trim( ouValue ) );
/** * {@inheritDoc} */ public void logChangetypeModDn( Connection connection, final String oldDn, final String newDn, final boolean deleteOldRdn, final Control[] controls, NamingException ex ) { if ( !isModificationLogEnabled() ) { return; } try { Dn dn = new Dn( newDn ); Rdn newrdn = dn.getRdn(); Dn newsuperior = dn.getParent(); LdifChangeModDnRecord record = new LdifChangeModDnRecord( LdifDnLine.create( oldDn ) ); addControlLines( record, controls ); record.setChangeType( LdifChangeTypeLine.createModDn() ); record.setNewrdn( LdifNewrdnLine.create( newrdn.getName() ) ); record.setDeloldrdn( deleteOldRdn ? LdifDeloldrdnLine.create1() : LdifDeloldrdnLine.create0() ); record.setNewsuperior( LdifNewsuperiorLine.create( newsuperior.getName() ) ); record.finish( LdifSepLine.create() ); String formattedString = record.toFormattedString( LdifFormatParameters.DEFAULT ); log( formattedString, ex, connection ); } catch ( LdapInvalidDnException e ) { } }
/** * Update the Operational Attribute with the reference to the subentry */ private void setOperationalAttribute( Entry entry, Dn subentryDn, AttributeType opAttr ) throws LdapException { Attribute operational = entry.get( opAttr ); if ( operational == null ) { operational = new DefaultAttribute( opAttr ); entry.put( operational ); } operational.add( subentryDn.getName() ); }
/** * {@inheritDoc} */ @Override public BindFuture bindAsync( Dn name, String credentials ) throws LdapException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04102_BIND_REQUEST, name ) ); } // The password must not be empty or null if ( Strings.isEmpty( credentials ) && ( !Dn.EMPTY_DN.equals( name ) ) ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04105_MISSING_PASSWORD ) ); } throw new LdapAuthenticationException( I18n.msg( I18n.MSG_04105_MISSING_PASSWORD ) ); } // Create the BindRequest BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ) ); return bindAsync( bindRequest ); }
/** * Update the list of modifications with a modification associated with a specific * role, if it's requested. */ private void getOperationalModForReplace( boolean hasRole, AttributeType attributeType, Entry entry, Dn oldDn, Dn newDn, List<Modification> modifications ) throws LdapInvalidAttributeValueException { String oldDnStr = oldDn.getName(); String newDnStr = newDn.getName(); if ( hasRole ) { Attribute operational = entry.get( attributeType ).clone(); if ( operational == null ) { operational = new DefaultAttribute( attributeType, newDnStr ); } else { operational.remove( oldDnStr ); operational.add( newDnStr ); } modifications.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, operational ) ); } }
/** * {@inheritDoc} */ @Override public void rename( Entry entry, Rdn newRdn, boolean cascade ) throws LdapException { String oldOid = getOid( entry ); String schemaName = getSchemaName( entry.getDn() ); if ( schemaManager.getMatchingRuleRegistry().contains( oldOid ) ) { throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_367, oldOid ) ); } String newOid = newRdn.getValue(); checkOidIsUniqueForNormalizer( newOid ); if ( isSchemaEnabled( schemaName ) ) { // Inject the new OID Entry targetEntry = entry.clone(); targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid ); // Inject the new Dn Dn newDn = targetEntry.getDn().getParent(); newDn = newDn.add( newRdn ); targetEntry.setDn( newDn ); Normalizer normalizer = factory.getNormalizer( schemaManager, targetEntry, schemaManager.getRegistries(), schemaName ); schemaManager.unregisterNormalizer( oldOid ); schemaManager.add( normalizer ); } }
public String rewriteBase(final String base) { try { Dn lowerCasedContextDn = (contextDn == null) ? null : new Dn(contextDn.toString().toLowerCase()); Dn lowerCasedBaseDn = new Dn(base.toLowerCase()); if (!lowerCasedBaseDn.isDescendantOf(lowerCasedContextDn)) { return base; } if (lowerCasedBaseDn.equals(lowerCasedContextDn)) { return ""; } Dn lowerCasedRelativeDn = lowerCasedBaseDn.getDescendantOf(lowerCasedContextDn); return base.substring(0, lowerCasedRelativeDn.toString().length()); } catch (LdapInvalidDnException e) { throw new RuntimeException(e); } }
private void addEntryIfNotExists(CoreSession session, String dnString, String... objectClasses) throws LdapException { final Dn dn = new Dn(dnString); final Rdn rdn = dn.getRdn(); final Entry entryRoda = service.newEntry(dn).add(OBJECT_CLASS, objectClasses).add(rdn.getType(), rdn.getValue()); try { session.add(entryRoda); } catch (LdapEntryAlreadyExistsException e) { LOGGER.debug("Error injecting the context entry for {}: {}", dnString, e.getMessage()); } }