From 9c2eb0f87535c165568ed73c33bc6cb0aa93c21e Mon Sep 17 00:00:00 2001 From: wolfhuangxuekun Date: Mon, 30 Jul 2018 23:22:50 +0800 Subject: [PATCH 1/4] fix some bugs --- .../system/controller/LoginController.java | 23 +++++++++++++++---- .../www/system/controller/MainController.java | 12 ++++++++++ src/main/resources/db.properties | 4 ++-- src/main/resources/log4j.properties | 4 ++-- src/main/resources/mybatis-config.xml | 4 ++++ target/classes/db.properties | 4 ++-- target/giit/WEB-INF/classes/db.properties | 4 ++-- 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/giit/www/system/controller/LoginController.java b/src/main/java/com/giit/www/system/controller/LoginController.java index ecbda9f..d851c42 100644 --- a/src/main/java/com/giit/www/system/controller/LoginController.java +++ b/src/main/java/com/giit/www/system/controller/LoginController.java @@ -7,9 +7,11 @@ import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.IncorrectCredentialsException; import org.apache.shiro.authc.UnknownAccountException; +import org.apache.shiro.authc.UsernamePasswordToken; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import javax.annotation.Resource; import javax.security.auth.Subject; @@ -26,8 +28,10 @@ public class LoginController { UserBiz userBiz; @RequestMapping("login") - public String login(HttpServletRequest req, Model model, HttpSession session) { - String exceptionClassName = (String) req.getAttribute("shiroLoginFailure"); + public String login(@RequestParam("username") String username, @RequestParam("password") String password) { + + /*String exceptionClassName = (String) req.getAttribute("shiroLoginFailure"); + System.out.println(exceptionClassName); String error = null; if (UnknownAccountException.class.getName().equals(exceptionClassName)) { error = "用户名/密码错误"; @@ -35,15 +39,26 @@ public String login(HttpServletRequest req, Model model, HttpSession session) { error = "用户名/密码错误"; } else if (exceptionClassName != null) { error = "其他错误:" + exceptionClassName; - } + }*/ //TODO 这里以后可以把角色更换成资源控制后动态生成页面,(-->这里有疑问-->是不是可以使用自定义角色?shiro张开涛的16章有个自定义标签扫描出的角色) org.apache.shiro.subject.Subject subject = SecurityUtils.getSubject(); + UsernamePasswordToken token = new UsernamePasswordToken(username, password); + try { + subject.login(token); + } catch(IncorrectCredentialsException e) { + e.printStackTrace(); + return "redirect:login.jsp"; + } catch(Exception e) { + e.printStackTrace(); + return "redirect:login.jsp"; + } + boolean isAuthenticated = subject.isAuthenticated(); if (isAuthenticated) { String principal = (String) subject.getPrincipal(); - session.setAttribute("username", principal); + //session.setAttribute("username", principal); switch (principal) { case "admin": diff --git a/src/main/java/com/giit/www/system/controller/MainController.java b/src/main/java/com/giit/www/system/controller/MainController.java index b563e39..a5975c3 100644 --- a/src/main/java/com/giit/www/system/controller/MainController.java +++ b/src/main/java/com/giit/www/system/controller/MainController.java @@ -1,5 +1,7 @@ package com.giit.www.system.controller; +import org.apache.shiro.crypto.hash.SimpleHash; +import org.apache.shiro.util.ByteSource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -26,4 +28,14 @@ public String studentMainView() { public String teacherMainView() { return "/teacher/main"; } + + public static void main(String[] args) { + String hashAlgorithmName = "MD5"; + Object credential = "123456"; + Object salt = ByteSource.Util.bytes("user"); + + + Object result = new SimpleHash(hashAlgorithmName,credential,salt,1); + System.out.println(result); + } } diff --git a/src/main/resources/db.properties b/src/main/resources/db.properties index 7732dfa..4432e1b 100644 --- a/src/main/resources/db.properties +++ b/src/main/resources/db.properties @@ -1,4 +1,4 @@ jdbc.driver=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://localhost:3306/giit +jdbc.url=jdbc:mysql://localhost:3306/giit?useUnicode=true&characterEncoding=utf8 jdbc.username=root -jdbc.password=0313 +jdbc.password= diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index 3d6d84c..6767e3a 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -1,9 +1,9 @@ # Global logging configuration #在开发环境下日志级别要设置成DEBUG 生产环境设置成info或error -log4j.rootLogger=DEBUG, stdout +log4j.rootLogger=INFO, stdout #Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n \ No newline at end of file +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{ 1 }:%L - %m%n \ No newline at end of file diff --git a/src/main/resources/mybatis-config.xml b/src/main/resources/mybatis-config.xml index 4009578..3f2e33a 100644 --- a/src/main/resources/mybatis-config.xml +++ b/src/main/resources/mybatis-config.xml @@ -6,4 +6,8 @@ + + + + \ No newline at end of file diff --git a/target/classes/db.properties b/target/classes/db.properties index 7732dfa..4432e1b 100644 --- a/target/classes/db.properties +++ b/target/classes/db.properties @@ -1,4 +1,4 @@ jdbc.driver=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://localhost:3306/giit +jdbc.url=jdbc:mysql://localhost:3306/giit?useUnicode=true&characterEncoding=utf8 jdbc.username=root -jdbc.password=0313 +jdbc.password= diff --git a/target/giit/WEB-INF/classes/db.properties b/target/giit/WEB-INF/classes/db.properties index 7732dfa..4432e1b 100644 --- a/target/giit/WEB-INF/classes/db.properties +++ b/target/giit/WEB-INF/classes/db.properties @@ -1,4 +1,4 @@ jdbc.driver=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://localhost:3306/giit +jdbc.url=jdbc:mysql://localhost:3306/giit?useUnicode=true&characterEncoding=utf8 jdbc.username=root -jdbc.password=0313 +jdbc.password= From b6076490e4c458b56783551eb6f361bace68392b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Oct 2019 00:58:58 +0000 Subject: [PATCH 2/4] Bump commons-fileupload from 1.3.1 to 1.3.3 Bumps commons-fileupload from 1.3.1 to 1.3.3. Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c525808..a57bb11 100644 --- a/pom.xml +++ b/pom.xml @@ -196,7 +196,7 @@ commons-fileupload commons-fileupload - 1.3.1 + 1.3.3 From 3519cc5cb3604dd090b7658885a8995767dc8d7b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Feb 2020 22:46:00 +0000 Subject: [PATCH 3/4] Bump shiro-core from 1.2.4 to 1.4.2 Bumps [shiro-core](https://github.com/apache/shiro) from 1.2.4 to 1.4.2. - [Release notes](https://github.com/apache/shiro/releases) - [Changelog](https://github.com/apache/shiro/blob/master/RELEASE-NOTES) - [Commits](https://github.com/apache/shiro/compare/shiro-root-1.2.4...shiro-root-1.4.2) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c525808..aa8e214 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ org.apache.shiro shiro-core - 1.2.4 + 1.4.2 org.apache.shiro From 5ca22aaff1970ea18a164f8f409b6782c3bf60d5 Mon Sep 17 00:00:00 2001 From: c0de8ug <40494925+c0de8ug@users.noreply.github.com> Date: Wed, 27 Oct 2021 14:36:59 -0700 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a6caaf..0302fde 100644 --- a/README.md +++ b/README.md @@ -76,5 +76,5 @@ Json: Gson ![image](https://pic3.zhimg.com/v2-3ff2f0da17e8609f85da3b61671cf0de_b.png) # 数据库表结构: -![image](http://7xi78h.com1.z0.glb.clouddn.com/db.png) +![image](https://user-images.githubusercontent.com/40494925/139150830-03dbbff5-0f56-4e74-be79-7b996b990c45.png)