This one makes no sense to me because i am certain everything is there
This is what i get in the login form
Your login attempt was not successful, try again. Reason:
PreparedStatementCallback; SQL [SELECT user_name, user_password,
enabled, email_address, id, user_first_name, user_last_name FROM user
WHERE user_name = ?]; Column Index out of range, 8 > 7. ; nested
exception is java.sql.SQLException: Column Index out of range, 8 > 7.
.
The bean in applicationContext-security.xml file for the authentication
<beans:bean id="customUserDetailsService" class="com.au.dealclick.implementations.CustomJdbcDaoImpl">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="usersByUsernameQuery" value="SELECT user_name, user_password, enabled, email_address, id, user_first_name, user_last_name, city FROM user WHERE user_name = ?"/>
<beans:property name="authoritiesByUsernameQuery" value="SELECT user_name , R.name FROM user U, roles R WHERE U.roles = R.Id AND user_name=?"/>
</beans:bean>
This is the customJdbcDaoImpl.java file
package com.au.dealclick.implementations;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContextException;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.MappingSqlQuery;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl;
import org.springframework.security.core.authority.AuthorityUtils;
import com.au.dealclick.implementations.UserDetailsImplementation;
public class CustomJdbcDaoImpl extends JdbcDaoImpl {
private MappingSqlQuery usersByUsernameMapping;
@Override
protected void initDao() throws ApplicationContextException {
super.initDao();
this.usersByUsernameMapping = new CustomUsersByUsernameMapping(getDataSource());
}
@Override
protected List<UserDetails> loadUsersByUsername(String username) {
return usersByUsernameMapping.execute(username);
}
@Override
protected UserDetails createUserDetails(String username, UserDetails userFromUserQuery,
List<GrantedAuthority> combinedAuthorities) {
UserDetails u = super.createUserDetails(username, userFromUserQuery, combinedAuthorities);
UserDetailsImplementation user = new UserDetailsImplementation(u.getUsername(), u.getPassword(), u.isEnabled(), u.isAccountNonExpired(), u.isCredentialsNonExpired(), u.isAccountNonLocked(), u.getAuthorities());
UserDetailsImplementation customUserFromUserQuery = (UserDetailsImplementation) userFromUserQuery;
user.setEmailAddress(customUserFromUserQuery.getEmailAddress());
user.setId(customUserFromUserQuery.getId());
user.setFirstName(customUserFromUserQuery.getFirstName());
user.setLastName(customUserFromUserQuery.getLastName());
user.setCityId(customUserFromUserQuery.getCityId());
return user;
}
private class CustomUsersByUsernameMapping extends MappingSqlQuery {
protected CustomUsersByUsernameMapping(DataSource dataSource) {
super(dataSource, getUsersByUsernameQuery());
declareParameter(new SqlParameter(Types.VARCHAR));
compile();
}
protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
String username = rs.getString(1);
String password = rs.getString(2);
boolean enabled = rs.getBoolean(3);
String email = rs.getString(4);
Long id = rs.getLong(5);
//Reference city
String firstName = rs.getString(6);
String lastName = rs.getString(7);
Long city = rs.getLong(8);
UserDetailsImplementation user = new UserDetailsImplementation(username, password, enabled, true, true, true, AuthorityUtils.NO_AUTHORITIES);
user.setEmailAddress(email);
user.setId(id);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setCityId(city);
return user;
}
}
}
This is the userDetailsImplementation.java file
package com.au.dealclick.implementations;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.Authentication;
import java.security.*;
import javax.persistence.*;
import java.lang.*;
import org.springframework.security.core.GrantedAuthority;
import java.util.*;
import com.au.dealclick.domain.Location;
public class UserDetailsImplementation extends User{
public UserDetailsImplementation(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, List<GrantedAuthority> authorities) {
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
}
public UserDetailsImplementation(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<GrantedAuthority> authorities) {
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
}
private Long id;
private String userFirstName;
private String userLastName;
private String emailAddress;
private Long city;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getFirstName() { return userFirstName; }
public void setFirstName(String userFirstName) { this.userFirstName = userFirstName; }
public String getLastName() { return userLastName; }
public void setLastName(String userLastName) { this.userLastName = userLastName; }
public Long getCityId() { return city; }
public void setCityId(Long city) { this.city = city; }
public String getEmailAddress() { return emailAddress; }
public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; }
}
Is it possible that the applicationContext-security.xml file that you are running against is not the one that you have posted? It could be something to do with your build not copying the file to the runtime location for some reason.
How is your running app deployed? e.g. WAR, WAR exploded, standalone jar etc. Try comparing the file in the runtime location with the source location.