Search in sources :

Example 1 with TokenServletRequestWrapper

use of com.tony.billing.filters.wapper.TokenServletRequestWrapper in project BillingDubbo by TonyJiangWJ.

the class XssTokenizeFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
    TokenServletRequestWrapper request;
    if (StringUtils.equals(httpServletRequest.getContentType(), MULTIPART_CONTENT)) {
        request = new TokenServletRequestWrapperWithFile(new CommonsMultipartResolver().resolveMultipart(httpServletRequest));
    } else {
        request = new TokenServletRequestWrapper(httpServletRequest);
    }
    filterChain.doFilter(request, httpServletResponse);
}
Also used : CommonsMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver) TokenServletRequestWrapperWithFile(com.tony.billing.filters.wapper.TokenServletRequestWrapperWithFile) TokenServletRequestWrapper(com.tony.billing.filters.wapper.TokenServletRequestWrapper)

Example 2 with TokenServletRequestWrapper

use of com.tony.billing.filters.wapper.TokenServletRequestWrapper in project BillingDubbo by TonyJiangWJ.

the class AuthorityInterceptor method isUserLogin.

private boolean isUserLogin(HttpServletRequest request) throws Exception {
    Cookie tokenCok = CookieUtil.getCookie(CommonConstants.COOKIE_TOKEN, request);
    if (tokenCok != null) {
        String tokenId = authUtil.getUserTokenId(tokenCok.getValue());
        Optional<Admin> store = redisUtils.get(tokenId, Admin.class);
        if (store.isPresent()) {
            Admin admin = store.get();
            UserIdContainer.setUserId(admin.getId());
            if (request instanceof TokenServletRequestWrapper) {
                ((TokenServletRequestWrapper) request).addParameter(CommonConstants.PARAM_TOKEN_ID, tokenId);
                ((TokenServletRequestWrapper) request).addParameter(CommonConstants.PARAM_USER_ID, String.valueOf(admin.getId()));
            } else if (request instanceof StandardMultipartHttpServletRequest) {
                ((TokenServletRequestWrapper) ((StandardMultipartHttpServletRequest) request).getRequest()).addParameter("tokenId", tokenId);
                ((TokenServletRequestWrapper) ((StandardMultipartHttpServletRequest) request).getRequest()).addParameter("userId", String.valueOf(admin.getId()));
            }
            redisUtils.set(tokenId, admin, 3600 * 24);
            return true;
        } else {
            logger.error("用户未登录:tokenId[{}]", tokenId);
        }
    }
    return false;
}
Also used : Cookie(javax.servlet.http.Cookie) StandardMultipartHttpServletRequest(org.springframework.web.multipart.support.StandardMultipartHttpServletRequest) Admin(com.tony.billing.entity.Admin) TokenServletRequestWrapper(com.tony.billing.filters.wapper.TokenServletRequestWrapper)

Aggregations

TokenServletRequestWrapper (com.tony.billing.filters.wapper.TokenServletRequestWrapper)2 Admin (com.tony.billing.entity.Admin)1 TokenServletRequestWrapperWithFile (com.tony.billing.filters.wapper.TokenServletRequestWrapperWithFile)1 Cookie (javax.servlet.http.Cookie)1 CommonsMultipartResolver (org.springframework.web.multipart.commons.CommonsMultipartResolver)1 StandardMultipartHttpServletRequest (org.springframework.web.multipart.support.StandardMultipartHttpServletRequest)1