doAuthSasl( ctx );
authList = "none"; }  }  authList = StringTools.deepTrim( authList ); String[] auth = authList.split( " " );  Collection authenticators = null;   for ( int i=0; i<auth.length; i++) { authenticators = getAuthenticators( auth[i] ); if ( authenticators != null ) break; }  if ( authenticators == null ) { ctx.getEnvironment(); ResultCodeEnum rc = ResultCodeEnum.AUTHMETHODNOTSUPPORTED; throw new LdapAuthenticationNotSupportedException( rc ); }   for ( Iterator i = authenticators.iterator(); i.hasNext(); ) { try { Authenticator authenticator = ( Authenticator ) i.next();   LdapPrincipal authorizationId = authenticator.authenticate( ctx );   ctx.setPrincipal( authorizationId );   ctx.removeFromEnvironment( CREDS );  return; } catch ( LdapAuthenticationException e ) {
    public void invoke( Invocation invocation ) throws NamingException    {        // only handle preinvocation state        if ( invocation.getState() != InvocationStateEnum.PREINVOCATION )        {            return;        }        // check if we are already authenticated and if so we return making        // sure first that the credentials are not exposed within context        ServerContext ctx = ( ServerLdapContext ) invocation.getContextStack().peek();        if ( ctx.getPrincipal() != null )        {            if ( ctx.getEnvironment().containsKey( CREDS ) )            {                ctx.removeFromEnvironment( CREDS );            }            return;        }        // check the kind of authentication being performed        if ( ctx.getEnvironment().containsKey( AUTH_TYPE ) )        {            // authentication type can be anything            String auth = ( String ) ctx.getEnvironment().get( AUTH_TYPE );            if ( auth.equalsIgnoreCase( "none" ) )            {                doAuthNone( ctx );            }            else if ( auth.equalsIgnoreCase( "simple" ) )            {                doAuthSimple( ctx );            }            else            {                doAuthSasl( ctx );            }        }        else if ( ctx.getEnvironment().containsKey( CREDS ) )        {            // authentication type is simple here            doAuthSimple( ctx );        }        else        {            // authentication type is anonymous            doAuthNone( ctx );        }        // remove creds so there is no security risk        ctx.removeFromEnvironment( CREDS );    }