主要技术:springmvc、 springboot 、mybatis、mysql 、jQuery、layui、css、jsp shiro权限控制
主要功能截图如下:
用户登录、首页主要功能有:会员信息管理、会员到期续费管理、充值管理、教练课程管理、私教管理、器材管理、小商品售卖管理、信息统计、修改密码等主要功能:
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
// HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
// //指定加密方式为MD5
// credentialsMatcher.setHashAlgorithmName("MD5");
// //加密次数
// credentialsMatcher.setHashIterations(1024);
// credentialsMatcher.setStoredCredentialsHexEncoded(true);
// return credentialsMatcher;
// }
@Bean
public MyRealm getMyRealm(){
MyRealm myRealm = new MyRealm() ;
// myRealm.setCredentialsMatcher(getHashedCredentialsMatcher());
return myRealm ;
}
@Bean
public SimpleCookie rememberMeCookie() {
//System.out.println("ShiroConfiguration.rememberMeCookie()");
//这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
* 防止密码在数据库里明码保存 , 当然在登陆认证的时候 ,
* 这个类也负责对form里输入的密码进行编码
* 处理认证匹配处理器:如果自定义需要实现继承HashedCredentialsMatcher
*/
// @Bean("hashedCredentialsMatcher")
// public HashedCredentialsMatcher getHashedCredentialsMatcher() {
// HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
// //指定加密方式为MD5
// credentialsMatcher.setHashAlgorithmName("MD5");
// //加密次数
// credentialsMatcher.setHashIterations(1024);
// credentialsMatcher.setStoredCredentialsHexEncoded(true);
// return credentialsMatcher;
// }
@Bean
public MyRealm getMyRealm(){
MyRealm myRealm = new MyRealm() ;
// myRealm.setCredentialsMatcher(getHashedCredentialsMatcher());
//
// map.put("/add.jsp","perms[user:*]") ;
map.put("/**","user") ;
shiroFilterFactoryBean.setFilterChainDefinitionMap(map);
shiroFilterFactoryBean.setLoginUrl("/login.jsp");
shiroFilterFactoryBean.setUnauthorizedUrl("/unauth.jsp");
return shiroFilterFactoryBean ;
}
}
用户管理控制层:
@Controller
@RequestMapping("/user")
public class UserController {
@Resource
private IUserService userService;
@ResponseBody
@RequestMapping("/login")
public String toIndex(User user,HttpSession session){
String account=user.getAccount();
user=userService.userLogin(user.getAccount(),user.getPwd());
if(user!=null){
List<Map<String,Object>> list = userService.findUserByAccount(account);
}
/*Adminuser a= adminuserDao.findByAdminNameAndAdminmima(username,password);
if(a!=null){
httpSession.setAttribute("user",a);
return "WEB-INF/jsp/index" ;
}
model.addAttribute("mag","账号或密码错误");
return "login";*/
}
/**
* @Description: 退出登录后清楚session
* xiaoc
* @Date: 2020/5/1
return "true";
}
}
管理员登录代码如下:
/**
* @Description: 管理员登录Controller控制层
* xiaoc
* @Date: 2020/4/4
*/
@Controller
@RequestMapping("/")
public class AdminuserConntroller {
@Autowired
private AdminuserDao adminuserDao;
/**
* @Description: 输入端口号直接跳转登录界面
* xiaoc
* @Date: 2020/4/29
*/
}
@Bean
public DefaultWebSecurityManager getDefaultWebSecurityManager(){
DefaultWebSecurityManager defaultWebSecurityManager = new DefaultWebSecurityManager() ;
defaultWebSecurityManager.setRealm(getMyRealm());
//注册记住我
defaultWebSecurityManager.setRememberMeManager(rememberMeManager());
//注册缓存
defaultWebSecurityManager.setCacheManager(getEhCacheManager());
return defaultWebSecurityManager ;
}
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(){
System.out.println("开启了Shiro注解支持");
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
authorizationAttributeSourceAdvisor.setSecurityManager(getDefaultWebSecurityManager());
return authorizationAttributeSourceAdvisor;
}
@Bean
@ConditionalOnMissingBean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
defaultAAP.setProxyTargetClass(true);
return defaultAAP;
}
@Bean
public String loginForward(){
return "user/index";
}
@RequestMapping("/exit")
public String exit(HttpSession session){
session.invalidate();
return "login";
}
@RequestMapping("/myInfo")
public String myInfo(HttpSession session){
String account=(String) session.getAttribute("account");
List<Map<String,Object>> list = userService.findUserByAccount(account);
session.setAttribute("userInfo", JSON.toJSON(list));
return "user/index";
// //加密次数
// credentialsMatcher.setHashIterations(1024);
// credentialsMatcher.setStoredCredentialsHexEncoded(true);
// return credentialsMatcher;
// }
@Bean
public MyRealm getMyRealm(){
MyRealm myRealm = new MyRealm() ;
// myRealm.setCredentialsMatcher(getHashedCredentialsMatcher());
return myRealm ;
}
@Bean
public SimpleCookie rememberMeCookie() {
//System.out.println("ShiroConfiguration.rememberMeCookie()");
//这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
SimpleCookie simpleCookie = new SimpleCookie("ckbox");
//<!-- 记住我cookie生效时间30天 ,单位秒;-->
simpleCookie.setMaxAge(259200);
return simpleCookie;
}
Adminuser a= adminuserDao.findByAdminNameAndAdminPassword(username,DigestUtils.md5Hex(password));
httpSession.setAttribute("user",a);
return "WEB-INF/jsp/index";
}catch (UnknownAccountException e){
model.addAttribute("msg","用户名或密码错误,请重新输入");
return "login";
}
/*Adminuser a= adminuserDao.findByAdminNameAndAdminmima(username,password);
if(a!=null){
httpSession.setAttribute("user",a);
return "WEB-INF/jsp/index" ;
}
model.addAttribute("mag","账号或密码错误");
return "login";*/
}
/**
* @Description: 退出登录后清楚session
* xiaoc
* @Date: 2020/5/1
*/
@RequestMapping("/logout")
public String logout(){
Subject subject = SecurityUtils.getSubject();
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean() ;
//设置网页安全管理器
shiroFilterFactoryBean.setSecurityManager(getDefaultWebSecurityManager());
Map<String,String> map = new LinkedHashMap<String,String>() ;
//定义可以直接访问的资源
map.put("/login.jsp","anon") ;
map.put("/vcode.jsp","anon");
map.put("/dl/yz","anon") ;
map.put("/static/**","anon") ;
//取消认证
map.put("/logout","logout") ;
//
// map.put("/add.jsp","perms[user:*]") ;
map.put("/**","user") ;
shiroFilterFactoryBean.setFilterChainDefinitionMap(map);
shiroFilterFactoryBean.setLoginUrl("/login.jsp");
shiroFilterFactoryBean.setUnauthorizedUrl("/unauth.jsp");
return shiroFilterFactoryBean ;
}
return "WEB-INF/jsp/updPassword";
}
Adminuser adminuser=(Adminuser) httpSession.getAttribute("user");
if(null != adminuser){
if(!adminuser.getAdminPassword().equals(DigestUtils.md5Hex(oldPassword))){
model.addAttribute("msg","原密码不正确,请重新输入");
return "WEB-INF/jsp/updPassword";
}
adminuserDao.updPassword(adminuser.getAdminId(), DigestUtils.md5Hex(newPassword));
}
Subject subject = SecurityUtils.getSubject();
subject.logout();
return "redirect:/login.jsp";
}
}
密码加密方式:
@Configuration
public class ShiroConfig {
/**
* 密码校验规则HashedCredentialsMatcher