Skip to content

Commit

Permalink
对认证做出小小修改
Browse files Browse the repository at this point in the history
  • Loading branch information
xwj-vic committed Mar 8, 2017
1 parent 46b1ade commit 6b39120
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/main/java/shiro/shirorealm/CustomRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authent
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
return null;
}


}
6 changes: 4 additions & 2 deletions src/main/java/web/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import service.ShiroUserService;
import util.MD5Util;

import javax.servlet.http.HttpServletRequest;
import java.rmi.activation.UnknownObjectException;

/**
* Created by xuweijie on 2017/3/3.
*/
@Controller
public class LoginController {

@RequestMapping(value = "/login",method = RequestMethod.GET)
@RequestMapping(value = "/login",method = RequestMethod.POST)
public String login(HttpServletRequest request, Model model){
CustomException customException=null;
String username=request.getParameter("username");
Expand All @@ -36,7 +39,6 @@ public String login(HttpServletRequest request, Model model){
}
if( subject.isAuthenticated()){
subject.logout();
System.out.println("认证成功");
model.addAttribute("username",username);
return "/loginsuccess";
}else {
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/spring/spring-shiro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<!-- (密码)凭证匹配器 -->
<bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
<property name="hashAlgorithmName" value="md5" />
<property name="hashIterations" value="1" />
</bean>

</beans>
3 changes: 1 addition & 2 deletions src/main/webapp/WEB-INF/jsp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<html>
<head>
<title>Shiro 测试项目首页</title>

</head>
<body>
<h1>这是首页</h1>
<jsp:include page="login.jsp"/>
</body>
</html>
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/jsp/login.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div align="center">
<h1>登录</h1>
<br><br><br>
<form action="/login" method="get">
<form action="/login" method="POST">
&nbsp;&nbsp;&nbsp;&nbsp;名:<input type="text" name="username"><br><br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" name="password"><br><br>
<input type="submit" value="登录">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="取消">
Expand Down
5 changes: 4 additions & 1 deletion src/main/webapp/WEB-INF/jsp/loginsuccess.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<title>成功登录</title>
</head>
<body>
<h1>用户名:${username}</h1>
<div align="center">
<h1>用户名:${username}</h1>
</div>

</body>
</html>
7 changes: 4 additions & 3 deletions src/main/webapp/WEB-INF/jsp/refuse.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<title>认证失败</title>
</head>
<body>
<h1>认证失败的异常信息:</h1><br>
${exception}

<div align="center">
<h1>认证失败的异常信息:</h1><br>
${exception}
</div>
</body>
</html>
14 changes: 14 additions & 0 deletions src/test/java/testmd5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.junit.Test;
import util.MD5Util;

/**
* Created by xuweijie on 2017/3/7.
*/
public class testmd5 {

@Test
public void md5(){
String pwd=MD5Util.md5("654321","xuweijie");
System.out.print("pwd:"+pwd);
}
}

0 comments on commit 6b39120

Please sign in to comment.