Hi, Please bare with me I'm new to Hibernate, Spring and Acegi.
I'm using ACEGI to provide the Security framework for my Web Application and I'm having some issues with my Junit tests. I'm trying to load the Spring Application Context in a JUnit test and I'm getting the following errors. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceManager' defined in class path resource [applicationContext-test.xml]: Initialization of bean failed; nested exception is net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext nner.main(RemoteTestRunner.java:186) at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.interceptor(Abstr actSecurityInterceptor.java:280) at net.sf.acegisecurity.intercept.method.MethodSecurityInterceptor.invoke(Metho dSecurityInterceptor.java:82) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect iveMethodInvocation.java:138) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(Tr ansactionInterceptor.java:56) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect iveMethodInvocation.java:138) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopPro xy.java:152) Is this normal? Do I need to setup the SecureContext when calling new ClassPathXmlApplicationContext(fileNames);? After poking around the JUnit test that came with the Hispacta project I found this piece of code: protected void setCurrentUser(String username, String password) { Authentication auth = new UsernamePasswordAuthenticationToken(username, password, authorities); SecureContext secureContext = new SecureContextImpl(); secureContext.setAuthentication(auth); ContextHolder.setContext(secureContext); } After implementing the method and calling it with a bogus Username and Password, because I do not have any users in my database yet, I get this error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceManager' defined in class path resource [applicationContext-test.xml]: Initialization of bean failed; nested exception is net.sf.acegisecurity.BadCredentialsException: Bad credentials presented at net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider.getUserFromBack end(DaoAuthenticationProvider.java:314) at net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider.authenticate(Da oAuthenticationProvider.java:193) at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderMana ger.java:128) at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuth enticationManager.java:49) at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.interceptor(Abstr actSecurityInterceptor.java:294) at net.sf.acegisecurity.intercept.method.MethodSecurityInterceptor.invoke(Metho dSecurityInterceptor.java:82) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect iveMethodInvocation.java:138) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(Tr ansactionInterceptor.java:56) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect iveMethodInvocation.java:138) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopPro xy.java:152) So, I'm guessing it is trying to authenticate the Username and Password I provided using the daoAuthenticationProvider that is setup in the ApplicationContext. After searching the ACEGI's developers mailing list I found a similar issue and the solution was to use the TestingAuthenticationToken. So I replaced the UsernamePasswordAuthenticationToken with the TestingAuthenticationToken and I get this error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceManager' defined in class path resource [applicationContext-test.xml]: Initialization of bean failed; nested exception is net.sf.acegisecurity.providers.ProviderNotFoundException: No authentication provider for net.sf.acegisecurity.providers.TestingAuthenticationToken net.sf.acegisecurity.providers.ProviderNotFoundException: No authentication provider for net.sf.acegisecurity.providers.TestingAuthenticationToken at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderMana ger.java:136) at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuth enticationManager.java:49) at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.interceptor(Abstr actSecurityInterceptor.java:294) at net.sf.acegisecurity.intercept.method.MethodSecurityInterceptor.invoke(Metho dSecurityInterceptor.java:82) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect iveMethodInvocation.java:138) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(Tr ansactionInterceptor.java:56) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect iveMethodInvocation.java:138) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopPro xy.java:152)Guy Tuberson I can get my JUnit test to work if I remove the SecurityInterceptor from the AutoTxProxyCreator. See attached ApplicationContext: <<applicationContext-test.xml>> Thanks, Software Engineer [EMAIL PROTECTED] 703-263-0100 ########################################### This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange. For more information, connect to http://www.F-Secure.com/
applicationContext-test.xml
Description: Binary data