Sqlite数据库在我的Java Spring安全应用程序中没有返回正确的值?
我对SQLite和Spring安全性有问题。我在Spring中准备了我的第一个应用程序,我希望使用SQLite的Spring安全性。 这是我的密码: 数据库的设置:Sqlite数据库在我的Java Spring安全应用程序中没有返回正确的值?,java,spring,sqlite,spring-mvc,spring-security,Java,Spring,Sqlite,Spring Mvc,Spring Security,我对SQLite和Spring安全性有问题。我在Spring中准备了我的第一个应用程序,我希望使用SQLite的Spring安全性。 这是我的密码: 数据库的设置: @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/", "/home").permitAll() .a
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.and().formLogin().loginPage("/login")
.usernameParameter("ssoId").passwordParameter("password")
.and().csrf()
.and().exceptionHandling().accessDeniedPage("/Access_Denied");
}
@Autowired
DataSource dataSource;
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery(
"select username,password,enabled from user where username=?");
}
数据库:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.and().formLogin().loginPage("/login")
.usernameParameter("ssoId").passwordParameter("password")
.and().csrf()
.and().exceptionHandling().accessDeniedPage("/Access_Denied");
}
@Autowired
DataSource dataSource;
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery(
"select username,password,enabled from user where username=?");
}
INSERT INTO user(username,password, enabled)
VALUES ('nequeq','123', 'true' );
INSERT INTO user(username,password, enabled)
VALUES ('alex','123', 'true');
INSERT INTO authorities (username, authority)
VALUES ('nequeq', 'ROLE_USER');
INSERT INTO authorities (username, authority)
VALUES ('nequeq', 'ROLE_ADMIN');
INSERT INTO authorities (username, authority)
VALUES ('alex', 'ROLE_USER');
登录页面:
<body>
<div id="mainWrapper">
<div class="login-container">
<div class="login-card">
<div class="login-form">
<c:url var="loginUrl" value="/login" />
<form action="${loginUrl}" method="post" class="form-horizontal">
<c:if test="${param.error != null}">
<div class="alert alert-danger">
<p>Invalid username and password.</p>
</div>
</c:if>
<c:if test="${param.logout != null}">
<div class="alert alert-success">
<p>You have been logged out successfully.</p>
</div>
</c:if>
<div class="input-group input-sm">
<label class="input-group-addon" for="username"><i class="fa fa-user"></i></label>
<input type="text" class="form-control" id="username" name="ssoId" placeholder="Enter Username" required>
</div>
<div class="input-group input-sm">
<label class="input-group-addon" for="password"><i class="fa fa-lock"></i></label>
<input type="password" class="form-control" id="password" name="password" placeholder="Enter Password" required>
</div>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<div class="form-actions">
<input type="submit"
class="btn btn-block btn-primary btn-default" value="Log in">
</div>
</form>
</div>
</div>
</div>
无效的用户名和密码
您已成功注销
这不是完整的代码,只是最重要的部分。应用程序工作,我可以看到网页和任何我想要的。
但我无法登录我的系统,此代码总是返回“无效用户名和密码”
你能帮我解决这个问题吗?好的,我解决了。我错过了Spring中userdetailservice的bean。好的,我解决了它。我错过了Spring中userdetailservice的bean。