org.apache.directory.api.ldap.model.exception.LdapException Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.exception.LdapException. 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: DefaultComparatorRegistry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void unregisterSchemaElements( String schemaName ) throws LdapException
{
    if ( schemaName == null )
    {
        return;
    }

    // Loop on all the SchemaObjects stored and remove those associated
    // with the give schemaName
    for ( LdapComparator<?> comparator : this )
    {
        if ( schemaName.equalsIgnoreCase( comparator.getSchemaName() ) )
        {
            String oid = comparator.getOid();
            SchemaObject removed = unregister( oid );

            if ( LOG.isDebugEnabled() )
            {
                LOG.debug( I18n.msg( I18n.MSG_13702_REMOVED_FROM_REGISTRY, removed, oid ) );
            }
        }
    }
}
 
Example #2
Source File: FastParserRdnTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleRdnValueNullSchemaManager() throws LdapException
{
    String errors = null;
    
    Rdn rdn = new Rdn( (SchemaManager)null, "Cn= TEST " );
    
    if ( !"Cn= TEST ".equals( rdn.getName() ) )
    {
        errors += "\nRdn.getName fails '" + rdn.getName() + "'";
    }
    
    if ( !"Cn=TEST".equals( rdn.getNormName() ) )
    {
        errors = "\nRdn.getNormName fails '" + rdn.getNormName() + "'";
    }
    
    if ( !"TEST".equals( rdn.getValue( "cn" ) ) )
    {
        errors += "\nRdn.getNormValue( 'cn' ) fails '" + ( String ) rdn.getValue( "cn" ) + "'";
    }
    
    assertEquals( null, errors );
}
 
Example #3
Source File: DefaultDitStructureRuleRegistry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DitStructureRule lookup( int ruleId ) throws LdapException
{
    DitStructureRule ditStructureRule = byRuleId.get( ruleId );

    if ( ditStructureRule == null )
    {
        String msg = I18n.err( I18n.ERR_13731_DIT_STRUCTURE_RULE_DOES_NOT_EXIST, ruleId );
        
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( msg );
        }
        
        throw new LdapException( msg );
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_13724_FOUND_WITH_RULE_ID, ditStructureRule, ruleId ) );
    }

    return ditStructureRule;
}
 
Example #4
Source File: AddRequestImplTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test for inequality when only the IDs are different.
 */
@Test
public void testNotEqualDiffId() throws LdapException
{
    AddRequestImpl req0 = new AddRequestImpl();
    req0.setMessageId( 7 );
    req0.setEntryDn( new Dn( "cn=admin,dc=example,dc=com" ) );
    req0.setEntry( getEntry() );

    AddRequestImpl req1 = new AddRequestImpl();
    req1.setMessageId( 5 );
    req1.setEntryDn( new Dn( "cn=admin,dc=example,dc=com" ) );
    req1.setEntry( getEntry() );

    assertFalse( req0.equals( req1 ) );
}
 
Example #5
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * This method is used to initialize the OBJECT_CLASS_AT attributeType.
 *
 * We want to do it only once, so it's a synchronized method. Note that
 * the alternative would be to call the lookup() every time, but this won't
 * be very efficient, as it will get the AT from a map, which is also
 * synchronized, so here, we have a very minimal cost.
 *
 * We can't do it once as a static part in the body of this class, because
 * the access to the registries is mandatory to get back the AttributeType.
 */
private void initObjectClassAT()
{
    if ( schemaManager == null )
    {
        return;
    }

    try
    {
        synchronized ( MUTEX )
        {
            if ( objectClassAttributeType == null )
            {
                objectClassAttributeType = schemaManager
                    .lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
            }
        }
    }
    catch ( LdapException ne )
    {
        // do nothing...
    }
}
 
Example #6
Source File: DnTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Normalize a simple Dn with a # on first position
 */
@Test
public void testNormalizeDnSharpFirst() throws LdapException, LdapException
{
    Dn dn = new Dn( "ou = \\#this is a sharp" );

    assertTrue( Dn.isValid( "ou = \\#this is a sharp" ) );
    assertEquals( "ou=\\#this is a sharp", dn.getEscaped() );
    assertEquals( "ou = \\#this is a sharp", dn.getName() );

    // Check the normalization now
    Dn ndn = new Dn( schemaManager, dn );

    assertEquals( "ou = \\#this is a sharp", ndn.getName() );
    assertEquals( "ou=\\#this is a sharp", ndn.getEscaped() );
}
 
Example #7
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@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 #8
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for removeAttributes( String... )
 */
@Test
public void testRemoveAttributesStringArray() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" );
    Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" );
    Attribute attrSN = new DefaultAttribute( "sn", "Test1", "Test2" );
    Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 );

    entry.put( attrOC, attrCN, attrSN, attrPWD );

    entry.removeAttributes( "CN", "SN" );

    assertFalse( entry.containsAttribute( "cn", "sn" ) );
    assertTrue( entry.containsAttribute( "objectclass", "userpassword" ) );

    entry.removeAttributes( "badId" );

    entry.removeAttributes( ( String ) null );
}
 
Example #9
Source File: RdnTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a simple Rdn with differents separators : a = b + c = d
 * 
 * @throws LdapException
 */
@Test
public void testRdnSimpleMultivaluedAttribute() throws LdapException
{
    String result = new Rdn( "a = b + c = d" ).getName();
    assertEquals( "a = b + c = d", result );
}
 
Example #10
Source File: FastDnParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a composite Dn with multiple NC and separators : a=b+c=d, e=f + g=h +
 * i=j
 */
@Test
public void testLdapDNCompositeMultivaluedAttribute() throws LdapException
{
    assertThrows( TooComplexDnException.class, () -> 
    {
        FastDnParser.parse( "a=b+c=d, e=f + g=h + i=j" );
    } );
}
 
Example #11
Source File: DummyNormalizer.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException
{
    if ( Strings.isEmpty( value ) )
    {
        return value;
    }

    return value;
}
 
Example #12
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void rename( Dn dn, Rdn newRdn, boolean deleteOldRdn, boolean ignoreReferral, LogChange log )
    throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();
    RenameOperationContext renameContext = new RenameOperationContext( this, dn, newRdn, deleteOldRdn );

    renameContext.setLogChange( log );
    setReferralHandling( renameContext, ignoreReferral );

    operationManager.rename( renameContext );
}
 
Example #13
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Entry getRootDse( GetRootDseOperationContext getRootDseContext ) throws LdapException
{
    if ( IS_DEBUG )
    {
        OPERATION_LOG.debug( ">> GetRootDseOperation : {}", getRootDseContext );
    }

    long opStart = 0L;

    if ( IS_TIME )
    {
        opStart = System.nanoTime();
    }

    ensureStarted();

    Interceptor head = directoryService.getInterceptor( getRootDseContext.getNextInterceptor() );

    Entry root = head.getRootDse( getRootDseContext );

    if ( IS_DEBUG )
    {
        OPERATION_LOG.debug( "<< getRootDseOperation successful" );
    }

    if ( IS_TIME )
    {
        OPERATION_TIME.debug( "GetRootDSE operation took " + ( System.nanoTime() - opStart ) + " ns" );
    }

    return root;
}
 
Example #14
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AddResponse add( Dn dn, final Attribute... attributes )
{
    return add( dn,
        new RequestBuilder<AddRequest>()
        {
            @Override
            public void buildRequest( AddRequest request ) throws LdapException
            {
                request.getEntry().add( attributes );
            }
        } );
}
 
Example #15
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Entry add( AttributeType attributeType, Value... values ) throws LdapException
{
    if ( attributeType == null )
    {
        String message = I18n.err( I18n.ERR_13203_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
        LOG.error( message );
        throw new IllegalArgumentException( message );
    }

    Attribute attribute = attributes.get( attributeType.getOid() );

    if ( attribute != null )
    {
        // This Attribute already exist, we add the values
        // into it
        attribute.add( values );
    }
    else
    {
        // We have to create a new Attribute and set the values.
        // The upId, which is set to null, will be setup by the
        // createAttribute method
        createAttribute( null, attributeType, values );
    }

    return this;
}
 
Example #16
Source File: ImmutableAttributeTypeRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void addMappingFor( AttributeType attributeType ) throws LdapException
{
    throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, 
        I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
}
 
Example #17
Source File: DefaultSchemaObjectRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public T get( String oid )
{
    try
    {
        return oidRegistry.getSchemaObject( oid );
    }
    catch ( LdapException ne )
    {
        return null;
    }
}
 
Example #18
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a ModificationItem to an instance of a ServerModification object
 *
 * @param modificationImpl the modification instance to convert
 * @param attributeType the associated attributeType
 * @return a instance of a ServerModification object
 */
private static Modification toServerModification( ModificationItem modificationImpl, AttributeType attributeType )
    throws LdapException
{
    ModificationOperation operation;

    switch ( modificationImpl.getModificationOp() )
    {
        case DirContext.REMOVE_ATTRIBUTE:
            operation = ModificationOperation.REMOVE_ATTRIBUTE;
            break;

        case DirContext.REPLACE_ATTRIBUTE:
            operation = ModificationOperation.REPLACE_ATTRIBUTE;
            break;

        case DirContext.ADD_ATTRIBUTE:
        default:
            operation = ModificationOperation.ADD_ATTRIBUTE;
            break;

    }

    Modification modification = new DefaultModification(
        operation,
        ServerEntryUtils.toServerAttribute( modificationImpl.getAttribute(), attributeType ) );

    return modification;

}
 
Example #19
Source File: LdapLoginManager.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
private static void bindAdmin(LdapConnection conn, LdapOptions options) throws LdapException {
	if (!Strings.isEmpty(options.adminDn)) {
		conn.bind(options.adminDn, options.adminPasswd);
	} else {
		conn.bind();
	}
}
 
Example #20
Source File: LDAPApi.java    From mamute with Apache License 2.0 5 votes vote down vote up
private LdapConnection connection(String username, String password) throws LdapException {
	// Manually build the configuration since the convenience constructor in 
	// the LdapNetworkConnection doesn't let us specify a TLS setting			
	LdapConnectionConfig config = new LdapConnectionConfig();
	config.setLdapHost(host);
	config.setLdapPort(port);
	config.setUseTls(useTls);
	config.setUseSsl(useSsl);
       LdapNetworkConnection conn = new LdapNetworkConnection(config);
	
	conn.bind(username, password);
	return conn;
}
 
Example #21
Source File: DnTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test for DIRSERVER-184
 * @throws LdapException
 */
@Test
public void testDIRSERVER_184_7()
{
    try
    {
        new Dn( "dn=a trailing pound #" );
    }
    catch ( LdapException ine )
    {
        assertTrue( true );
    }
}
 
Example #22
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException
{
    if ( attributeType == null )
    {
        return false;
    }

    try
    {
        Attribute attribute = attributes.get( attributeType.getOid() );

        if ( attribute == null )
        {
            // Can't remove values from a not existing attribute !
            return false;
        }

        int nbOldValues = attribute.size();

        // Remove the values
        attribute.remove( values );

        if ( attribute.size() == 0 )
        {
            // No mare values, remove the attribute
            attributes.remove( attributeType.getOid() );

            return true;
        }

        return nbOldValues != attribute.size();
    }
    catch ( IllegalArgumentException iae )
    {
        LOG.error( I18n.err( I18n.ERR_13205_CANNOT_REMOVE_VAL_MISSING_ATTR, attributeType ) );
        return false;
    }
}
 
Example #23
Source File: SetCursor.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void beforeFirst() throws LdapException, CursorException
{
    checkNotClosed();
    this.index = -1;
}
 
Example #24
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for getDN()
 */
@Test
public void testGetDn() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    assertEquals( exampleDn, entry.getDn() );

    Dn testDn = new Dn( "cn=test" );
    entry.setDn( testDn );

    assertEquals( testDn, entry.getDn() );
}
 
Example #25
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for hashcode()
 */
@Test
public void testHashCode() throws LdapException, LdapException
{
    Entry entry1 = new DefaultEntry( exampleDn );
    Entry entry2 = new DefaultEntry( exampleDn );

    assertEquals( entry1.hashCode(), entry2.hashCode() );

    entry2.setDn( new Dn( "ou=system,dc=com" ) );
    assertNotSame( entry1.hashCode(), entry2.hashCode() );

    entry2.setDn( exampleDn );
    assertEquals( entry1.hashCode(), entry2.hashCode() );

    Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" );
    Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" );
    Attribute attrSN = new DefaultAttribute( "sn", "Test1", "Test2" );
    Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 );

    entry1.add( attrOC, attrCN, attrSN, attrPWD );
    entry2.add( attrOC, attrCN, attrSN, attrPWD );

    assertEquals( entry1.hashCode(), entry2.hashCode() );

    Entry entry3 = new DefaultEntry( exampleDn );
    entry3.add( attrOC, attrSN, attrCN, attrPWD );

    assertEquals( entry1.hashCode(), entry3.hashCode() );
}
 
Example #26
Source File: DnTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test for DIRSERVER-191
 */
@Test
public void testGetPrefixName() throws LdapException, InvalidNameException
{
    LdapName jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
    Dn aName = new Dn( "cn=four,cn=three,cn=two,cn=one" );

    assertEquals( jName.getPrefix( 0 ).toString(), aName.getAncestorOf( "cn=four,cn=three,cn=two,cn=one" )
        .toString() );
    assertEquals( jName.getPrefix( 1 ).toString(), aName.getAncestorOf( "cn=four,cn=three,cn=two" ).toString() );
    assertEquals( jName.getPrefix( 2 ).toString(), aName.getAncestorOf( "cn=four,cn=three" ).toString() );
    assertEquals( jName.getPrefix( 3 ).toString(), aName.getAncestorOf( "cn=four" ).toString() );
    assertEquals( jName.getPrefix( 4 ).toString(), aName.getAncestorOf( "" ).toString() );
}
 
Example #27
Source File: FastDnParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testVsldapExtras() throws LdapException
{
    assertThrows( TooComplexDnException.class, () -> 
    {
        FastDnParser
            .parse( "cn=Billy Bakers, OID.2.5.4.11=Corporate Tax, ou=Fin-Accounting, ou=Americas, ou=Search, o=IMC, c=US" );
    } );
}
 
Example #28
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException
{
    if ( attributeType == null )
    {
        return false;
    }

    try
    {
        Attribute attribute = attributes.get( attributeType.getOid() );

        if ( attribute == null )
        {
            // Can't remove values from a not existing attribute !
            return false;
        }

        int nbOldValues = attribute.size();

        // Remove the values
        attribute.remove( values );

        if ( attribute.size() == 0 )
        {
            // No mare values, remove the attribute
            attributes.remove( attributeType.getOid() );

            return true;
        }

        return nbOldValues != attribute.size();
    }
    catch ( IllegalArgumentException iae )
    {
        LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
        return false;
    }
}
 
Example #29
Source File: StringValueAttributeTypeTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the instanceOf method
 */
@Test
public void testInstanceOf() throws LdapException
{
    AttributeType attribute = EntryUtils.getIA5StringAttributeType();
    Value ssv = Value.createValue( attribute );

    assertTrue( ssv.isInstanceOf( attribute ) );

    attribute = EntryUtils.getBytesAttributeType();

    assertFalse( ssv.isInstanceOf( attribute ) );
}
 
Example #30
Source File: UserDAO.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * @param user
 * @throws UpdateException
 */
void resetUserPassword( User user ) throws UpdateException
{
    LdapConnection ld = null;
    String userDn = getDn( user.getUserId(), user.getContextId() );

    try
    {
        List<Modification> mods = new ArrayList<Modification>();

        mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants
            .USER_PASSWORD_AT, user.getPassword() ) );

        mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, OPENLDAP_PW_RESET, "TRUE" ) );

        ld = getAdminConnection();
        modify( ld, userDn, mods, user );
    }
    catch ( LdapException e )
    {
        String warning = "resetUserPassword userId [" + user.getUserId() + "] caught LDAPException=" + e
            .getMessage();
        throw new UpdateException( GlobalErrIds.USER_PW_RESET_FAILED, warning, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
}