I am using Spring Security 3.1 to authenticate users for a website. When a login fails because spring security is unable to connect to the database, I get the following statement in my log:
2012-07-12 11:42:45,419 [ajp-bio-8009-exec-1] DEBUG org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter - Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
My question is, why is this a DEBUG statement instead of an ERROR? I have to wade through a whole lot of debug statements just to find the actual error.
EDIT
Here is my authentication manager:
<bean id="securityDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/securityDS"/>
<property name="resourceRef" value="true"/>
</bean>
<bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder" />
<security:authentication-manager>
<security:authentication-provider>
<security:password-encoder ref="encoder" />
<security:jdbc-user-service
data-source-ref="securityDataSource"
authorities-by-username-query="SELECT username, authority FROM login WHERE username = ?"
users-by-username-query="SELECT username, password, enabled FROM login WHERE username = ?"
/>
</security:authentication-provider>
</security:authentication-manager>
That message is printed out in
AbstractAuthenticationProcessingFilter.unsuccessfulAuthentication:There are a number of ways an authentication can fail, including based on user input. For example, in
AbstractUserDetailsAuthenticationProvider.authenticate, aBadCredentialsExceptioncould be thrown if the username is not found:Since there could be legitimate reasons why an authentication can fail, it doesn’t make sense for
AbstractAuthenticationProcessingFilterto log an error. If there is a system error the error should have been logged further downstream.I suspect that the problem is in
DaoAuthenticationProvider(see my comment inline):Perhaps an error should be logged here – you can log a JIRA with Spring to request that. Though maybe they are assuming that everyone is going to provide a custom
UserDetailsServiceand will catch/log their own exceptions there. If you are usingJdbcDaoImplit does not. I thinkJdbcDaoImplis intended to be an example and is not robust. Per the docs: