Example usage for org.apache.shiro.web.util WebUtils issueRedirect

List of usage examples for org.apache.shiro.web.util WebUtils issueRedirect

Introduction

In this page you can find the example usage for org.apache.shiro.web.util WebUtils issueRedirect.

Prototype

public static void issueRedirect(ServletRequest request, ServletResponse response, String url)
        throws IOException 

Source Link

Document

Redirects the current request to a new URL based on the given parameters and default values for unspecified parameters.

Usage

From source file:cn.dreampie.common.plugin.shiro.MyAccessControlFilter.java

License:Apache License

/**
 * Convenience method for subclasses that merely acquires the {@link #getLoginUrl() getLoginUrl} and redirects
 * the request to that url.//from  w  w w.  j  av  a  2s  . c  o  m
 * <p/>
 * <b>N.B.</b>  If you want to issue a redirect with the intention of allowing the user to then return to their
 * originally requested URL, don't use this method directly.  Instead you should call
 * {@link #saveRequestAndRedirectToLogin(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
 * saveRequestAndRedirectToLogin(request,response)}, which will save the current request state so that it can
 * be reconstructed and re-used after a successful login.
 *
 * @param request  the incoming <code>ServletRequest</code>
 * @param response the outgoing <code>ServletResponse</code>
 * @throws java.io.IOException if an error occurs.
 */
protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
    String loginUrl = getRealLoginUrl(request);

    WebUtils.issueRedirect(request, response, loginUrl);
}

From source file:cn.dreampie.common.plugin.shiro.MyLogoutFilter.java

License:Apache License

/**
 * Issues an HTTP redirect to the specified URL after subject logout.  This implementation simply calls
 * {@code WebUtils.}{@link org.apache.shiro.web.util.WebUtils#issueRedirect(javax.servlet.ServletRequest, javax.servlet.ServletResponse, String) issueRedirect(request,response,redirectUrl)}.
 *
 * @param request     the incoming Servlet request
 * @param response    the outgoing Servlet response
 * @param redirectUrl the URL to where the browser will be redirected immediately after Subject logout.
 * @throws Exception if there is any error.
 *//* ww  w.  j av a2  s  .  c o m*/
protected void issueRedirect(ServletRequest request, ServletResponse response, String redirectUrl)
        throws Exception {
    WebUtils.issueRedirect(request, response, redirectUrl);
}

From source file:cn.mario256.blog.filter.AuthenticationFilter.java

License:Open Source License

/**
 * ??//from  w w w .  jav  a 2 s . c o m
 * 
 * @param servletRequest
 *            ServletRequest
 * @param servletResponse
 *            ServletResponse
 * @return ??
 */
@Override
protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse)
        throws Exception {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    if (StringUtils.equalsIgnoreCase(request.getHeader("X-Requested-With"), "XMLHttpRequest")) {
        response.addHeader("loginStatus", "accessDenied");
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return false;
    }
    String loginToken = cn.mario256.blog.util.WebUtils.getCookie(request, Admin.LOGIN_TOKEN_COOKIE_NAME);
    if (!StringUtils.equalsIgnoreCase(loginToken, adminService.getLoginToken())) {
        WebUtils.issueRedirect(request, response, "/");
        return false;
    }
    return super.onAccessDenied(request, response);
}

From source file:com.ace.console.shiro.filter.user.SysUserFilter.java

License:Apache License

protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
    User user = (User) request.getAttribute(Constants.CURRENT_USER);
    String url = null;//  w  w  w .  j a  v  a 2 s  .  c o  m
    if (Boolean.TRUE.equals(user.getDeleted())) {
        url = getUserNotfoundUrl();
    } else if (user.getStatus() == UserStatus.blocked) {
        url = getUserBlockedUrl();
    } else {
        url = getUserUnknownErrorUrl();
    }

    WebUtils.issueRedirect(request, response, url);
}

From source file:com.ace.erp.filter.jcaptcha.JCaptchaValidateFilter.java

License:Apache License

protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
    WebUtils.issueRedirect(request, response, getJcapatchaErrorUrl());
}

From source file:com.axelor.auth.AuthFilter.java

License:Open Source License

@Override
public void doFilterInternal(ServletRequest request, ServletResponse response, FilterChain chain)
        throws ServletException, IOException {

    // tomcat 7.0.67 doesn't redirect with / if root request is sent without slash
    // see RM-4500 for more details
    if (!SecurityUtils.getSubject().isAuthenticated() && isRootWithoutSlash(request)) {
        WebUtils.issueRedirect(request, response, "/");
        return;//  w  ww . j av a  2s  .co m
    }

    if (isLoginRequest(request, response) && SecurityUtils.getSubject().isAuthenticated()) {
        // in case of login submission with ajax
        if (isXHR(request) && isLoginSubmission(request, response)) {
            WebUtils.toHttp(response).setStatus(200);
            return;
        }
        WebUtils.issueRedirect(request, response, "/");
    }
    super.doFilterInternal(request, response, chain);
}

From source file:com.huntering.filter.OnlineSessionFilter.java

License:Apache License

protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
    WebUtils.issueRedirect(request, response, getForceLogoutUrl());
}

From source file:com.huntering.filter.SysUserFilter.java

License:Apache License

protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
    Account user = (Account) ((HttpServletRequest) request).getSession().getAttribute(Constants.CURRENT_USER);
    String url = null;/*from  w  w w  .j av  a 2s .c om*/
    if (Boolean.TRUE.equals(user.getDeleted())) {
        url = getUserNotfoundUrl();
    } else if (Boolean.FALSE.equals(user.getActive())) {
        url = getUserBlockedUrl();
    } else {
        url = getUserUnknownErrorUrl();
    }
    WebUtils.issueRedirect(request, response, url);
}

From source file:com.motang.framework.shiro.filter.JCaptchaValidateFilter.java

License:Apache License

protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
    WebUtils.issueRedirect(request, response, this.getJcapatchaErrorUrl());
}

From source file:com.motang.framework.shiro.filter.SysUserFilter.java

License:Apache License

protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
    //        User user = (User) request.getAttribute(Constants.CURRENT_USER);
    //        String url = null;
    //        if (Boolean.TRUE.equals(user.getDeleted())) {
    //            url = getUserNotfoundUrl();
    //        } else if (user.getStatus() == UserStatus.blocked) {
    //            url = getUserBlockedUrl();
    //        } else {
    //            url = getUserUnknownErrorUrl();
    //        }/*from w w  w .  j av  a  2s. com*/

    WebUtils.issueRedirect(request, response, this.getUserBlockedUrl());
}