Java Code Examples for org.springframework.security.web.util.UrlUtils#buildRequestUrl()

The following examples show how to use org.springframework.security.web.util.UrlUtils#buildRequestUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyAntPathRequestMatcher.java    From bbs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Returns true if the configured pattern (and HTTP-Method) match those of the supplied request.
 * 修改
 * @param request the request to match against. The ant pattern will be matched against the
 *    {@code servletPath} + {@code pathInfo} of the request.
 */
public boolean matches(HttpServletRequest request) {
	
	
    if (httpMethod != null && request.getMethod() != null && httpMethod != HttpMethod.valueOf(request.getMethod())) {
        if (logger.isDebugEnabled()) {
            logger.debug("Request '" + request.getMethod() + " " + getRequestPath(request) + "'"
                    + " doesn't match '" + httpMethod  + " " + pattern);
        }

        return false;
    }

    if (pattern.equals(MATCH_ALL)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Request '" + getRequestPath(request) + "' matched by universal pattern '/**'");
        }

        return true;
    }
    
    //删除URL的路径和虚拟目录
    String url = UrlUtils.buildRequestUrl(request);
    return pathMatcher.match(pattern, url);
}
 
Example 2
Source File: StudioLoginUrlAuthenticationEntryPoint.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected String determineUrlToUseForThisRequest(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {

    String redirectParamValue = request.getContextPath() + UrlUtils.buildRequestUrl(request);
    try {
        redirectParamValue = UriUtils.encode(redirectParamValue, StandardCharsets.UTF_8.toString());
    } catch (UnsupportedEncodingException e) {
        logger.debug("Unsupported encoding for redirect query param value. Sending param without encoding it");
    }
    String redirect = super.determineUrlToUseForThisRequest(request, response, exception);
    return UriComponentsBuilder.fromPath(redirect).queryParam(PARAM_REDIRECT, redirectParamValue).toUriString();
}
 
Example 3
Source File: StudioLoginUrlAuthenticationEntryPoint.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
    String requestUrl = UrlUtils.buildRequestUrl(request);
    if (StringUtils.startsWith(requestUrl, "/api/")) {
        // This is invoked when user tries to access a secured REST resource without supplying any credentials
        // We should just send a 401 Unauthorized response because there is no 'login page' to redirect to
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
    } else {
        super.commence(request, response, authException);
    }
}