Spring启动,渲染静态页面

时间:2016-02-09 13:01:19

标签: spring-security spring-boot

这是我的安全配置:

protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/login","/newuser").permitAll()
            .antMatchers("/css/**").permitAll()
            .antMatchers("/js/**").permitAll()
            .antMatchers("/**").hasRole("USER").anyRequest().authenticated()
            .and()
        .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
        .httpBasic()
            .and()
        .csrf()
            .csrfTokenRepository(csrfTokenRepository())
            .and()
        .addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class);
}

首先,当我未经过身份验证时,我被重定向到登录页面。 第二,当我尝试创建请求此路径的新用户时“/ newuser”响应状态正常但页面未显示。 这些是我的控制器方法:

@RequestMapping("/login")
public String login() {
    return "loginpage.html";
}

@RequestMapping(value="/newuser")
public String newUser() {
    return "signup.html";
}

这是我的loginpage.html

  <!doctype html>
        <html lang="en">
          <head>
          <meta charset="UTF-8">
          <title>Title</title>

         <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">

    <link href="css/angular-bootstrap.css" rel="stylesheet">
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
    <div class="container" ng-controller="AuthenticationController">
        <form role="form" ng-submit="signin()">
            <div class="form-group">
                <label for="username">Username:</label> <input type="text"
                    class="form-control" id="username" name="username" ng-model="credentials.username"/>
            </div>
            <div class="form-group">
                <label for="password">Password:</label> <input type="password"
                    class="form-control" id="password" name="password" ng-model="credentials.password"/>
            </div>
            <button type="submit" class="btn btn-primary">Submit</button>
        </form>
        <a href ng-click="newuser()">Create new account</a>
    </div>


    <script src="js/angular-bootstrap.js" type="text/javascript"></script>
    <script src="js/init.js"></script>
    <script>
        angular.element(document).ready(function() {
            code.application.initialize(function() {
            angular.bootstrap(document, ['authentication']);
        }, function(error) {
            console.log("Error while initializing Application Content Developer:", error);
            });
        });
    </script>
    <script src="js/AuthenticationController.js"></script>
</body>
</html>

这是我的signup.html:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">

    <link href="css/angular-bootstrap.css" rel="stylesheet">
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
    <p>SIGNUP</p>

    <script src="js/angular-bootstrap.js" type="text/javascript"></script>
    <script src="js/init.js"></script>
    <script>
        angular.element(document).ready(function() {
            code.application.initialize(function() {
            angular.bootstrap(document, ['authentication']);
        }, function(error) {
            console.log("Error while initializing Application Content Developer:", error);
            });
        });
    </script>
    <script src="js/AuthenticationController.js"></script>
</body>
</html>

这是我的项目主要结构:

enter image description here

我无法理解的是:为什么登录页面成功呈现,但注册页面被忽略而根本没有呈现。

1 个答案:

答案 0 :(得分:0)

建议您尝试默认成功网址。例如:

.loginPage("/login").defaultSuccessUrl("/newuser", true)