集成OAuth2,实现基础功能
diff --git a/leaveschool/client/pom.xml b/leaveschool/client/pom.xml
index 589e5af..56fb3a9 100644
--- a/leaveschool/client/pom.xml
+++ b/leaveschool/client/pom.xml
@@ -69,6 +69,11 @@
<artifactId>spring-security-cas</artifactId>
</dependency> -->
+ <dependency>
+ <groupId>org.springframework.security.oauth.boot</groupId>
+ <artifactId>spring-security-oauth2-autoconfigure</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.springframework.boot</groupId>
diff --git a/leaveschool/client/src/main/java/com/supwisdom/leaveschool/client/ClientApplication.java b/leaveschool/client/src/main/java/com/supwisdom/leaveschool/client/ClientApplication.java
index 4d83c0d..7ddeca9 100644
--- a/leaveschool/client/src/main/java/com/supwisdom/leaveschool/client/ClientApplication.java
+++ b/leaveschool/client/src/main/java/com/supwisdom/leaveschool/client/ClientApplication.java
@@ -9,13 +9,13 @@
import org.springframework.context.annotation.Bean;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
-import com.supwisdom.infras.security.EnableInfrasWebSecurity;
+import com.supwisdom.infras.security.configure.oauth2.EnableInfrasOAuth2;
@SpringBootApplication
@EnableCircuitBreaker
@EnableFeignClients(value = "com.supwisdom.leaveschool.client.service")
@EnableHystrixDashboard
-@EnableInfrasWebSecurity
+@EnableInfrasOAuth2
public class ClientApplication {
public static void main(String[] args) {
diff --git a/leaveschool/client/src/main/java/com/supwisdom/leaveschool/client/controller/web/MainController.java b/leaveschool/client/src/main/java/com/supwisdom/leaveschool/client/controller/web/MainController.java
index 217f944..0999305 100644
--- a/leaveschool/client/src/main/java/com/supwisdom/leaveschool/client/controller/web/MainController.java
+++ b/leaveschool/client/src/main/java/com/supwisdom/leaveschool/client/controller/web/MainController.java
@@ -16,9 +16,7 @@
package com.supwisdom.leaveschool.client.controller.web;
import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class MainController {
@@ -33,21 +31,4 @@
return "web/index";
}
- @RequestMapping(value = "/web/login")
- public String login() {
- return "web/login";
- }
-
- @RequestMapping(value = "/web/login", method = RequestMethod.POST)
- public String postLogin() {
- // TODO Enable form login with Spring Security (trigger error for now)
- return "redirect:/web/login-error";
- }
-
- @RequestMapping("/web/login-error")
- public String loginError(Model model) {
- model.addAttribute("loginError", true);
- return "web/login";
- }
-
}
diff --git a/leaveschool/client/src/main/resources/templates/oauth/login.html b/leaveschool/client/src/main/resources/templates/oauth/login.html
new file mode 100644
index 0000000..81f8f7c
--- /dev/null
+++ b/leaveschool/client/src/main/resources/templates/oauth/login.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
+ <head>
+ <title>OAuth2 Login page</title>
+ <meta charset="utf-8" />
+ <link rel="stylesheet" href="/assets/css/main.css" th:href="@{/assets/css/main.css}" />
+ </head>
+ <body>
+ <h1>OAuth2 Login page</h1>
+ <p>Example user: admin / 111111</p>
+
+ <div th:if="${loginError}" class="error">Wrong user or password</div>
+ <div th:if="${param.error}" class="alert alert-error">Invalid username and password.</div>
+ <div th:if="${param.logout}" class="alert alert-success">You have been logged out.</div>
+
+ <form th:action="@{/oauth/login}" method="post">
+ <label for="username">Username</label>:
+ <input type="text" id="username" name="username" autofocus="autofocus" /> <br />
+ <label for="password">Password</label>:
+ <input type="password" id="password" name="password" /> <br />
+ <input type="submit" value="Log in" />
+ </form>
+ </body>
+</html>