Angularjs SpringSecurity4和Angular登录身份验证
我对seend good post登录身份验证有问题 这是我的安全配置:Angularjs SpringSecurity4和Angular登录身份验证,angularjs,spring,authentication,Angularjs,Spring,Authentication,我对seend good post登录身份验证有问题 这是我的安全配置: @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/", "/home").access("hasRole('USER')") .antMatchers("/admin/**").access("
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/home").access("hasRole('USER')")
.antMatchers("/admin/**").access("hasRole('ADMIN')")
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login/authentication").successHandler(securityHandler)
.usernameParameter("s_username").passwordParameter("s_password")
.and().csrf()
.and().exceptionHandling().accessDeniedPage("/Access_Denied");
}
弹簧控制器:
@Controller
@RequestMapping("/login")
public class AuthController {
@RequestMapping(value="", method = RequestMethod.GET)
public String getLoginPage(){
return "login/layout";
}
}
(function (angular) {
'use strict';
var App = angular.module('appAuth', ['ngRoute'])
App.controller("LoginController", function ($scope, $http, $window) {
var encode4form = function(data){
var result="";
var first = true;
for(var key in data)
{
if(first){
first=false;
}
else{
result+="&"
}
result+=(key + "=" + data[key]);
}
return result;
};
$scope.Login = function () {
var mycsrf = $("input[name='_csrf']").val();
$http(
{
url: "/login/authentication",
method:"POST",
data: encode4form({
s_username: $scope.login.username,
s_password: $scope.login.password,
_csrf: mycsrf
}),
headers:
{
"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
}
}
);
//$http({
// method: 'POST',
// url: 'http://localhost:8080/login/authentication',
// data: data,
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded'
// }
//$http.post('/login/authentication', loginData), {
// headers: {
// 'X-CSRF-TOKEN': $('input[name="_csrf"]').val(),
// //'Content-Type': "application/x-www-form-urlencoded"
// 'Content-Type': 'application/json'
// }
//});
};
});
})(window.angular);
我的登录页面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Login</title>
<link href="resources/css/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<script src="resources/js/angular.min.js"></script>
<script src="resources/scripts/auth/Auth.js"></script>
<script src="resources/js/angular-route.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body ng-app="appAuth">
<div class="col-md-6 col-md-offset-3" ng-controller="LoginController as login">
<h2>Login</h2>
<form name="form" ng-submit="Login()" role="form">
<div class="form-group">
<label for="username">Username</label>
<input type="text" name="username" id="username" class="form-control" ng-model="login.username" required />
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" class="form-control" ng-model="login.password" required />
</div>
<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid" class="btn btn-primary">Login</button>
</div>
</form>
</div>
</body>
</html>
控制台日志:
2016-02-27 11:11:27信息授权控制器:24-登录2016-02-27 11:11:31警告页面NotFound:1136-在DispatcherServlet中找不到URI为[/Access\u Denied]的HTTP请求的映射(当我单击登录时) 我尝试了很多方法,但没有一种方法不起作用。当我点击登录按钮时,chrome显示错误“POST 404(未找到)”。当我将登录页面更改为login.jsp(不带angular)时,它就可以工作了。为什么我们不在角上工作