/*    */ package com.picc.grab.controller;
/*    */ 
/*    */ import com.alibaba.fastjson.JSONObject;
/*    */ import com.picc.grab.common.shiro.NoPwdToken;
/*    */ import com.picc.grab.util.StringEncrypt;
/*    */ import java.util.Date;
/*    */ import org.apache.commons.lang3.StringUtils;
/*    */ import org.apache.shiro.SecurityUtils;
/*    */ import org.apache.shiro.authc.AuthenticationException;
/*    */ import org.apache.shiro.authc.AuthenticationToken;
/*    */ import org.apache.shiro.authc.IncorrectCredentialsException;
/*    */ import org.apache.shiro.authc.UnknownAccountException;
/*    */ import org.apache.shiro.subject.Subject;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ import org.springframework.web.bind.annotation.RequestParam;
/*    */ import org.springframework.web.bind.annotation.RestController;
/*    */ import org.springframework.web.servlet.ModelAndView;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @RestController
/*    */ @RequestMapping
/*    */ public class IndexController
/*    */ {
/* 31 */   private static Logger logger = LoggerFactory.getLogger(IndexController.class);
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   private String getJsonByToken(String token) {
/* 39 */     if (StringUtils.isBlank(token)) return null; 
/* 40 */     token = StringEncrypt.decryptNoPwdLoginToken(token);
/* 41 */     if (StringUtils.isBlank(token)) return null; 
/* 42 */     return token;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   private boolean isToken(long time) {
/* 51 */     long l = (new Date()).getTime();
/* 52 */     long e = l - time;
/*    */     
/* 54 */     if (e > 1800000L) {
/* 55 */       return false;
/*    */     }
/* 57 */     return true;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   @RequestMapping({"/nopwdlogin"})
/*    */   public ModelAndView nopwdlogin(@RequestParam(required = false, value = "token") String token) throws Exception {
/* 69 */     String utoken = getJsonByToken(token);
/* 70 */     if (StringUtils.isNotBlank(token)) {
/* 71 */       JSONObject jo = JSONObject.parseObject(utoken);
/*    */       
/* 73 */       if (isToken(jo.getLong("time").longValue())) {
/* 74 */         String username = jo.getString("username");
/*    */         try {
/* 76 */           Subject subject = SecurityUtils.getSubject();
/*    */ 
/*    */           
/* 79 */           NoPwdToken ssoToken = new NoPwdToken(username);
/* 80 */           subject.login((AuthenticationToken)ssoToken);
/* 81 */           return new ModelAndView("redirect:/loginSuccess");
/*    */         }
/* 83 */         catch (UnknownAccountException e) {
/* 84 */           logger.info("nopwdlogin UnknownAccountException -- > 账号不存在：");
/* 85 */         } catch (IncorrectCredentialsException e) {
/* 86 */           logger.info("nopwdlogin IncorrectCredentialsException -- > 密码不正确：");
/* 87 */         } catch (AuthenticationException e) {
/* 88 */           logger.info("nopwdlogin AuthenticationException -- > 账户验证失败：");
/* 89 */         } catch (Exception e) {
/* 90 */           logger.info("nopwdlogin Exception -- > 未知异常：");
/*    */         } 
/*    */       } 
/*    */     } 
/* 94 */     return new ModelAndView("redirect:/");
/*    */   }
/*    */ }


/* Location:              C:\Users\Administrator\Desktop\ROOT\WEB-INF\classes\!\com\picc\grab\controller\IndexController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */