[SCB-1343]provide web pages to demonstrate login and operations
diff --git a/README.md b/README.md
index 9cfeab5..1fd5f35 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,13 @@
After build, the Authentication Server, Resource Server, Edge Service and Testing Client runnable jar are generated, start and run the four services.
+* Demo web pages
+
+Using admin/changeMyPassword login to the demo pages, and try operations.
+```
+http://localhost:9090/ui/login.html
+```
+
* Run tests
After services are started, try
diff --git a/README_ZH.md b/README_ZH.md
index 55dda1a..19cab05 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -25,6 +25,14 @@
编译完成后,会生成Authentication Server, Resource Server, Edge Service and Testing Client可执行jar包,运行这四个服务。
+* 使用演示界面
+
+进入页面,使用admin/changeMyPassword登录
+```
+http://localhost:9090/ui/login.html
+```
+
+
* 运行测试用例
当四个服务都运行起来后,访问:
diff --git a/api/edge-service/endpoint/src/main/java/org/apache/servicecomb/authentication/edge/CustomVertxRestDispatcher.java b/api/edge-service/endpoint/src/main/java/org/apache/servicecomb/authentication/edge/CustomVertxRestDispatcher.java
index a08873d..46fb804 100644
--- a/api/edge-service/endpoint/src/main/java/org/apache/servicecomb/authentication/edge/CustomVertxRestDispatcher.java
+++ b/api/edge-service/endpoint/src/main/java/org/apache/servicecomb/authentication/edge/CustomVertxRestDispatcher.java
@@ -64,7 +64,7 @@
@Override
public void init(Router router) {
// TODO: regex configuration
- String regex = "(/v1/log|/inspector|/v1/auth)/(.*)";
+ String regex = "(/v1/log|/inspector|/v1/token)(.*)";
router.routeWithRegex(regex).handler(CookieHandler.create());
router.routeWithRegex(regex).handler(createBodyHandler());
router.routeWithRegex(regex).failureHandler(this::failureHandler).handler(this::onRequest);
diff --git a/samples/Client/src/main/java/org/apache/servicecomb/authentication/TestEndpoint.java b/samples/Client/src/main/java/org/apache/servicecomb/authentication/TestEndpoint.java
index 68f727e..d51dd54 100644
--- a/samples/Client/src/main/java/org/apache/servicecomb/authentication/TestEndpoint.java
+++ b/samples/Client/src/main/java/org/apache/servicecomb/authentication/TestEndpoint.java
@@ -23,7 +23,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.client.HttpClientErrorException;
@RestSchema(schemaId = "TestEndpoint")
@RequestMapping(path = "/v1/test")
diff --git a/samples/EdgeService/src/main/resources/microservice.yaml b/samples/EdgeService/src/main/resources/microservice.yaml
index 7531d52..c75034f 100644
--- a/samples/EdgeService/src/main/resources/microservice.yaml
+++ b/samples/EdgeService/src/main/resources/microservice.yaml
@@ -64,8 +64,8 @@
default:
enabled: false # overriden by ApiDispatcher
rest:
- eanbled: false # overriden by CustomVertxRestDispatcher
+ enabled: false # overriden by CustomVertxRestDispatcher
# StaticWebpageDispatcher checking file exists is async, and will mark request status to ended, and VertxRestDispatcher read
# body will print exception.
-#gateway.webroot: /code/servicecomb-samples/porter_lightweight/gateway-service/src/main/resources
+gateway.webroot: /code/servicecomb-fence/samples/EdgeService/src/main/resources
diff --git a/samples/EdgeService/src/main/resources/ui/js/login.js b/samples/EdgeService/src/main/resources/ui/js/login.js
index c7e7c8e..69c3c9b 100644
--- a/samples/EdgeService/src/main/resources/ui/js/login.js
+++ b/samples/EdgeService/src/main/resources/ui/js/login.js
@@ -19,20 +19,21 @@
var username = document.getElementById("username").value;
var password = document.getElementById("paasword").value;
var formData = {};
- formData.userName = username;
+ formData.username = username;
formData.password = password;
+ formData.grant_type = "password";
$.ajax({
type: 'POST',
- url: "/api/user-service/v1/user/login",
+ url: "/v1/token",
data: formData,
success: function (data) {
- console.log(data);
- setCookie("session-id", data.sessiondId, 1);
- window.location = "/ui/upload.html";
+ console.log(JSON.stringify(data));
+ window.localStorage.setItem("token", JSON.stringify(data));
+ window.location = "/ui/operation.html";
},
error: function(data) {
- console.log(data);
+ console.log(JSON.stringify(data));
var error = document.getElementById("error");
error.textContent="Login failed";
error.hidden=false;
@@ -41,12 +42,3 @@
});
}
-function setCookie(name,value,days) {
- var expires = "";
- if (days) {
- var date = new Date();
- date.setTime(date.getTime() + (days*24*60*60*1000));
- expires = "; expires=" + date.toUTCString();
- }
- document.cookie = name + "=" + (value || "") + expires + "; path=/";
-}
\ No newline at end of file
diff --git a/samples/EdgeService/src/main/resources/ui/js/operation.js b/samples/EdgeService/src/main/resources/ui/js/operation.js
new file mode 100644
index 0000000..f911432
--- /dev/null
+++ b/samples/EdgeService/src/main/resources/ui/js/operation.js
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function everyoneSayHello() {
+ $.ajax({
+ type: 'POST',
+ url: "/api/resource-server/v1/auth/handler/everyoneSayHello?name=Hi",
+ headers: {
+ Authorization: "Bearer " + JSON.parse(window.localStorage.getItem("token")).id_token
+ },
+ success: function (data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Successfully";
+ error.hidden=false;
+ },
+ error: function(data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Failed";
+ error.hidden=false;
+ },
+ async: true
+ });
+}
+
+function adminSayHello() {
+ $.ajax({
+ type: 'POST',
+ url: "/api/resource-server/v1/auth/handler/adminSayHello?name=Hi",
+ headers: {
+ Authorization: "Bearer " + JSON.parse(window.localStorage.getItem("token")).id_token
+ },
+ success: function (data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Successfully";
+ error.hidden=false;
+ },
+ error: function(data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Failed";
+ error.hidden=false;
+ },
+ async: true
+ });
+}
+
+function guestOrAdminSayHello() {
+ $.ajax({
+ type: 'POST',
+ url: "/api/resource-server/v1/auth/handler/guestOrAdminSayHello?name=Hi",
+ headers: {
+ Authorization: "Bearer " + JSON.parse(window.localStorage.getItem("token")).id_token
+ },
+ success: function (data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Successfully";
+ error.hidden=false;
+ },
+ error: function(data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Failed";
+ error.hidden=false;
+ },
+ async: true
+ });
+}
+
+function guestSayHello() {
+ $.ajax({
+ type: 'POST',
+ url: "/api/resource-server/v1/auth/handler/guestSayHello?name=Hi",
+ headers: {
+ Authorization: "Bearer " + JSON.parse(window.localStorage.getItem("token")).id_token
+ },
+ success: function (data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Successfully";
+ error.hidden=false;
+ },
+ error: function(data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Failed";
+ error.hidden=false;
+ },
+ async: true
+ });
+}
\ No newline at end of file
diff --git a/samples/EdgeService/src/main/resources/ui/js/upload.js b/samples/EdgeService/src/main/resources/ui/js/upload.js
deleted file mode 100644
index 7d66555..0000000
--- a/samples/EdgeService/src/main/resources/ui/js/upload.js
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-function uploadAction() {
- var formData = new FormData(document.getElementById("upload_form"));
-
- $.ajax({
- type: 'POST',
- url: "/api/file-service/upload",
- data: formData,
- processData:false,
- contentType:false,
- success: function (data) {
- console.log(data);
- var error = document.getElementById("error");
- error.textContent="Upload Successfully";
- error.hidden=false;
- },
- error: function(data) {
- console.log(data);
- var error = document.getElementById("error");
- error.textContent="Upload failed";
- error.hidden=false;
- },
- async: true
- });
-}
-
-function deleteAction() {
- var fileID = document.getElementById("fileID").value;
- $.ajax({
- type: 'DELETE',
- url: "/api/file-service/delete?" + $.param({ id: fileID }),
- data: {},
- success: function (data) {
- console.log(data);
- var error = document.getElementById("error");
- error.textContent="Delete successfully";
- error.hidden=false;
- },
- error: function(data) {
- console.log(data);
- var error = document.getElementById("error");
- error.textContent="Delete failed";
- error.hidden=false;
- },
- async: true
- });
-}
\ No newline at end of file
diff --git a/samples/EdgeService/src/main/resources/ui/upload.html b/samples/EdgeService/src/main/resources/ui/operation.html
similarity index 66%
rename from samples/EdgeService/src/main/resources/ui/upload.html
rename to samples/EdgeService/src/main/resources/ui/operation.html
index bd5eeff..c127612 100644
--- a/samples/EdgeService/src/main/resources/ui/upload.html
+++ b/samples/EdgeService/src/main/resources/ui/operation.html
@@ -22,37 +22,43 @@
<title>PORTER</title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
- <script type="text/javascript" src="js/upload.js"></script>
+ <script type="text/javascript" src="js/operation.js"></script>
</head>
<body>
- <div class="header">
- <h2>Upload</h2>
- </div>
+
<div class="section">
- <form id="upload_form" method="POST">
+ <form id="everyoneSayHello" method="POST">
<p>
- File Name: <input type="file" name="fileName"/>
- </p>
- <p>
- <input type="button" value="Upload" onclick="uploadAction()">
+ <input type="button" value="everyoneSayHello" onclick="everyoneSayHello()">
</p>
</form>
</div>
- <div class="header">
- <h2>Delete file</h2>
- </div>
<div class="section">
- <form id="delete_form" method="DELETE">
+ <form id="adminSayHello" method="POST">
<p>
- File ID: <input id="fileID" type="text"/>
- </p>
- <p>
- <input type="button" value="Delete" onclick="deleteAction()">
+ <input type="button" value="adminSayHello" onclick="adminSayHello()">
</p>
</form>
</div>
+
+ <div class="section">
+ <form id="guestOrAdminSayHello" method="POST">
+ <p>
+ <input type="button" value="guestOrAdminSayHello" onclick="guestOrAdminSayHello()">
+ </p>
+ </form>
+ </div>
+
+ <div class="section">
+ <form id="guestSayHello" method="POST">
+ <p>
+ <input type="button" value="guestSayHello" onclick="guestSayHello()">
+ </p>
+ </form>
+ </div>
+
<div class="footer">
<p id="error" hidden="true" class="error"/>
</div>