我正在使用Spring Auth和Spring Rest服务构建我的第一个AngularJS应用程序。我已经构建并测试了CRUD页面。现在我尝试使用Spring Security实现auth。我在实现登录登录方面取得了一些成功,但是我遇到了多个问题,需要你的帮助来解决这个问题。
以下是我现在所拥有的
spring security.xml
<http auto-config="true" entry-point-ref="restUnauthorizedEntryPoint">
<intercept-url pattern="/" access="permitAll" />
<intercept-url pattern="/html/login.html" access="permitAll" />
<intercept-url pattern="/css/**" access="permitAll" />
<intercept-url pattern="/js/**" access="permitAll" />
<intercept-url pattern="/s/**" access="isAuthenticated()" />
<intercept-url pattern="/**" access="isAuthenticated()" />
<form-login login-page="/html/login.html"
username-parameter="ssoId" password-parameter="password" />
<logout logout-url="/logout" delete-cookies="true" invalidate-session="true"
logout-success-url="/html/login.html"/>
<csrf token-repository-ref="tokenRepository" />
</http>
登录页面控制器
app.controller("login", function($scope, $http, $log) {
$scope.doLogin = function() {
$log.debug($scope.login);
$http({
method : "POST",
url : "../login",
data : "ssoId="+$scope.login.ssoId+"&password="+$scope.login.password,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-Login-Ajax-call": 'true'
}
}).then(function(response) {
//location.href="./dashboard.html";
$log.debug("success : " + angular.toJson(response));
}, function(response) {
$log.debug("error : " + angular.toJson(response));
});
}
})
RestUnauthorizedEntryPoint
@Component
public class RestUnauthorizedEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException, ServletException {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
}
}
我有以下问题
HttpServletResponse.SC_UNAUTHORIZED
RestUnauthorizedEntryPoint