这应该是一个简单的解决方案,但我似乎无法弄明白。
问题:每当我尝试以用户或管理员身份登录时,用户名和密码始终返回“此用户拒绝访问”(即使用户名和角色确实在数据库中)。
以下是我的文件:
的LoginController:
@Controller
public class LoginController {
@RequestMapping("login")
public ModelAndView getLoginForm(
@RequestParam(required = false) String authfailed, String logout,
String denied) {
String message = "";
if (authfailed != null) {
message = "Invalid username of password, try again !";
} else if (logout != null) {
message = "Logged Out successfully, login again to continue !";
} else if (denied != null) {
message = "Access denied for this user !";
}
return new ModelAndView("login", "message", message);
}
@RequestMapping("user")
public String geUserPage() {
return "user";
}
@RequestMapping("admin")
public String geAdminPage() {
return "admin";
}
@RequestMapping("403page")
public String ge403denied() {
return "redirect:login?denied";
}
}
安全servlet.xml中:
<http auto-config="true" use-expressions="true">
<access-denied-handler error-page="/403page" />
<intercept-url pattern="/anonymous" access="isAnonymous"/>
<intercept-url pattern="/user**" access="hasRole('ROLE_USER')" />
<intercept-url pattern="/admin**" access="hasRole('ROLE_ADMIN')" />
<form-login login-page='/login' username-parameter="username"
password-parameter="password" default-target-url="/user"
authentication-failure-url="/login?authfailed" />
<logout logout-success-url="/login?logout" />
</http>
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="select username,password, enabled from users where username=?"
authorities-by-username-query="select username, role from user_roles where username =? " />
</authentication-provider>
</authentication-manager>
答案 0 :(得分:0)
通过在pom.xml中使用正确的安全性版本来解决这个问题