org.apache.directory.api.ldap.model.name.Dn Java Examples
The following examples show how to use
org.apache.directory.api.ldap.model.name.Dn.
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: Runner.java From aws-iam-ldap-bridge with Apache License 2.0 | 6 votes |
public void createStructure() throws Exception { String rootDN = AWSIAMAuthenticator.getConfig().rootDN; Dn dnIAM = service.getDnFactory().create(rootDN); if (!utils.exists(dnIAM)) { IAM_LOG.info("Creating partition " + rootDN); Partition iamPartition = utils.addPartition("iam", rootDN, service.getDnFactory()); // Index some attributes on the apache partition utils.addIndex(iamPartition, "objectClass", "ou", "uid", "gidNumber", "uidNumber", "cn"); if (!utils.exists(dnIAM)) { IAM_LOG.info("Creating root node " + rootDN); Rdn rdn = dnIAM.getRdn(0); Entry entryIAM = new DefaultEntry(service.getSchemaManager(), dnIAM, "objectClass: top", "objectClass: domain", "entryCsn: " + service.getCSN(), SchemaConstants.ENTRY_UUID_AT + ": " + UUID.randomUUID().toString(), rdn.getType() + ": " + rdn.getValue()); service.getAdminSession().add(entryIAM); checkErrors(); } } service.sync(); }
Example #2
Source File: DefaultPartitionNexus.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException { Dn base = searchContext.getDn(); // TODO since we're handling the *, and + in the EntryFilteringCursor // we may not need this code: we need see if this is actually the // case and remove this code. if ( base.size() == 0 ) { return searchFromRoot( searchContext ); } // Not sure we need this code... base.apply( schemaManager ); // Normal case : do a search on the specific partition Partition backend = getPartition( base ); return backend.search( searchContext ); }
Example #3
Source File: DnNode.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * rename the DnNode's Dn * * @param newRdn the new Rdn of this node * @throws LdapException If the rename failed */ public synchronized void rename( Rdn newRdn ) throws LdapException { Dn temp = nodeDn.getParent(); temp = temp.add( newRdn ); Rdn oldRdn = nodeRdn; nodeRdn = temp.getRdn(); nodeDn = temp; if ( parent != null ) { parent.children.remove( oldRdn.getNormName() ); parent.children.put( nodeRdn.getNormName(), this ); } updateAfterModDn( nodeDn ); }
Example #4
Source File: ApacheLdapProviderImpl.java From ldapchai with GNU Lesser General Public License v2.1 | 6 votes |
public void writeBinaryAttribute( final String entryDN, final String attributeName, final byte[][] values, final boolean overwrite ) throws ChaiUnavailableException, ChaiOperationException { activityPreCheck(); getInputValidator().writeBinaryAttribute( entryDN, attributeName, values, overwrite ); try { final ModifyRequest modifyRequest = new ModifyRequestImpl(); modifyRequest.setName( new Dn( entryDN ) ); { final Modification modification = new DefaultModification(); modification.setOperation( overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE ); modification.setAttribute( new DefaultAttribute( attributeName, values ) ); modifyRequest.addModification( modification ); } final ModifyResponse response = connection.modify( modifyRequest ); processResponse( response ); } catch ( LdapException e ) { throw ChaiOperationException.forErrorMessage( e.getMessage() ); } }
Example #5
Source File: CompareRequestImplTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Tests for equal hashCode using exact copies. */ @Test public void testHashCodeExactCopy() throws LdapException { CompareRequestImpl req0 = new CompareRequestImpl(); req0.setMessageId( 5 ); req0.setName( new Dn( "cn=admin,dc=example,dc=com" ) ); req0.setAttributeId( "objectClass" ); req0.setAssertionValue( "top" ); CompareRequestImpl req1 = new CompareRequestImpl(); req1.setMessageId( 5 ); req1.setName( new Dn( "cn=admin,dc=example,dc=com" ) ); req1.setAttributeId( "objectClass" ); req1.setAssertionValue( "top" ); assertTrue( req0.hashCode() == req1.hashCode() ); }
Example #6
Source File: FastDnParserTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * test a simple Dn : a = b */ @Test public void testLdapDNSimple() throws LdapException { Dn dn = FastDnParser.parse( "a = b" ); assertEquals( "a = b", dn.getName() ); assertEquals( "a=b", dn.getEscaped() ); assertEquals( "a = b", dn.toString() ); assertEquals( "a = b", dn.getRdn().getName() ); assertEquals( "a=b", dn.getRdn().getEscaped() ); assertEquals( "a=b", dn.getRdn().getAva().getName() ); assertEquals( "a=b", dn.getRdn().getAva().getEscaped() ); assertEquals( "a", dn.getRdn().getAva().getType() ); assertEquals( "a", dn.getRdn().getAva().getNormType() ); assertEquals( "b", dn.getRdn().getAva().getValue().getString() ); assertEquals( "b", dn.getRdn().getAva().getValue().getString() ); }
Example #7
Source File: LdifRevertorTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test a DelRequest reverse * @throws LdapException */ @Test public void testReverseDel() throws LdapException { Dn dn = new Dn( "dc=apache, dc=com" ); Entry deletedEntry = new DefaultEntry( dn , "objectClass: top", "objectClass: person", "cn: test", "sn: apache", "dc: apache" ); LdifEntry reversed = LdifRevertor.reverseDel( dn, deletedEntry ); assertNotNull( reversed ); assertEquals( dn.getName(), reversed.getDn().getName() ); assertEquals( ChangeType.Add, reversed.getChangeType() ); assertNotNull( reversed.getEntry() ); assertEquals( deletedEntry, reversed.getEntry() ); }
Example #8
Source File: ExceptionInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * Checks to make sure the entry being deleted exists, and has no children, otherwise throws the appropriate * LdapException. */ public void delete( DeleteOperationContext deleteContext ) throws LdapException { Dn dn = deleteContext.getDn(); if ( dn.equals( subschemSubentryDn ) ) { throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_253, subschemSubentryDn ) ); } next( deleteContext ); // Update the alias cache synchronized ( notAliasCache ) { if ( notAliasCache.containsKey( dn.getNormName() ) ) { notAliasCache.remove( dn.getNormName() ); } } }
Example #9
Source File: ExceptionInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException { Dn oldDn = moveAndRenameContext.getDn(); // Don't allow M&R in the SSSE if ( oldDn.equals( subschemSubentryDn ) ) { throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258, subschemSubentryDn, subschemSubentryDn ) ); } // Remove the original entry from the NotAlias cache, if needed synchronized ( notAliasCache ) { if ( notAliasCache.containsKey( oldDn.getNormName() ) ) { notAliasCache.remove( oldDn.getNormName() ); } } next( moveAndRenameContext ); }
Example #10
Source File: DefaultEntry.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * <p> * Creates a new instance of DefaultEntry, schema aware. * </p> * <p> * No attributes will be created. * </p> * * @param schemaManager The reference to the schemaManager * @param dn The String Dn for this serverEntry. Can be null. * @throws LdapInvalidDnException If the Dn is invalid */ public DefaultEntry( SchemaManager schemaManager, String dn ) throws LdapInvalidDnException { this.schemaManager = schemaManager; if ( Strings.isEmpty( dn ) ) { this.dn = Dn.EMPTY_DN; } else { this.dn = new Dn( dn ); normalizeDN( this.dn ); } // Initialize the ObjectClass object initObjectClassAT(); }
Example #11
Source File: TestDnNode.java From directory-ldap-api with Apache License 2.0 | 6 votes |
@Test public void testGetChildRdn() throws Exception { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn = new Dn( "dc=c,dc=b,dc=a" ); tree.add( dn, dn ); Rdn rdnA = new Rdn( "dc=a" ); Rdn rdnB = new Rdn( "dc=b" ); Rdn rdnC = new Rdn( "dc=c" ); DnNode<Dn> child = tree.getChild( rdnA ); assertNotNull( child ); assertEquals( rdnA, child.getRdn() ); child = child.getChild( rdnB ); assertNotNull( child ); assertEquals( rdnB, child.getRdn() ); child = child.getChild( rdnC ); assertNotNull( child ); assertEquals( rdnC, child.getRdn() ); }
Example #12
Source File: TestDnNode.java From directory-ldap-api with Apache License 2.0 | 6 votes |
@Test public void testGetParent() throws Exception { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn = new Dn( "dc=c,dc=b,dc=a" ); tree.add( dn, dn ); assertNull( tree.getParent() ); DnNode<Dn> child = tree.getChild( new Rdn( "dc=a" ) ); assertEquals( tree, child.getParent() ); DnNode<Dn> child1 = child.getChild( new Rdn( "dc=b" ) ); assertEquals( child, child1.getParent() ); child = child1.getChild( new Rdn( "dc=c" ) ); assertEquals( child1, child.getParent() ); }
Example #13
Source File: DefaultEntry.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void setDn( Dn dn ) { this.dn = dn; // Rehash the object rehash(); }
Example #14
Source File: LdapConnectionWrapper.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException { return connection.search( baseDn, filter, scope, attributes ); }
Example #15
Source File: DefaultCoreSession.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void move( Dn dn, Dn newParent, LogChange log ) throws LdapException { MoveOperationContext moveContext = new MoveOperationContext( this, dn, newParent ); moveContext.setLogChange( log ); OperationManager operationManager = directoryService.getOperationManager(); operationManager.move( moveContext ); }
Example #16
Source File: LdapDataProvider.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Method will retrieve the relative distinguished name from a distinguished name variable. * * @param dn contains ldap distinguished name. * @return rDn as string. */ protected String getRdn( String dn ) { try { return new Dn( dn ).getRdn().getName(); } catch ( LdapInvalidDnException lide ) { return null; } }
Example #17
Source File: BindRequestDsml.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Element toDsml( Element root ) { Element element = super.toDsml( root ); BindRequest request = getDecorated(); // Principal Dn dn = request.getDn(); if ( !Dn.isNullOrEmpty( dn ) ) { // A DN has been provided element.addAttribute( "principal", dn.getName() ); } else { // No DN has been provided, let's use the name as a string instead String name = request.getName(); element.addAttribute( "principal", name ); } return element; }
Example #18
Source File: BaseSubtreeSpecification.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Creates a simple subtree whose administrative point above the base and * all subordinates underneath the base (excluding those that are part of * inner areas) are part of the the subtree. * * @param base the base of the subtree relative to the administrative point */ @SuppressWarnings("unchecked") public BaseSubtreeSpecification( Dn base ) { this.base = base; this.minBaseDistance = 0; this.maxBaseDistance = UNBOUNDED_MAX; this.chopAfter = Collections.EMPTY_SET; this.chopBefore = Collections.EMPTY_SET; this.refinement = null; }
Example #19
Source File: ScopeNode.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Creates a new ScopeNode object. * * @param aliasDerefAliases the alias dereferencing mode * @param baseDn the search base * @param baseId the search ID * @param scope the search scope */ public ScopeNode( AliasDerefMode aliasDerefAliases, Dn baseDn, String baseId, SearchScope scope ) { super( AssertionType.SCOPE ); this.scope = scope; this.baseDn = baseDn; this.aliasDerefAliases = aliasDerefAliases; this.baseId = baseId; }
Example #20
Source File: LdapConnectionTemplate.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public <T> List<T> search( Dn baseDn, String filter, SearchScope scope, EntryMapper<T> entryMapper ) { return search( modelFactory.newSearchRequest( baseDn, filter, scope ), entryMapper ); }
Example #21
Source File: LdifRevertorTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test a reversed Modify replacing existing values with new values */ @Test public void testReverseModifyReplaceExistingOuValues() throws LdapException { Entry modifiedEntry = buildEntry(); Attribute ou = new DefaultAttribute( "ou", "apache", "acme corp" ); modifiedEntry.put( ou ); Dn dn = new Dn( "cn=test, ou=system" ); Attribute ouModified = new DefaultAttribute( "ou", "directory", "BigCompany inc." ); Modification mod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, ouModified ); LdifEntry reversed = LdifRevertor.reverseModify( dn, Collections.<Modification> singletonList( mod ), modifiedEntry ); assertNotNull( reversed ); assertEquals( dn.getName(), reversed.getDn().getName() ); assertEquals( ChangeType.Modify, reversed.getChangeType() ); assertNull( reversed.getEntry() ); List<Modification> mods = reversed.getModifications(); assertNotNull( mods ); assertEquals( 1, mods.size() ); Modification modif = mods.get( 0 ); assertEquals( ModificationOperation.REPLACE_ATTRIBUTE, modif.getOperation() ); Attribute attr = modif.getAttribute(); assertNotNull( attr ); assertEquals( ou, attr ); }
Example #22
Source File: DefaultEntry.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void setDn( Dn dn ) { this.dn = dn; // Rehash the object rehash(); }
Example #23
Source File: DefaultEntry.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // Read the Dn dn = new Dn( schemaManager ); dn.readExternal( in ); // Read the number of attributes int nbAttributes = in.readInt(); // Read the attributes for ( int i = 0; i < nbAttributes; i++ ) { // Read each attribute Attribute attribute = new DefaultAttribute(); attribute.readExternal( in ); if ( schemaManager != null ) { try { AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() ); attribute.apply( attributeType ); attributes.put( attributeType.getOid(), attribute ); } catch ( LdapException le ) { String message = le.getLocalizedMessage(); LOG.error( message ); throw new IOException( message ); } } else { attributes.put( attribute.getId(), attribute ); } } }
Example #24
Source File: ModelFactoryImpl.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public SearchRequest newSearchRequest( Dn baseDn, FilterBuilder filter, SearchScope scope, String... attributes ) { return newSearchRequest( baseDn, filter.toString(), scope, attributes ); }
Example #25
Source File: DnParserTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
@Test public void testAUmlautPlusBytes() throws Exception { String cn = new String( new byte[] { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, '\\', '2', 'B' }, StandardCharsets.UTF_8 ); Dn dn = new Dn( cn ); assertEquals( "cn=\u00c4\\2B", dn.getName() ); assertEquals( "cn=\u00c4\\+", dn.getEscaped() ); }
Example #26
Source File: TestDnNode.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test the addition of two overlapping DNs */ @Test public void testAdd2OverlappingDNs() throws LdapException { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn1 = new Dn( "dc=b,dc=a" ); Dn dn2 = new Dn( "dc=f,dc=a" ); tree.add( dn1, dn1 ); tree.add( dn2, dn2 ); assertNotNull( tree ); Map<String, DnNode<Dn>> children = tree.getChildren(); assertNotNull( children ); assertEquals( 1, children.size() ); assertNull( tree.getElement() ); DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ).getNormName() ); DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ).getNormName() ); Map<String, DnNode<Dn>> childrenDn1 = level1.getChildren(); assertNotNull( childrenDn1 ); assertEquals( 2, childrenDn1.size() ); assertNull( level1.getElement() ); assertNotNull( level2 ); assertEquals( dn1, level2.getElement() ); level1 = children.get( new Rdn( "dc=a" ).getNormName() ); level2 = level1.getChildren().get( new Rdn( "dc=f" ).getNormName() ); assertNotNull( level2 ); assertEquals( dn2, level2.getElement() ); }
Example #27
Source File: DnNormalizer.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException { Dn dn = new Dn( schemaManager, value ); return dn.getNormName(); }
Example #28
Source File: TestDnNode.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test the addition of a null Dn */ @Test public void testAddNullDNNoElem() throws LdapException { DnNode<Dn> tree = new DnNode<Dn>(); assertThrows( LdapUnwillingToPerformException.class, () -> { tree.add( null ); } ); }
Example #29
Source File: DefaultCoreSession.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public Entry lookup( Dn dn, String... attrIds ) throws LdapException { OperationManager operationManager = directoryService.getOperationManager(); LookupOperationContext lookupContext = new LookupOperationContext( this, dn, attrIds ); Entry entry = operationManager.lookup( lookupContext ); return entry; }
Example #30
Source File: DefaultCoreSession.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public boolean compare( Dn dn, String oid, Object value ) throws LdapException { OperationManager operationManager = directoryService.getOperationManager(); return operationManager.compare( new CompareOperationContext( this, dn, oid, convertToValue( oid, value ) ) ); }