Search in sources :

Example 1 with BaseResponse

use of com.junliang.spring.pojo.vo.BaseResponse in project spring-boot by Linda-Tan.

the class AccessFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    if (isIgnorePath(request.getRequestURI()))
        return null;
    String token = request.getHeader(jwtTokenHeader);
    if (StringUtils.isBlank(token)) {
        log.warn("access token is empty");
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        return null;
    }
    try {
        // 校验token合法性
        Jws<Claims> claimsJws = Jwts.parser().setSigningKey(RSAHelper.getBase64PublicKey(pubKeyPath)).parseClaimsJws(token);
        Claims body = claimsJws.getBody();
        UserInfo userInfo = new UserInfo();
        userInfo.setId(body.getId());
        userInfo.setName(body.getSubject());
        log.info("parser token : {}", body);
    } catch (Exception e) {
        ctx.setResponseBody(JSON.toJSONString(new BaseResponse(ResponseCode.EX_OTHER_CODE, "Token error or Token is Expired!")));
        log.error(e.getMessage());
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BaseResponse(com.junliang.spring.pojo.vo.BaseResponse) Claims(io.jsonwebtoken.Claims) UserInfo(com.junliang.spring.pojo.bean.UserInfo) RequestContext(com.netflix.zuul.context.RequestContext)

Example 2 with BaseResponse

use of com.junliang.spring.pojo.vo.BaseResponse in project spring-boot by Linda-Tan.

the class TestController method sendEmailTemplate.

@GetMapping("sendEmailTemplate")
public BaseResponse sendEmailTemplate() {
    try {
        Email email = new Email();
        Map<String, String> map = new HashMap<>(2);
        map.put("text", "welcome");
        email.setKvMap(map);
        email.setTemplate("welcome");
        email.setEmail(new String[] { "tyf201314@qq.com" });
        email.setSubject("默认主题");
        email.setCc(new String[] { "li926893@gmail.com" });
        emailService.sendBytemplate(email);
        return new ObjectRestResponse("hellowzho直接后果orld");
    } catch (Exception ex) {
        log.error("发送失败", ex);
        return new BaseResponse(4000, "发送失败");
    }
}
Also used : BaseResponse(com.junliang.spring.pojo.vo.BaseResponse) Email(com.junliang.spring.pojo.bean.Email) HashMap(java.util.HashMap) ObjectRestResponse(com.junliang.spring.pojo.vo.ObjectRestResponse) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

BaseResponse (com.junliang.spring.pojo.vo.BaseResponse)2 Email (com.junliang.spring.pojo.bean.Email)1 UserInfo (com.junliang.spring.pojo.bean.UserInfo)1 ObjectRestResponse (com.junliang.spring.pojo.vo.ObjectRestResponse)1 RequestContext (com.netflix.zuul.context.RequestContext)1 Claims (io.jsonwebtoken.Claims)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1