这个对我毫无意义,因为我确信一切都在那里
这是我在登录表单中获得的内容
您的登录尝试失败,请重试。原因: PreparedStatementCallback; SQL [SELECT user_name,user_password, enabled,email_address,id,user_first_name,user_last_name FROM user WHERE user_name =?];列索引超出范围,8> 7.;嵌套 异常是java.sql.SQLException:列索引超出范围,8> 7。
用于身份验证的applicationContext-security.xml文件中的bean
<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>
这是customJdbcDaoImpl.java文件
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;
}
}
}
这是userDetailsImplementation.java文件
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; }
}
答案 0 :(得分:0)
您运行的applicationContext-security.xml文件是否可能不是您发布的文件?这可能与您的构建有关,而不是出于某种原因将文件复制到运行时位置。
如何部署正在运行的应用?例如WAR,WAR爆炸,独立jar等。尝试将运行时位置中的文件与源位置进行比较。