Commit 9ded52d3 authored by 杨伊博's avatar 杨伊博

security is ok

parent 282c99b1
...@@ -34,6 +34,12 @@ ...@@ -34,6 +34,12 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
<!--db--> <!--db-->
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
......
...@@ -17,5 +17,4 @@ public class HomeController { ...@@ -17,5 +17,4 @@ public class HomeController {
model.addAttribute("msg", msg); model.addAttribute("msg", msg);
return "home"; return "home";
} }
} }
...@@ -6,7 +6,7 @@ import java.util.List; ...@@ -6,7 +6,7 @@ import java.util.List;
* Created by yangyibo on 17/1/17. * Created by yangyibo on 17/1/17.
*/ */
public class SysUser { //用户实体实现UserDetails接口,我门的用户实体即位 security 所使用的用户 public class SysUser {
private Integer id; private Integer id;
private String username; private String username;
private String password; private String password;
......
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" <html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"><!-- 1 --> xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head> <head>
<meta content="text/html;charset=UTF-8"/> <meta content="text/html;charset=UTF-8"/>
<title sec:authentication="name"></title> <!-- 2 --> <title sec:authentication="name"></title>
<link rel="stylesheet" th:href="@{css/bootstrap.min.css}" /> <link rel="stylesheet" th:href="@{css/bootstrap.min.css}" />
<style type="text/css"> <style type="text/css">
body { body {
...@@ -24,7 +24,6 @@ body { ...@@ -24,7 +24,6 @@ body {
<div id="navbar" class="collapse navbar-collapse"> <div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a th:href="@{/}"> 首页 </a></li> <li><a th:href="@{/}"> 首页 </a></li>
</ul> </ul>
</div><!--/.nav-collapse --> </div><!--/.nav-collapse -->
</div> </div>
...@@ -38,16 +37,16 @@ body { ...@@ -38,16 +37,16 @@ body {
<p class="bg-primary" th:text="${msg.content}"></p> <p class="bg-primary" th:text="${msg.content}"></p>
<div sec:authorize="hasRole('ROLE_ADMIN')"> <!-- 3 --> <div sec:authorize="hasRole('ROLE_ADMIN')"> <!-- 用户类型为ROLE_ADMIN 显示 -->
<p class="bg-info" th:text="${msg.etraInfo}"></p> <p class="bg-info" th:text="${msg.etraInfo}"></p>
</div> </div>
<div sec:authorize="hasRole('ROLE_USER')"> <!-- 4--> <div sec:authorize="hasRole('ROLE_USER')"> <!-- 用户类型为 ROLE_USER 显示 -->
<p class="bg-info">无更多信息显示</p> <p class="bg-info">无更多信息显示</p>
</div> </div>
<form th:action="@{/logout}" method="post"> <form th:action="@{/logout}" method="post">
<input type="submit" class="btn btn-primary" value="注销"/><!-- 5 --> <input type="submit" class="btn btn-primary" value="注销"/>
</form> </form>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment