org.springframework.security.web.util.UrlUtils Java Examples

The following examples show how to use org.springframework.security.web.util.UrlUtils. 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: XForwardedAwareRedirectStrategy.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
private String calculateRedirectUrl(String contextPath, String url) {
    if (!UrlUtils.isAbsoluteUrl(url)) {
        if (contextRelative) {
            return url;
        } else {
            return contextPath + url;
        }
    }

    // Full URL, including http(s)://

    if (!contextRelative) {
        return url;
    }

    // Calculate the relative URL from the fully qualified URL, minus the last
    // occurrence of the scheme and base context.
    url = url.substring(url.lastIndexOf("://") + 3); // strip off scheme
    url = url.substring(url.indexOf(contextPath) + contextPath.length());

    if (url.length() > 1 && url.charAt(0) == '/') {
        url = url.substring(1);
    }

    return url;
}
 
Example #3
Source File: MobileClientController.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static String getUrl( HttpServletRequest request, long id, String path )
{
    String url = UrlUtils.buildFullRequestUrl( request );
    if ( url.endsWith( "/" ) )
    {
        url = url + "orgUnits/" + id + "/" + path;
    }
    else
    {
        url = url + "/orgUnits/" + id + "/" + path;
    }
    return url;
}
 
Example #4
Source File: UrlGenerationUtils.java    From jakduk-api with MIT License 5 votes vote down vote up
/**
 * URL 생성
 *
 * @param request HttpServletRequest
 * @param uri URI
 * @return 만들어진 URL
 */
public static String buildFullRequestUrl(HttpServletRequest request, String uri) {

    return UrlUtils.buildFullRequestUrl(
            request.getScheme(),
            request.getServerName(),
            request.getServerPort(),
            request.getContextPath() + uri, null);
}
 
Example #5
Source File: MustacheCustomTag.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setAttributes(Node node, String tagName, Map<String, String> attributes) {
    if (node instanceof Link) {
        Link l = (Link) node;
        String destination = StringUtils.trimToEmpty(l.getDestination());
        if (UrlUtils.isAbsoluteUrl(destination)) {
            attributes.put("target", "_blank");
            attributes.put("rel", "nofollow noopener noreferrer");
        }
    }
}
 
Example #6
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 #7
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);
    }
}
 
Example #8
Source File: MySimpleUrlAuthenticationFailureHandler.java    From springboot-security-wechat with Apache License 2.0 4 votes vote down vote up
public void setDefaultFailureUrl(String defaultFailureUrl) {
    Assert.isTrue(UrlUtils.isValidRedirectUrl(defaultFailureUrl), "'" + defaultFailureUrl + "' is not a valid redirect URL");
    this.defaultFailureUrl = defaultFailureUrl;
}
 
Example #9
Source File: XForwardedAwareRedirectStrategy.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException {
    String redirectUrl = calculateRedirectUrl(request.getContextPath(), url);

    UriComponentsBuilder builder;
    if (UrlUtils.isAbsoluteUrl(redirectUrl)) {
        builder = UriComponentsBuilder.fromHttpUrl(redirectUrl);
    } else {
        builder = UriComponentsBuilder.fromUriString(redirectUrl);
    }

    String scheme = request.getHeader(HttpHeaders.X_FORWARDED_PROTO);
    if (scheme != null && !scheme.isEmpty()) {
        builder.scheme(scheme);
    }

    String host = request.getHeader(HttpHeaders.X_FORWARDED_HOST);
    if (host != null && !host.isEmpty()) {
        if (host.contains(":")) {
            // Forwarded host contains both host and port
            String [] parts = host.split(":");
            builder.host(parts[0]);
            builder.port(parts[1]);
        } else {
            builder.host(host);
        }
    }

    // handle forwarded path
    String forwardedPath = request.getHeader(X_FORWARDED_PREFIX);
    if (forwardedPath != null && !forwardedPath.isEmpty()) {
        String path = builder.build().getPath();
        // remove trailing slash
        forwardedPath = forwardedPath.substring(0, forwardedPath.length() - (forwardedPath.endsWith("/") ? 1 : 0));
        builder.replacePath(forwardedPath + path);
    }

    redirectUrl = response.encodeRedirectURL(builder.build(false).toUriString());

    if (logger.isDebugEnabled()) {
        logger.debug("Redirecting to '{}'", redirectUrl);
    }

    response.sendRedirect(redirectUrl);
}
 
Example #10
Source File: MobileClientController.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private org.hisp.dhis.api.mobile.model.LWUITmodel.MobileOrgUnitLinks getTrackerOrgUnit( OrganisationUnit unit,
    HttpServletRequest request )
{
    org.hisp.dhis.api.mobile.model.LWUITmodel.MobileOrgUnitLinks orgUnit = new org.hisp.dhis.api.mobile.model.LWUITmodel.MobileOrgUnitLinks();

    orgUnit.setId( unit.getId() );
    orgUnit.setName( unit.getShortName() );

    orgUnit.setDownloadAllUrl( getUrl( request, unit.getId(), "all" ) );
    orgUnit.setUpdateActivityPlanUrl( getUrl( request, unit.getId(), "activitiyplan" ) );
    orgUnit.setUploadFacilityReportUrl( getUrl( request, unit.getId(), "dataSets" ) );
    orgUnit.setDownloadFacilityReportUrl( getUrl( request, unit.getId(), "dataSetValue" ) );
    orgUnit.setUploadActivityReportUrl( getUrl( request, unit.getId(), "activities" ) );
    orgUnit.setUpdateDataSetUrl( getUrl( request, unit.getId(), "updateDataSets" ) );
    orgUnit.setChangeUpdateDataSetLangUrl( getUrl( request, unit.getId(), "changeLanguageDataSet" ) );
    orgUnit.setSearchUrl( getUrl( request, unit.getId(), "search" ) );
    orgUnit.setUpdateNewVersionUrl( getUrl( request, unit.getId(), "updateNewVersionUrl" ) );
    orgUnit.setSendFeedbackUrl( getUrl( request, unit.getId(), "sendFeedback" ) );
    orgUnit.setFindUserUrl( getUrl( request, unit.getId(), "findUser" ) );
    orgUnit.setSendMessageUrl( getUrl( request, unit.getId(), "sendMessage" ) );
    orgUnit.setDownloadMessageConversationUrl( getUrl( request, unit.getId(), "downloadMessageConversation" ) );
    orgUnit.setGetMessageUrl( getUrl( request, unit.getId(), "getMessage" ) );
    orgUnit.setReplyMessageUrl( getUrl( request, unit.getId(), "replyMessage" ) );
    orgUnit.setDownloadInterpretationUrl( getUrl( request, unit.getId(), "downloadInterpretation" ) );
    orgUnit.setPostInterpretationUrl( getUrl( request, unit.getId(), "postInterpretation" ) );
    orgUnit.setPostCommentUrl( getUrl( request, unit.getId(), "postComment" ) );
    orgUnit.setUpdateContactUrl( getUrl( request, unit.getId(), "updateContactForMobile" ) );
    orgUnit.setFindPatientUrl( getUrl( request, unit.getId(), "findPatient" ) );
    orgUnit.setRegisterPersonUrl( getUrl( request, unit.getId(), "registerPerson" ) );
    orgUnit.setUploadProgramStageUrl( getUrl( request, unit.getId(), "uploadProgramStage" ) );
    orgUnit.setEnrollProgramUrl( getUrl( request, unit.getId(), "enrollProgram" ) );
    orgUnit.setGetVariesInfoUrl( getUrl( request, unit.getId(), "getVariesInfo" ) );
    orgUnit.setAddRelationshipUrl( getUrl( request, unit.getId(), "addRelationship" ) );
    orgUnit.setDownloadAnonymousProgramUrl( getUrl( request, unit.getId(), "downloadAnonymousProgram" ) );
    orgUnit.setFindProgramUrl( getUrl( request, unit.getId(), "findProgram" ) );
    orgUnit.setFindPatientInAdvancedUrl( getUrl( request, unit.getId(), "findPatientInAdvanced" ) );
    orgUnit.setFindPatientsUrl( getUrl( request, unit.getId(), "findPatients" ) );
    orgUnit.setFindVisitScheduleUrl( getUrl( request, unit.getId(), "findVisitSchedule" ) );
    orgUnit.setFindLostToFollowUpUrl( getUrl( request, unit.getId(), "findLostToFollowUp" ) );
    orgUnit.setHandleLostToFollowUpUrl( getUrl( request, unit.getId(), "handleLostToFollowUp" ) );
    orgUnit.setGenerateRepeatableEventUrl( getUrl( request, unit.getId(), "generateRepeatableEvent" ) );
    orgUnit.setUploadSingleEventWithoutRegistration( getUrl( request, unit.getId(),
        "uploadSingleEventWithoutRegistration" ) );
    orgUnit.setCompleteProgramInstanceUrl( getUrl( request, unit.getId(), "completeProgramInstance" ) );
    orgUnit.setRegisterRelativeUrl( getUrl( request, unit.getId(), "registerRelative" ) );

    // generate URL for download new version
    String full = UrlUtils.buildFullRequestUrl( request );
    String root = full.substring( 0, full.length() - UrlUtils.buildRequestUrl( request ).length() );
    String updateNewVersionUrl = root + "/dhis-web-api-mobile/updateClient.action";
    orgUnit.setUpdateNewVersionUrl( updateNewVersionUrl );

    return orgUnit;
}
 
Example #11
Source File: MobileClientController.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private MobileOrgUnitLinks getOrgUnit( OrganisationUnit unit, HttpServletRequest request )
{
    MobileOrgUnitLinks orgUnit = new MobileOrgUnitLinks();

    orgUnit.setId( unit.getId() );
    orgUnit.setName( unit.getShortName() );

    orgUnit.setDownloadAllUrl( getUrl( request, unit.getId(), "all" ) );
    orgUnit.setUpdateActivityPlanUrl( getUrl( request, unit.getId(), "activitiyplan" ) );
    orgUnit.setUploadFacilityReportUrl( getUrl( request, unit.getId(), "dataSets" ) );
    orgUnit.setDownloadFacilityReportUrl( getUrl( request, unit.getId(), "dataSetValue" ) );
    orgUnit.setUploadActivityReportUrl( getUrl( request, unit.getId(), "activities" ) );
    orgUnit.setUpdateDataSetUrl( getUrl( request, unit.getId(), "updateDataSets" ) );
    orgUnit.setChangeUpdateDataSetLangUrl( getUrl( request, unit.getId(), "changeLanguageDataSet" ) );
    orgUnit.setSearchUrl( getUrl( request, unit.getId(), "search" ) );
    orgUnit.setUpdateNewVersionUrl( getUrl( request, unit.getId(), "updateNewVersionUrl" ) );
    orgUnit.setSendFeedbackUrl( getUrl( request, unit.getId(), "sendFeedback" ) );
    orgUnit.setFindUserUrl( getUrl( request, unit.getId(), "findUser" ) );
    orgUnit.setSendMessageUrl( getUrl( request, unit.getId(), "sendMessage" ) );
    orgUnit.setDownloadMessageConversationUrl( getUrl( request, unit.getId(), "downloadMessageConversation" ) );
    orgUnit.setGetMessageUrl( getUrl( request, unit.getId(), "getMessage" ) );
    orgUnit.setReplyMessageUrl( getUrl( request, unit.getId(), "replyMessage" ) );
    orgUnit.setDownloadInterpretationUrl( getUrl( request, unit.getId(), "downloadInterpretation" ) );
    orgUnit.setPostInterpretationUrl( getUrl( request, unit.getId(), "postInterpretation" ) );
    orgUnit.setPostCommentUrl( getUrl( request, unit.getId(), "postComment" ) );
    orgUnit.setUpdateContactUrl( getUrl( request, unit.getId(), "updateContactForMobile" ) );
    orgUnit.setFindPatientUrl( getUrl( request, unit.getId(), "findPatient" ) );
    orgUnit.setRegisterPersonUrl( getUrl( request, unit.getId(), "registerPerson" ) );
    orgUnit.setUploadProgramStageUrl( getUrl( request, unit.getId(), "uploadProgramStage" ) );
    orgUnit.setEnrollProgramUrl( getUrl( request, unit.getId(), "enrollProgram" ) );
    orgUnit.setGetVariesInfoUrl( getUrl( request, unit.getId(), "getVariesInfo" ) );
    orgUnit.setAddRelationshipUrl( getUrl( request, unit.getId(), "addRelationship" ) );
    orgUnit.setDownloadAnonymousProgramUrl( getUrl( request, unit.getId(), "downloadAnonymousProgram" ) );
    orgUnit.setFindProgramUrl( getUrl( request, unit.getId(), "findProgram" ) );
    orgUnit.setFindPatientInAdvancedUrl( getUrl( request, unit.getId(), "findPatientInAdvanced" ) );
    orgUnit.setFindPatientsUrl( getUrl( request, unit.getId(), "findPatients" ) );
    orgUnit.setFindVisitScheduleUrl( getUrl( request, unit.getId(), "findVisitSchedule" ) );
    orgUnit.setFindLostToFollowUpUrl( getUrl( request, unit.getId(), "findLostToFollowUp" ) );
    orgUnit.setHandleLostToFollowUpUrl( getUrl( request, unit.getId(), "handleLostToFollowUp" ) );
    orgUnit.setGenerateRepeatableEventUrl( getUrl( request, unit.getId(), "generateRepeatableEvent" ) );
    orgUnit.setUploadSingleEventWithoutRegistration( getUrl( request, unit.getId(),
        "uploadSingleEventWithoutRegistration" ) );
    orgUnit.setCompleteProgramInstanceUrl( getUrl( request, unit.getId(), "completeProgramInstance" ) );
    orgUnit.setRegisterRelativeUrl( getUrl( request, unit.getId(), "registerRelative" ) );

    // generate URL for download new version
    String full = UrlUtils.buildFullRequestUrl( request );
    String root = full.substring( 0, full.length() - UrlUtils.buildRequestUrl( request ).length() );
    String updateNewVersionUrl = root + "/dhis-web-api-mobile/updateClient.action";
    orgUnit.setUpdateNewVersionUrl( updateNewVersionUrl );

    return orgUnit;
}
 
Example #12
Source File: ConfigAwareAuthenticationFailureHandler.java    From engine with GNU General Public License v3.0 4 votes vote down vote up
public void setDefaultFailureUrl(String defaultFailureUrl) {
    Assert.isTrue(UrlUtils.isValidRedirectUrl(defaultFailureUrl), "'"
        + defaultFailureUrl + "' is not a valid redirect URL");
    this.defaultFailureUrl = defaultFailureUrl;
}
 
Example #13
Source File: IntegrationAuthenticationFilter.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() {
    Assert.hasLength(filterProcessesUrl, "filterProcessesUrl must be specified");
    Assert.notNull(userDetailsService, "userDetailsService must be specified");
    Assert.isTrue(UrlUtils.isValidRedirectUrl(filterProcessesUrl), filterProcessesUrl + " isn't a valid redirect URL");
}