| | |
| | | import com.terra.common.entity.lf.UserPo; |
| | | import com.terra.common.helper.StringHelper; |
| | | import com.terra.common.helper.WebHelper; |
| | | import com.terra.common.service.CommonService; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.HandlerInterceptor; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.List; |
| | |
| | | */ |
| | | @Configuration |
| | | public class AuthInterceptor implements HandlerInterceptor { |
| | | private CommonService commonService; |
| | | |
| | | private static final Log log = LogFactory.getLog(AuthInterceptor.class); |
| | | |
| | | private static final String NO_TOKEN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.TOKEN_ERROR, "找不到令牌")); |
| | |
| | | |
| | | private static final String ILLEGAL_TOKEN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.UNAUTHORIZED, "令牌来源非法")); |
| | | |
| | | //public AuthInterceptor(SysService sysService) { |
| | | // this.sysService = sysService; |
| | | //} |
| | | public AuthInterceptor(CommonService commonService) { |
| | | this.commonService = commonService; |
| | | } |
| | | |
| | | /** |
| | | * Controller执行之前执行,如果返回值是true则代表放行,返回false则拦截 |
| | |
| | | } |
| | | |
| | | // 3.获取用户令牌 |
| | | UserPo ue = new UserPo(); //sysService.tokenService.getUserByToken(token); |
| | | if (ue == null) { |
| | | UserPo ue = commonService.getUserByToken(token); //new UserPo(); //sysService.tokenService.getUserByToken(token); |
| | | if (null == ue) { |
| | | return WebHelper.writeStr2Page(response, NO_LOGIN); |
| | | } |
| | | |
| | |
| | | * 检查权限 |
| | | */ |
| | | private boolean checkPerms(UserPo ue, HttpServletRequest request) { |
| | | List<String> list = null; //sysService.permsService.selectPerms(ue.getUid()); |
| | | if (list == null || list.size() == 0) { |
| | | return false; |
| | | } |
| | | return true; |
| | | |
| | | String url = request.getRequestURI(); |
| | | for (String perm : list) { |
| | | if (url.contains(perm)) { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | // List<String> list = null; //sysService.permsService.selectPerms(ue.getUid()); |
| | | // if (list == null || list.size() == 0) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // String url = request.getRequestURI(); |
| | | // for (String perm : list) { |
| | | // if (url.contains(perm)) { |
| | | // return true; |
| | | // } |
| | | // } |
| | | // |
| | | // return false; |
| | | } |
| | | |
| | | /** |