org.apache.directory.server.core.api.interceptor.context.HasEntryOperationContext Java Examples

The following examples show how to use org.apache.directory.server.core.api.interceptor.context.HasEntryOperationContext. 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: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
{
    Dn dn = hasEntryContext.getDn();

    if ( IS_DEBUG )
    {
        LOG.debug( "Check if Dn '" + dn + "' exists." );
    }

    if ( dn.isRootDse() )
    {
        return true;
    }

    Partition partition = getPartition( dn );

    return partition.hasEntry( hasEntryContext );
}
 
Example #2
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
{
    Dn dn = hasEntryContext.getDn();

    if ( IS_DEBUG )
    {
        LOG.debug( "Check if Dn '" + dn + "' exists." );
    }

    if ( dn.isRootDse() )
    {
        return true;
    }

    Partition partition = getPartition( dn );

    return partition.hasEntry( hasEntryContext );
}
 
Example #3
Source File: LDAPIAMPoller.java    From aws-iam-ldap-bridge with Apache License 2.0 6 votes vote down vote up
private void ensureDNs() throws LdapException, IOException, ParseException, CursorException {
    directory.getPartitionNexus().hasEntry(new HasEntryOperationContext(directory.getAdminSession(),
            directory.getDnFactory().create(rootDN)));
    if (!directory.getPartitionNexus().hasEntry(new HasEntryOperationContext(directory.getAdminSession(),
            directory.getDnFactory().create(usersDN)))) {
        createEntry(usersDN, "organizationalUnit");
    }
    if (!directory.getPartitionNexus().hasEntry(new HasEntryOperationContext(directory.getAdminSession(),
            directory.getDnFactory().create(groupsDN)))) {
        createEntry(groupsDN, "organizationalUnit");
    }
    if (!directory.getPartitionNexus().hasEntry(new HasEntryOperationContext(directory.getAdminSession(),
            directory.getDnFactory().create(rolesDN)))) {
        createEntry(rolesDN, "organizationalUnit");
    }
}
 
Example #4
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean exists( Dn dn ) throws LdapException
{
    HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( this, dn );
    OperationManager operationManager = directoryService.getOperationManager();

    return operationManager.hasEntry( hasEntryContext );
}
 
Example #5
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean exists( Dn dn ) throws LdapException
{
    HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( this, dn );
    OperationManager operationManager = directoryService.getOperationManager();

    return operationManager.hasEntry( hasEntryContext );
}
 
Example #6
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
{
    Dn dn = hasEntryContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        hasEntryContext.setDn( new Dn( schemaManager, dn ) );
    }

    return next( hasEntryContext );
}
 
Example #7
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
{
    if ( IS_DEBUG )
    {
        OPERATION_LOG.debug( ">> hasEntryOperation : {}", hasEntryContext );
    }

    long opStart = 0L;

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

    ensureStarted();

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

    boolean result = false;

    lockRead();

    try
    {
        result = head.hasEntry( hasEntryContext );
    }
    finally
    {
        unlockRead();
    }

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

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

    return result;
}
 
Example #8
Source File: MyVDInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasEntry(HasEntryOperationContext has)
		throws LdapException {
	HashMap<Object,Object> userRequest = new HashMap<Object,Object>();
	
	//how to track?
	HashMap<Object,Object> userSession = has.getSession().getUserSession();
	if (userSession.get(SessionVariables.BOUND_INTERCEPTORS) == null) {
		userSession.put(SessionVariables.BOUND_INTERCEPTORS,new ArrayList<String>());
	}
	
	DistinguishedName bindDN;
	byte[] password;
	
	if (has.getSession().isAnonymous()) {
		bindDN = new DistinguishedName("");
		password = null;
	} else {
		bindDN = new DistinguishedName(has.getSession().getAuthenticatedPrincipal().getDn().getName());
		if (has.getSession().getAuthenticatedPrincipal().getUserPasswords() != null) {
			password = has.getSession().getAuthenticatedPrincipal().getUserPasswords()[0];
		} else {
			password = null;
		}
	}
	
	Password pass = new Password(password);
	
	
	SearchInterceptorChain chain = new SearchInterceptorChain(bindDN,pass,0,this.globalChain,userSession,userRequest,this.router);
	Results res = new Results(this.globalChain);
	Entry entry = new DefaultEntry();
	try {
		ArrayList<net.sourceforge.myvd.types.Attribute> attrs = new ArrayList<net.sourceforge.myvd.types.Attribute>();
		net.sourceforge.myvd.types.Attribute none = new net.sourceforge.myvd.types.Attribute("1.1");
		attrs.add(none);
		chain.nextSearch(new DistinguishedName(has.getDn().getName()), new Int(0), new Filter("(objectClass=*)"), attrs, new Bool(false), res, new LDAPSearchConstraints());
		
		boolean more = res.hasMore();
		
		if (more) {
			res.next();
			while (res.hasMore()) res.next();
			return true;
		} else {
			return false;
		}
		
	} catch (LDAPException e1) {
		if (e1.getResultCode() == 32) {
			return false;
		} else {
			throw generateException(e1);
		}
	}
}
 
Example #9
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
{
    if ( IS_DEBUG )
    {
        OPERATION_LOG.debug( ">> hasEntryOperation : {}", hasEntryContext );
    }

    long opStart = 0L;

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

    ensureStarted();

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

    boolean result = false;

    lockRead();

    try
    {
        result = head.hasEntry( hasEntryContext );
    }
    finally
    {
        unlockRead();
    }

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

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

    return result;
}
 
Example #10
Source File: MyVDInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasEntry(HasEntryOperationContext has)
		throws LdapException {
	HashMap<Object,Object> userRequest = new HashMap<Object,Object>();
	
	//how to track?
	HashMap<Object,Object> userSession = has.getSession().getUserSession();
	if (userSession.get(SessionVariables.BOUND_INTERCEPTORS) == null) {
		userSession.put(SessionVariables.BOUND_INTERCEPTORS,new ArrayList<String>());
	}
	
	DistinguishedName bindDN;
	byte[] password;
	
	if (has.getSession().isAnonymous()) {
		bindDN = new DistinguishedName("");
		password = null;
	} else {
		bindDN = new DistinguishedName(has.getSession().getAuthenticatedPrincipal().getDn().getName());
		if (has.getSession().getAuthenticatedPrincipal().getUserPasswords() != null) {
			password = has.getSession().getAuthenticatedPrincipal().getUserPasswords()[0];
		} else {
			password = null;
		}
	}
	
	Password pass = new Password(password);
	
	
	SearchInterceptorChain chain = new SearchInterceptorChain(bindDN,pass,0,this.globalChain,userSession,userRequest,this.router);
	Results res = new Results(this.globalChain);
	Entry entry = new DefaultEntry();
	try {
		ArrayList<net.sourceforge.myvd.types.Attribute> attrs = new ArrayList<net.sourceforge.myvd.types.Attribute>();
		net.sourceforge.myvd.types.Attribute none = new net.sourceforge.myvd.types.Attribute("1.1");
		attrs.add(none);
		chain.nextSearch(new DistinguishedName(has.getDn().getName()), new Int(0), new Filter("(objectClass=*)"), attrs, new Bool(false), res, new LDAPSearchConstraints());
		
		boolean more = res.hasMore();
		
		if (more) {
			res.next();
			while (res.hasMore()) res.next();
			return true;
		} else {
			return false;
		}
		
	} catch (LDAPException e1) {
		if (e1.getResultCode() == 32) {
			return false;
		} else {
			throw generateException(e1);
		}
	}
}