无法在spring-boot应用程序中建立安全性配置。登录凭据不起作用

时间:2019-05-20 12:50:02

标签: java spring spring-boot security

我试图逐步探索安全性方面。首先,我尝试使用spring-boot-starter-security和thymeleaf-extras-springsecurity5依赖项。一个默认的登录页面正在打开,但无法成功登录。

我尝试使用默认用户名登录那里:-用户名和密码:-spring-boot生成的密码。我也尝试过使用配置的用户名和密码。

应用程序起始页

@SpringBootApplication
public class BootSecurityApplication {

    public static void main(String[] args) {
        SpringApplication.run(BootSecurityApplication.class, args);
    }
}

控制器文件:-

@Controller
@RequestMapping("/")
public class HomeController {
    @GetMapping("index")
    public String index(){
        return "index";
    }
}

我的html:-

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:insert="fragments.html :: headerfiles"></head>
<body>
<header th:insert="fragments.html :: nav"></header>
<!-- Page content goes here -->
<div class="container">
    <div class="jumbotron">
        <h1 class="display-4">Hello, Spring Boot Security!</h1>
        <p class="lead">This is the home page of our web application. Anyone can access it, even if they have not signed in.</p>
        <hr class="my-4">
        <p>Using this example, you will become more familiar with Spring Security concepts:)</p>
        <p class="lead">
            <a class="btn btn-primary btn-lg" href="https://spring.io/projects/spring-security" role="button">Learn more about Spring Security</a>
        </p>
    </div>
</div>

我的pom.xml

 <modelVersion>4.0.0</modelVersion>

<groupId>rc</groupId>
<artifactId>bootsecurity</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>boot-security</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
            <!-- Security -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity5</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

This Login page is appearing

0 个答案:

没有答案