sessionController.checkAuthenticationAllowed(authentication);
    public Authentication doAuthentication(Authentication authentication)        throws AuthenticationException {        Iterator iter = providers.iterator();        Class toTest = authentication.getClass();        sessionController.checkAuthenticationAllowed(authentication);        AuthenticationException lastException = null;        while (iter.hasNext()) {            AuthenticationProvider provider = (AuthenticationProvider) iter                .next();            if (provider.supports(toTest)) {                logger.debug("Authentication attempt using "                    + provider.getClass().getName());                Authentication result = null;                try {                    result = provider.authenticate(authentication);                } catch (AuthenticationException ae) {                    lastException = ae;                }                if (result != null) {                    sessionController.registerSuccessfulAuthentication(result);                    applicationEventPublisher.publishEvent(new AuthenticationSuccessEvent(result));                    return result;                }            }        }        if (lastException == null) {        	lastException = new ProviderNotFoundException("No authentication provider for " + toTest.getName());        }    	// Publish the event        String className = exceptionMappings.getProperty(lastException.getClass().getName());        AbstractAuthenticationEvent event = null;        if (className != null) {        	try {        		Class clazz = getClass().getClassLoader().loadClass(className);        		Constructor constructor = clazz.getConstructor(new Class[] {Authentication.class, AuthenticationException.class});        		Object obj = constructor.newInstance(new Object[] {authentication, lastException});        		Assert.isInstanceOf(AbstractAuthenticationEvent.class, obj, "Must be an AbstractAuthenticationEvent");        		event = (AbstractAuthenticationEvent) obj;        	} catch (ClassNotFoundException ignored) {        	} catch (NoSuchMethodException ignored) {        	} catch (IllegalAccessException ignored) {        	} catch (InstantiationException ignored) {        	} catch (InvocationTargetException ignored) {        	}        }        Assert.notNull(event, "A valid event must be available for the exception " + lastException.getClass().getName());        applicationEventPublisher.publishEvent(event);                // Throw the exception        throw lastException;    }