diff --git a/src/main/java/org/casbin/Application.java b/src/main/java/org/casbin/Application.java index c8137f6..9abdd52 100644 --- a/src/main/java/org/casbin/Application.java +++ b/src/main/java/org/casbin/Application.java @@ -14,14 +14,37 @@ package org.casbin; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.Environment; +import org.springframework.util.StringUtils; + +import java.lang.management.ManagementFactory; +import java.net.InetAddress; +import java.net.UnknownHostException; @SpringBootApplication +@Slf4j public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); + public static void main(String[] args) throws UnknownHostException { + ConfigurableApplicationContext application = SpringApplication.run(Application.class, args); + Environment env = application.getEnvironment(); + String ip = InetAddress.getLocalHost().getHostAddress(); + String port = env.getProperty("server.port"); + String path = env.getProperty("server.servlet.context-path"); + if (StringUtils.isEmpty(path)) { + path = ""; + } + log.info("\n----------------------------------------------------------\n\t" + + "Application is running! Access URLs:\n\t" + + "Local access website: \t\thttp://localhost:" + port + path + "\n\t" + + "External access website: \thttp://" + ip + ":" + port + path + "\n\t" + + "----------------------------------------------------------"); + String jvmName = ManagementFactory.getRuntimeMXBean().getName(); + log.info("Current project progress number:" + jvmName.split("@")[0]); } } + diff --git a/src/main/java/org/casbin/controller/LoginController.java b/src/main/java/org/casbin/controller/LoginController.java index ebad95a..4fb311e 100644 --- a/src/main/java/org/casbin/controller/LoginController.java +++ b/src/main/java/org/casbin/controller/LoginController.java @@ -16,43 +16,29 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.casbin.service.AuthenticationService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; @Controller public class LoginController { - @Autowired - private AuthenticationService authenticationService; - @RequestMapping(value = {"/"}, method = RequestMethod.GET) public String index() { return "main/login"; } @RequestMapping(value = "/login", method = RequestMethod.POST) - public String login(@RequestParam String username, @RequestParam String password, HttpSession session, HttpServletRequest request, RedirectAttributes redirectAttributes) { - boolean isAuthenticated = authenticationService.authenticate(username, password); - - if (isAuthenticated) { - session.invalidate(); - session = request.getSession(true); - session.setAttribute("username", username); - return "redirect:/menu"; - } else { - redirectAttributes.addAttribute("error", true); - return "redirect:/login"; - } + public String login(@RequestParam String username, HttpSession session, HttpServletRequest request) { + session.invalidate(); + session = request.getSession(true); + session.setAttribute("username", username); + return "redirect:/menu"; } @RequestMapping(value = {"/denied"}, method = RequestMethod.GET) public String denied() { return "main/denied"; } -} - +} \ No newline at end of file diff --git a/src/main/java/org/casbin/service/AuthenticationService.java b/src/main/java/org/casbin/service/AuthenticationService.java deleted file mode 100644 index aa16180..0000000 --- a/src/main/java/org/casbin/service/AuthenticationService.java +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2024 The casbin Authors. All Rights Reserved. -// -// Licensed 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. - -package org.casbin.service; - -import org.springframework.stereotype.Service; - -@Service -public class AuthenticationService { - public boolean authenticate(String username, String password) { - // Three valid username and password combinations are set here. - return ("root".equals(username) && "root".equals(password)) || - ("admin".equals(username) && "admin".equals(password)) || - ("user".equals(username) && "user".equals(password)); - } -} - - diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 84f0921..75fa716 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -37,6 +37,4 @@ spring: max-file-size: 2048MB server: - port: 8080 - servlet: - context-path: /casbin \ No newline at end of file + port: 8080 \ No newline at end of file diff --git a/src/main/resources/templates/AdminMenu/AdminMenu.html b/src/main/resources/templates/AdminMenu/AdminMenu.html index c986868..2abe406 100644 --- a/src/main/resources/templates/AdminMenu/AdminMenu.html +++ b/src/main/resources/templates/AdminMenu/AdminMenu.html @@ -3,6 +3,18 @@ AdminMenu +
diff --git a/src/main/resources/templates/AdminMenu/AdminSubMenu_allow.html b/src/main/resources/templates/AdminMenu/AdminSubMenu_allow.html index cd91397..8cd0e85 100644 --- a/src/main/resources/templates/AdminMenu/AdminSubMenu_allow.html +++ b/src/main/resources/templates/AdminMenu/AdminSubMenu_allow.html @@ -3,6 +3,18 @@ AdminSubMenu_allow +
diff --git a/src/main/resources/templates/AdminMenu/AdminSubMenu_deny.html b/src/main/resources/templates/AdminMenu/AdminSubMenu_deny.html index fb72b5a..96fec8a 100644 --- a/src/main/resources/templates/AdminMenu/AdminSubMenu_deny.html +++ b/src/main/resources/templates/AdminMenu/AdminSubMenu_deny.html @@ -3,6 +3,18 @@ AdminSubMenu_deny +
diff --git a/src/main/resources/templates/OtherMenu/OtherMenu.html b/src/main/resources/templates/OtherMenu/OtherMenu.html index cddee05..2e1e270 100644 --- a/src/main/resources/templates/OtherMenu/OtherMenu.html +++ b/src/main/resources/templates/OtherMenu/OtherMenu.html @@ -2,12 +2,23 @@ - SystemMenu + OtherMenu +
OtherMenu
- - \ No newline at end of file + diff --git a/src/main/resources/templates/UserMenu/UserMenu.html b/src/main/resources/templates/UserMenu/UserMenu.html index f06186b..4d51739 100644 --- a/src/main/resources/templates/UserMenu/UserMenu.html +++ b/src/main/resources/templates/UserMenu/UserMenu.html @@ -3,6 +3,18 @@ UserMenu +
diff --git a/src/main/resources/templates/UserMenu/UserSubMenu_allow.html b/src/main/resources/templates/UserMenu/UserSubMenu_allow.html index 0f4881e..8673458 100644 --- a/src/main/resources/templates/UserMenu/UserSubMenu_allow.html +++ b/src/main/resources/templates/UserMenu/UserSubMenu_allow.html @@ -3,6 +3,18 @@ UserSubMenu_allow +
diff --git a/src/main/resources/templates/UserMenu/UserSubMenu_deny.html b/src/main/resources/templates/UserMenu/UserSubMenu_deny.html index 4338eea..75e2307 100644 --- a/src/main/resources/templates/UserMenu/UserSubMenu_deny.html +++ b/src/main/resources/templates/UserMenu/UserSubMenu_deny.html @@ -3,6 +3,18 @@ UserSubMenu_deny +
diff --git a/src/main/resources/templates/UserMenu/UserSubSubMenu.html b/src/main/resources/templates/UserMenu/UserSubSubMenu.html index 1b580eb..a357474 100644 --- a/src/main/resources/templates/UserMenu/UserSubSubMenu.html +++ b/src/main/resources/templates/UserMenu/UserSubSubMenu.html @@ -3,6 +3,18 @@ UserSubSubMenu +
diff --git a/src/main/resources/templates/main/login.html b/src/main/resources/templates/main/login.html index 2fc9010..7dd71cd 100644 --- a/src/main/resources/templates/main/login.html +++ b/src/main/resources/templates/main/login.html @@ -2,26 +2,22 @@ - login + Login + - -
-
login
-
-
-
- - -
-
- - -
-
- -
+ +
+
+
+

Login as:

+
+ + + + +
- \ No newline at end of file + diff --git a/src/main/resources/templates/main/menu.html b/src/main/resources/templates/main/menu.html index 960f8b6..caa1bec 100644 --- a/src/main/resources/templates/main/menu.html +++ b/src/main/resources/templates/main/menu.html @@ -1,108 +1,94 @@ - + - Jcasbin-Menu-Permission - - - + Menu with Submenus + - -
-
- -
-
-
-

- -

-
- -
-
-
+
+ -
- - - - - +