ssm+activiti+shiro OA项目登录模块

包含流程图+各个模块代码+配置文件+jar包

流程图

EmployeeController 中的方法:

// 登录校验
	@RequestMapping("/login")
	public String main(Model model, HttpServletRequest request) throws Exception {

		// 从request域获得customRealm传来的错误信息
		String exceptionName = (String) request.getAttribute("shiroLoginFailure");

		if (exceptionName != null) {// 处理错误的消息
			// 1.账号错误UnknownAccountException
			if (UnknownAccountException.class.getName().equals(exceptionName)) {
				// 在login设置错误信息
				model.addAttribute("errorMsg", "账号错误");
			}
			// 2.密码错误incorrectCrend
			if (IncorrectCredentialsException.class.getName().equals(exceptionName)) {
				// 在login设置错误信息
				model.addAttribute("errorMsg", "密码错误");
			}
		}
		return "login";
	}

	//主页面
	@RequestMapping("/main")
	public String main(Model model) throws Exception {
		// 从shiro的session中获得employee
		Subject subject = SecurityUtils.getSubject();
		// 取身份信息
		Employee employee = (Employee) subject.getPrincipal();
		//通过model传到页面
		model.addAttribute("employee", employee);
		
		return "index";
	}
	
	//退出登录
	@RequestMapping("/logout")
	public String logout(HttpSession session)throws Exception{
		//session失效
		session.invalidate();
		return "login";
	}

CustomRealm:

@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
				
				//登录功能
				//获取用户输入的账号
				String userName = (String) token.getPrincipal();
				Employee loginEmp = null;
				
				try {
					loginEmp = employeeService.findEmployeeByUserName(userName);
					if(loginEmp==null){
						return null;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				String password_db = loginEmp.getPassword();
				String salt = loginEmp.getSalt();
				
				//构建Employee封装用户对象
				Employee employee = new Employee();
				employee.setId(loginEmp.getId());
				employee.setName(loginEmp.getName());
				
				SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(employee, password_db,ByteSource.Util.bytes(salt), "CustomRealm");
				return info;
			}

EmployeeServiceImpl

@Service
public class EmployeeServiceImpl implements EmployeeService{

	//登录
	@Autowired
	private EmployeeMapper employeeMapper;
	
	@Override
	public Employee findEmployeeByUserName(String userName) {
		EmployeeExample example = new EmployeeExample();
		EmployeeExample.Criteria criteria = example.createCriteria();
		
		criteria.andNameEqualTo(userName);
		List<Employee> list = employeeMapper.selectByExample(example);
		if (list != null && list.size()>0) {
			return list.get(0);
		}
		return null;
	}

此时页面会有bug,bug解决:在自定义表单验证过滤器CustomFormAuthenticationFilter中加一个方法

@Override
	protected boolean onLoginSuccess(AuthenticationToken token,Subject subject,ServletRequest request,ServletResponse response) throws Exception{
		WebUtils.getAndClearSavedRequest(request);
		WebUtils.redirectToSavedRequest(request, response, "/main");
		return false;
	}

配置文件:

链接:https://pan.baidu.com/s/1O6ERzxo9TqenHnCCeK1Yww 
提取码:k7jj 

 

ssm+activiti5+shiro-web jar包:

链接:https://pan.baidu.com/s/10I7F78L3scvTnLCJg25WQg 
提取码:87b2 
 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值