Search in sources :

Example 1 with StrutsRequestWrapper

use of org.apache.struts2.dispatcher.StrutsRequestWrapper in project tis by qlangtech.

the class UserUtils method getUser.

public static final IUser getUser(final HttpServletRequest r, RunContext runContext) {
    TUser result = null;
    if (true || ManageUtils.isDaily()) {
        result = getMockUser(r, runContext);
        // return NOT_LOGIN_USER;
        return result;
    }
    final TISHttpServletRequestWrapper request = (TISHttpServletRequestWrapper) (((StrutsRequestWrapper) r).getRequest());
    HttpSession session = request.getSession();
    try {
        if ((result = getUserFromCache(request)) == null) {
            Cookie userCookie = request.getCookie(UserUtils.USER_TOKEN);
            if (userCookie != null && StringUtils.isNotEmpty(userCookie.getValue())) {
                UsrDptRelationCriteria query = new UsrDptRelationCriteria();
                query.createCriteria().andUserNameEqualTo(LoginAction.getDcodeUserName(userCookie.getValue()));
                for (UsrDptRelation usr : runContext.getUsrDptRelationDAO().selectByExample(query)) {
                    result = new TUser(usr, runContext);
                    session.setAttribute(USER_TOKEN_SESSION, result);
                    return result;
                }
            } else {
                return NOT_LOGIN_USER;
            }
        // SimpleSSOUser user = SimpleUserUtil.findUser(request);
        // result = new TUser(user.getEmpId(),
        // StringUtils.defaultIfEmpty(
        // user.getNickNameCn(), user.getLastName()), runContext);
        // result.setDepartment(user.getDepDesc());
        // result = new TUser("18097", "baisui", runContext);
        // result.setDepartment("manage");
        // 
        // // 阿里巴巴全局departmentId
        // result.setDepartmentid(123);
        // result.setWangwang("百岁");
        // result.setEmail("bvaisui@taobao.com");
        }
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Cookie(javax.servlet.http.Cookie) UsrDptRelationCriteria(com.qlangtech.tis.manage.biz.dal.pojo.UsrDptRelationCriteria) HttpSession(javax.servlet.http.HttpSession) StrutsRequestWrapper(org.apache.struts2.dispatcher.StrutsRequestWrapper) UsrDptRelation(com.qlangtech.tis.manage.biz.dal.pojo.UsrDptRelation)

Example 2 with StrutsRequestWrapper

use of org.apache.struts2.dispatcher.StrutsRequestWrapper in project tis by qlangtech.

the class LoginAction method doLogout.

/**
 * 退出登录
 *
 * @param
 * @param context
 * @throws Exception
 */
public void doLogout(Context context) throws Exception {
    // this.getRequest().getSession(true);
    ServletActionContext.getRequest().getSession().removeAttribute(UserUtils.USER_TOKEN_SESSION);
    final String host = this.getRequest().getHeader("Host");
    ChangeDomainAction.addCookie(getResponse(), UserUtils.USER_TOKEN, "", StringUtils.substringBefore(host, ":"), 0);
    final TISHttpServletRequestWrapper request = (TISHttpServletRequestWrapper) (((StrutsRequestWrapper) this.getRequest()).getRequest());
    request.removeCookie(UserUtils.USER_TOKEN);
    getRundataInstance().redirectTo("/runtime/login.htm");
}
Also used : StrutsRequestWrapper(org.apache.struts2.dispatcher.StrutsRequestWrapper) TISHttpServletRequestWrapper(com.qlangtech.tis.manage.common.TISHttpServletRequestWrapper)

Example 3 with StrutsRequestWrapper

use of org.apache.struts2.dispatcher.StrutsRequestWrapper in project struts by apache.

the class Dispatcher method wrapRequest.

/**
 * <p>
 * Wrap and return the given request or return the original request object.
 * </p>
 *
 * <p>
 * This method transparently handles multipart data as a wrapped class around the given request.
 * Override this method to handle multipart requests in a special way or to handle other types of requests.
 * Note, {@link org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper} is
 * flexible - look first to that object before overriding this method to handle multipart data.
 * </p>
 *
 * @param request the HttpServletRequest object.
 * @return a wrapped request or original request.
 * @throws java.io.IOException on any error.
 * @see org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper
 * @since 2.3.17
 */
public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOException {
    // don't wrap more than once
    if (request instanceof StrutsRequestWrapper) {
        return request;
    }
    if (isMultipartSupportEnabled(request) && isMultipartRequest(request)) {
        MultiPartRequest multiPartRequest = getMultiPartRequest();
        LocaleProviderFactory localeProviderFactory = getContainer().getInstance(LocaleProviderFactory.class);
        request = new MultiPartRequestWrapper(multiPartRequest, request, getSaveDir(), localeProviderFactory.createLocaleProvider(), disableRequestAttributeValueStackLookup);
    } else {
        request = new StrutsRequestWrapper(request, disableRequestAttributeValueStackLookup);
    }
    return request;
}
Also used : MultiPartRequest(org.apache.struts2.dispatcher.multipart.MultiPartRequest) MultiPartRequestWrapper(org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper) LocaleProviderFactory(com.opensymphony.xwork2.LocaleProviderFactory)

Aggregations

StrutsRequestWrapper (org.apache.struts2.dispatcher.StrutsRequestWrapper)2 LocaleProviderFactory (com.opensymphony.xwork2.LocaleProviderFactory)1 UsrDptRelation (com.qlangtech.tis.manage.biz.dal.pojo.UsrDptRelation)1 UsrDptRelationCriteria (com.qlangtech.tis.manage.biz.dal.pojo.UsrDptRelationCriteria)1 TISHttpServletRequestWrapper (com.qlangtech.tis.manage.common.TISHttpServletRequestWrapper)1 Cookie (javax.servlet.http.Cookie)1 HttpSession (javax.servlet.http.HttpSession)1 MultiPartRequest (org.apache.struts2.dispatcher.multipart.MultiPartRequest)1 MultiPartRequestWrapper (org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper)1