Shrio-(自动登陆)RememberMe 笔记

1.Spring的XML配置

	
		    
	
	
		 //名字
		  //保存实际
	

2.conteroller层配置

@ResponseBody
	@RequestMapping(value="login33")
	public String Login(HttpServletRequest request) {
		Subject subject = SecurityUtils.getSubject();
		System.out.println(request.getParameter("psw"));
		UsernamePasswordToken token = new UsernamePasswordToken(request.getParameter("username"),request.getParameter("psw"));
		try {
		token.setRememberMe(true);
		subject.login(token);
		}catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		
		if(subject.hasRole("admin")) {
			System.out.println("有该角色");
		}else {
			System.out.println("无该角色");
		}
		if(subject.isPermitted("user:delect")) {
			System.out.println("有该权限");
		}else {
			System.out.println("无该权限");
		}
		
		return "yes";
	}
	

你可能感兴趣的:(Shrio-(自动登陆)RememberMe 笔记)