當前位置: 首頁>>代碼示例>>Java>>正文


Java WebUtils.toHttp方法代碼示例

本文整理匯總了Java中org.apache.shiro.web.util.WebUtils.toHttp方法的典型用法代碼示例。如果您正苦於以下問題:Java WebUtils.toHttp方法的具體用法?Java WebUtils.toHttp怎麽用?Java WebUtils.toHttp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.shiro.web.util.WebUtils的用法示例。


在下文中一共展示了WebUtils.toHttp方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onAccessDenied

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
    StringBuffer sso_server_url = new StringBuffer(PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.sso.server.url"));
    // server需要登錄
    String upmsType = PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.type");
    if ("server".equals(upmsType)) {
        WebUtils.toHttp(response).sendRedirect(sso_server_url.append("/sso/login").toString());
        return false;
    }
    sso_server_url.append("/sso/index").append("?").append("appid").append("=").append(PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.appID"));
    // 回跳地址
    HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
    StringBuffer backurl = httpServletRequest.getRequestURL();
    String queryString = httpServletRequest.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        backurl.append("?").append(queryString);
    }
    sso_server_url.append("&").append("backurl").append("=").append(URLEncoder.encode(backurl.toString(), "utf-8"));
    WebUtils.toHttp(response).sendRedirect(sso_server_url.toString());
    return false;
}
 
開發者ID:youngMen1,項目名稱:-Spring-SpringMVC-Mybatis-,代碼行數:22,代碼來源:UpmsAuthenticationFilter.java

示例2: isAccessAllowed

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
		throws Exception {
	// 1、設置驗證碼是否開啟屬性,頁麵可以根據該屬性來決定是否顯示驗證碼
	request.setAttribute("captchaEbabled", captchaEbabled);

	HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
	// 2、判斷驗證碼是否禁用 或不是表單提交(允許訪問)
	if (captchaEbabled == false || !"post".equalsIgnoreCase(httpServletRequest.getMethod())) {
		return true;
	}
	// 3、此時是表單提交,驗證驗證碼是否正確
	// 獲取頁麵提交的驗證碼
	String submitCaptcha = httpServletRequest.getParameter(captchaParam);
	// 獲取session中的驗證碼
	String captcha = (String) httpServletRequest.getSession().getAttribute("rcCaptcha");
	if (submitCaptcha.equals(captcha)) {
		return true;
	}
	return false;
}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:22,代碼來源:RcCaptchaValidateFilter.java

示例3: onPreHandle

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
@Override
protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
   	Subject subject = SecurityUtils.getSubject();
	if (!subject.isAuthenticated()) {
        HttpServletRequest httpRequest = WebUtils.toHttp(request);
        String authzHeader = httpRequest.getHeader(AUTHORIZATION_HEADER);
        if (authzHeader != null) {
            if (authzHeader.toLowerCase(Locale.ENGLISH).startsWith("basic") 
            		|| authzHeader.toLowerCase(Locale.ENGLISH).startsWith("token")) {
            	String authToken = StringUtils.substringAfter(authzHeader, " ");
                String decoded = Base64.decodeToString(authToken);
                String userName = StringUtils.substringBefore(decoded, ":").trim();
                String password = StringUtils.substringAfter(decoded, ":").trim();
                if (userName.length() != 0 && password.length() != 0) {
	                UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
                    subject.login(token);
                }
            }
        } 
	} 
	
	return true;
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:24,代碼來源:BasicAuthenticationFilter.java

示例4: onAccessDenied

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
    StringBuffer sso_server_url = new StringBuffer(PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.sso.server.url"));
    // server需要登錄
    String upmsType = PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.type");
    if ("server".equals(upmsType)) {
        WebUtils.toHttp(response).sendRedirect(sso_server_url.append("/sso/login").toString());
        return false;
    }
    sso_server_url.append("/sso/index").append("?").append("appid").append("=").append(PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.appID"));
    // 回跳地址
    HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
    StringBuffer backurl = httpServletRequest.getRequestURL();
    String queryString = httpServletRequest.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        backurl.append("?").append(queryString);
    }
    sso_server_url.append("&").append("backurl").append("=").append(URLEncoder.encode(backurl.toString(), "utf-8"));
    WebUtils.toHttp(response).sendRedirect(sso_server_url.toString());
    return false;
}
 
開發者ID:sunzhen086,項目名稱:lambo,代碼行數:22,代碼來源:UpmsAuthenticationFilter.java

示例5: onAccessDenied

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
    StringBuffer ssoServerUrl = new StringBuffer(PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.sso.server.url"));
    // server需要登錄
    String upmsType = PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.type");
    if ("server".equals(upmsType)) {
        WebUtils.toHttp(response).sendRedirect(ssoServerUrl.append("/sso/login").toString());
        return false;
    }
    ssoServerUrl.append("/sso/index").append("?").append("appid").append("=").append(PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.appID"));
    // 回跳地址
    HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
    StringBuffer backurl = httpServletRequest.getRequestURL();
    String queryString = httpServletRequest.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        backurl.append("?").append(queryString);
    }
    ssoServerUrl.append("&").append("backurl").append("=").append(URLEncoder.encode(backurl.toString(), "utf-8"));
    WebUtils.toHttp(response).sendRedirect(ssoServerUrl.toString());
    return false;
}
 
開發者ID:ChangyiHuang,項目名稱:shuzheng,代碼行數:22,代碼來源:UpmsAuthenticationFilter.java

示例6: onAccessDenied

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
/**
 * 所有請求都會經過的方法。
 */
@Override
protected boolean onAccessDenied(ServletRequest request,
                                 ServletResponse response) throws Exception {

    if (isLoginRequest(request, response)) {
        if (isLoginSubmission(request, response)) {
            //嘗試執行登陸
            return executeLogin(request, response);
        } else {
            //登陸頁麵視圖
            return true;
        }
    } else {//處理會話過期返回
        if (!"XMLHttpRequest".equalsIgnoreCase(((HttpServletRequest) request).getHeader("X-Requested-With"))) {// 不是ajax請求
            saveRequestAndRedirectToLogin(request, response);
        } else {
            HttpServletResponse res = WebUtils.toHttp(response);
            res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        }
        return false;
    }
}
 
開發者ID:haizicq,項目名稱:osframe,代碼行數:26,代碼來源:MscAuthenticationFilter.java

示例7: buildJSONMessage

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
private void buildJSONMessage(String message, ServletRequest request, ServletResponse response){
    try {
        Map map = new HashMap<String, Object>();
        map.put("code", HttpStatus.UNAUTHORIZED.value());
        map.put("message", message);
        map.put("timestamp", new Date());
        HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
        httpServletResponse.setCharacterEncoding("UTF-8");
        httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
        servletOutputStream.print(JSONObject.toJSONString(map));
        servletOutputStream.flush();
        servletOutputStream.close();
    } catch (IOException e) {
        logger.error(e.getMessage(), e.getCause());
        e.printStackTrace();
    }
}
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:19,代碼來源:FormAuthenticationFilterExt.java

示例8: buildJSONMessage

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
private void buildJSONMessage(String message, ServletRequest request, ServletResponse response){
    try {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", HttpStatus.UNAUTHORIZED.value());
        map.put("message", message);
        map.put("timestamp", new Date());
        HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
        httpServletResponse.setCharacterEncoding("UTF-8");
        httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
        servletOutputStream.print(JSONObject.toJSONString(map));
        servletOutputStream.flush();
        servletOutputStream.close();
    } catch (IOException e) {
        logger.error(e.getMessage(), e.getCause());
        e.printStackTrace();
    }
}
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:19,代碼來源:PcFormAuthenticationFilter.java

示例9: isAccessAllowed

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
/**
 * The Basic authentication filter can be configured with a list of HTTP methods to which it should apply. This
 * method ensures that authentication is <em>only</em> required for those HTTP methods specified. For example,
 * if you had the configuration:
 * <pre>
 *    [urls]
 *    /basic/** = authcBasic[POST,PUT,DELETE]
 * </pre>
 * then a GET request would not required authentication but a POST would.
 * @param request The current HTTP servlet request.
 * @param response The current HTTP servlet response.
 * @param mappedValue The array of configured HTTP methods as strings. This is empty if no methods are configured.
 */
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
    HttpServletRequest httpRequest = WebUtils.toHttp(request);
    String httpMethod = httpRequest.getMethod();
    
    // Check whether the current request's method requires authentication.
    // If no methods have been configured, then all of them require auth,
    // otherwise only the declared ones need authentication.
    String[] methods = (String[]) (mappedValue == null ? new String[0] : mappedValue);
    boolean authcRequired = methods.length == 0;
    for (String m : methods) {
        if (httpMethod.equalsIgnoreCase(m)) {
            authcRequired = true;
            break;
        }
    }
    
    if (authcRequired) {
        return super.isAccessAllowed(request, response, mappedValue);
    }
    else {
        return true;
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:37,代碼來源:BasicHttpAuthenticationFilter.java

示例10: sendChallenge

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
protected void sendChallenge(ServletRequest request, ServletResponse response) throws IOException {
    HttpServletResponse httpResponse = WebUtils.toHttp(response);
    HttpServletRequest httpRequest = WebUtils.toHttp(request);
    String loginUrl = getLoginUrl();

    // org.apache.shiro.web.util.WebUtils.issueRedirect(ServletRequest,
    // ServletResponse, String, Map, boolean, boolean)
    // org.apache.shiro.web.util.RedirectView.renderMergedOutputModel(Map,
    // HttpServletRequest, HttpServletResponse)
    // Prepare name URL.
    StringBuilder targetUrl = new StringBuilder();
    if (loginUrl.startsWith("/")) {
        // Do not apply context path to relative URLs.
        targetUrl.append(httpRequest.getContextPath());
    }
    targetUrl.append(loginUrl);

    String url = targetUrl.toString();
    url = httpResponse.encodeRedirectURL(url);
    httpResponse.setHeader("Location", url);
    httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
 
開發者ID:howiefh,項目名稱:jee-restful-web,代碼行數:23,代碼來源:RestFormAuthenticationFilter.java

示例11: extractToken

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
public static String extractToken(ServletRequest request) {
  HttpServletRequest httpRequest = WebUtils.toHttp(request);
  
  String header =  httpRequest.getHeader(AUTHORIZATION_HEADER);
  if (header == null || header.isEmpty())
    return null;
  
  if (!header.toLowerCase(Locale.ENGLISH).startsWith("bearer"))
    return null;
  
  String[] headerParts = header.split(" ");
  if (headerParts.length != 2)
    return null;
  
  String jwt = headerParts[1];
  return jwt;
}
 
開發者ID:OHDSI,項目名稱:WebAPI,代碼行數:18,代碼來源:TokenManager.java

示例12: preHandle

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
  HttpServletRequest httpRequest = WebUtils.toHttp(request);
  
  String path = httpRequest.getPathInfo()
                            .replaceAll("^/+", "")
                            .replaceAll("/+$", "")
                            // replace special characters
                            .replace(":", "&colon;")
                            .replace(",", "&comma;")
                            .replace("*", "&asterisk;");

  String method = httpRequest.getMethod();    
  String permission = String.format("%s:%s", path.replace("/", ":"), method).toLowerCase();

  if (this.isPermitted(permission))
    return true;
  
  HttpServletResponse httpResponse = WebUtils.toHttp(response);
  httpResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
  return false;
}
 
開發者ID:OHDSI,項目名稱:WebAPI,代碼行數:23,代碼來源:UrlBasedAuthorizingFilter.java

示例13: getCreatePermissionsOnCreateCohortDefinitionFilter

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
private Filter getCreatePermissionsOnCreateCohortDefinitionFilter() {
  return new ProcessResponseContentFilter() {
    @Override
    protected boolean shouldProcess(ServletRequest request, ServletResponse response) {
      HttpServletRequest httpRequest = WebUtils.toHttp(request);
      String path = httpRequest.getPathInfo().replaceAll("/+$", "");

      if (StringUtils.endsWithIgnoreCase(path, "copy")) {
        return HttpMethod.GET.equalsIgnoreCase(WebUtils.toHttp(request).getMethod());
      }
      else {
        return  HttpMethod.POST.equalsIgnoreCase(WebUtils.toHttp(request).getMethod());
      }
    }

    @Override
    protected void doProcessResponseContent(String content) throws Exception {
      String id = this.parseJsonField(content, "id");
      RoleEntity currentUserPersonalRole = authorizer.getCurrentUserPersonalRole();
      authorizer.addPermissionsFromTemplate(currentUserPersonalRole, cohortdefinitionCreatorPermissionTemplates, id);
    }
  };
}
 
開發者ID:OHDSI,項目名稱:WebAPI,代碼行數:24,代碼來源:AtlasSecurity.java

示例14: getDeletePermissionsOnDeleteCohortDefinitionFilter

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
private Filter getDeletePermissionsOnDeleteCohortDefinitionFilter() {
  return new AdviceFilter() {
    @Override
    protected void postHandle(ServletRequest request, ServletResponse response) {
      HttpServletRequest httpRequest = WebUtils.toHttp(request);
      if (!HttpMethod.DELETE.equalsIgnoreCase(httpRequest.getMethod())) {
        return;
      }

      String id = httpRequest.getPathInfo()
              .replaceAll("^/+", "")
              .replaceAll("/+$", "")
              .split("/")
              [1];
      authorizer.removePermissionsFromTemplate(cohortdefinitionCreatorPermissionTemplates, id);
    }
  };
}
 
開發者ID:OHDSI,項目名稱:WebAPI,代碼行數:19,代碼來源:AtlasSecurity.java

示例15: getDeletePermissionsOnDeleteConceptSetFilter

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
private Filter getDeletePermissionsOnDeleteConceptSetFilter() {
  return new AdviceFilter() {
    @Override
    protected void postHandle(ServletRequest request, ServletResponse response) {
      HttpServletRequest httpRequest = WebUtils.toHttp(request);
      if (!HttpMethod.DELETE.equalsIgnoreCase(httpRequest.getMethod())) {
        return;
      }

      String id = httpRequest.getPathInfo()
              .replaceAll("^/+", "")
              .replaceAll("/+$", "")
              .split("/")
              [1];
      authorizer.removePermissionsFromTemplate(conceptsetCreatorPermissionTemplates, id);
    }
  };
}
 
開發者ID:OHDSI,項目名稱:WebAPI,代碼行數:19,代碼來源:AtlasSecurity.java


注:本文中的org.apache.shiro.web.util.WebUtils.toHttp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。