[英]Spring Security + Angularjs redirect after login
嘗試使用本教程中的思想: https : //spring.io/guides/tutorials/spring-security-and-angular-js/
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin().and()
.logout().and().authorizeRequests()
.antMatchers("/index.html", "/main.html", "admin.html",
"/login.html", "/")
.permitAll().anyRequest()
.authenticated().and().csrf().disable();
}
我也使用angularjs ngRoute:
var myApp = angular.module('myApp',['ngRoute']);
myApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'main.html',
controller: 'MainController'
})
.when('/admin', {
templateUrl: 'admin.html',
controller: 'AdminController'
})
.when('/login', {
templateUrl: 'login.html',
controller: 'LoginController'
})
.otherwise({
redirectTo: '/'
});
}]);
等等。
但是,當我嘗試打開管理頁面(例如/#/ admin)時,它會打開登錄表單(從框中),然后我希望它可以將我重定向回/#/ admin, 但會將我重定向到/ admin。 html,這超出了角度控制范圍。
如何解決呢?
為了解決/錯誤重定向,您可以創建一個像這樣的控制器
@Controller
public class ErrorController {
@RequestMapping(value="/error")
public String error() {
return "forward:/index.html";
}
}
從春季啟動的角度來看,它應該始終落在“將控件賦予角度”的index.html中
我假設您的資源文件夾結構如下resources / static / index.html
以便在訪問root時呈現該索引。
我的目錄結構與教程中的目錄結構不同,但是應該可以使用
剛了解了您的問題是:因此,在您的角度配置中添加以下內容:
$locationProvider.html5Mode(true).hashPrefix('#');
並在index.htm中包含基本標記
<base href="<!-- @echo BASE_URL -->" target="_blank">
這將擺脫“#”字符,一切都應該工作
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.