【发布时间】:2017-08-10 18:17:57
【问题描述】:
我正在做基于 spring boot + Angularjs 的应用程序 我根据这篇博文进行的身份验证:https://spring.io/guides/tutorials/spring-security-and-angular-js/ 所以我启用了基本用户/密码或 OAuth2
我想向它添加记住我的功能。我有 AuthService
AuthService.authenticate = function (credentials, callback) {
var headers = credentials ? {
authorization: "Basic "
+ btoa(credentials.username + ":" + credentials.password)
} : {};
$http.get('api/user/', {headers: headers}, {timeout: 5000}).then(
function (response) {
var data = response.data;
if (data.id) {
$rootScope.authenticated = true;
$rootScope.principal = data;
$translate.use($rootScope.principal.language);
$location.search('lang', $rootScope.principal.language);
AvatarService.getUserAvatar($rootScope.principal);
$log.debug("[DEBUG] User logged in " + $rootScope.principal.id);
} else {
$rootScope.authenticated = false;
}
callback && callback();
},
function () {
$rootScope.authenticated = false;
callback && callback();
});
};
在登录控制器中我得到了处理:
$scope.credentials = {};
//LOGIN
$scope.login = function () {
AuthService.authenticate($scope.credentials, function () {
if ($rootScope.authenticated) {
$location.path("/");
AlertService.clearAlerts();
} else {
$location.path("/login");
AlertService.addError('user.login.failed');
}
});
};
在 Spring 安全性上,我像往常一样设置它,(配置的一部分)
....
.and().formLogin()
.loginPage("/#/login")
.and().rememberMe()
.rememberMeServices(rememberMeServices())
.key("remember-me-key")
.and().addFilterBefore(new CsrfHeaderFilter(), CsrfFilter.class)
.csrf()
....
但我的猜测是它期望使用记住我而不是基本身份验证的后调用
如何调整它才能使用记住我? 我可以通过帖子执行调用以使用 j_username j_password 登录并记住我吗?
【问题讨论】:
标签: angularjs spring spring-security