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) diff --git a/pom.xml b/pom.xml index c525808..8c821f4 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 @@ -196,7 +196,7 @@ commons-fileupload commons-fileupload - 1.3.1 + 1.3.3 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=