content: package com.us.controller;
  
  import org.apache.shiro.SecurityUtils;
  import org.apache.shiro.authc.AuthenticationException;
  
  import org.apache.shiro.authc.UsernamePasswordToken;
  import org.apache.shiro.subject.Subject;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import org.springframework.web.bind.annotation.*;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * Created by cdyoue on 2016/10/21.
   * 登陆控制器
   */
  @RestController
  public class LoginController {
      private Logger logger = LoggerFactory.getLogger(this.getClass());
  
      @RequestMapping(value = "/login", method = RequestMethod.POST)
      public String login(
              @RequestParam(value = "username", required = true) String userName,
              @RequestParam(value = "password", required = true) String password,
              @RequestParam(value = "rememberMe", required = true, defaultValue = "false") boolean rememberMe
      ) {
          logger.info("==========" + userName + password + rememberMe);
          Subject subject = SecurityUtils.getSubject();
          UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
          token.setRememberMe(rememberMe);
  
          try {
              subject.login(token);
          } catch (AuthenticationException e) {
              e.printStackTrace();
  //            rediect.addFlashAttribute("errorText", "您的账号或密码输入错误!");
              return "{\"Msg\":\"您的账号或密码输入错误\",\"state\":\"failed\"}";
          }
          return "{\"Msg\":\"登陆成功\",\"state\":\"success\"}";
      }
  
      @RequestMapping("/")
      @ResponseBody
      public String index() {
          return "no permission";
      }
  }
  