前天接到了老大的一个任务,就是超级管理员这个角色才有权限模拟登陆功能,但是我们的密码都是在前端添加的时候用shiro的SHA-256加了密的,所以从数据库看是看不出密码是什么?接到这个功能的时候我也一脸懵逼,一度怀疑是不是当时数据库设计错了,为什么不加上明文密码。直到后来问了老大,说是为了安全起见。
对于shiro,这还是我第一次接触shiro框架,所以一头雾水,在百度、google到处模糊查询(java shiro 模拟登陆),哈哈,然而结果并不是我想要的,所以我就打算写这个博客,为以后的人谋福利。
- 编写shiro-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
">
<!-- 继承自AuthorizingRealm的自定义Realm,即指定Shiro验证用户登录的类为自定义的ManagerRealm.java -->
<bean id="managerRealm" class="com.parking.shiro.ManagerRealm" >
<!-- 自定义匹配类,用于免密登录 -->
<property name="credentialsMatcher">
<bean id="credentialsMatcher" class="com.parking.shiro.RetryLimitHashedCredentialsMatcher">
</bean>
</property>
</bean>