Example usage for org.springframework.security.config.http WebConfigUtils validateHttpRedirect

List of usage examples for org.springframework.security.config.http WebConfigUtils validateHttpRedirect

Introduction

In this page you can find the example usage for org.springframework.security.config.http WebConfigUtils validateHttpRedirect.

Prototype

static void validateHttpRedirect(String url, ParserContext pc, Object source) 

Source Link

Document

Checks the value of an XML attribute which represents a redirect URL.

Usage

From source file:org.springframework.security.config.http.FormLoginBeanDefinitionParser.java

public BeanDefinition parse(Element elt, ParserContext pc) {
    String loginUrl = null;/*from   ww w .j a v a  2  s . c  om*/
    String defaultTargetUrl = null;
    String authenticationFailureUrl = null;
    String alwaysUseDefault = null;
    String successHandlerRef = null;
    String failureHandlerRef = null;
    // Only available with form-login
    String usernameParameter = null;
    String passwordParameter = null;
    String authDetailsSourceRef = null;
    String authenticationFailureForwardUrl = null;
    String authenticationSuccessForwardUrl = null;

    Object source = null;

    if (elt != null) {
        source = pc.extractSource(elt);
        loginUrl = elt.getAttribute(ATT_LOGIN_URL);
        WebConfigUtils.validateHttpRedirect(loginUrl, pc, source);
        defaultTargetUrl = elt.getAttribute(ATT_FORM_LOGIN_TARGET_URL);
        WebConfigUtils.validateHttpRedirect(defaultTargetUrl, pc, source);
        authenticationFailureUrl = elt.getAttribute(ATT_FORM_LOGIN_AUTHENTICATION_FAILURE_URL);
        WebConfigUtils.validateHttpRedirect(authenticationFailureUrl, pc, source);
        alwaysUseDefault = elt.getAttribute(ATT_ALWAYS_USE_DEFAULT_TARGET_URL);
        loginPage = elt.getAttribute(ATT_LOGIN_PAGE);
        successHandlerRef = elt.getAttribute(ATT_SUCCESS_HANDLER_REF);
        failureHandlerRef = elt.getAttribute(ATT_FAILURE_HANDLER_REF);
        authDetailsSourceRef = elt.getAttribute(AuthenticationConfigBuilder.ATT_AUTH_DETAILS_SOURCE_REF);
        authenticationFailureForwardUrl = elt.getAttribute(ATT_FORM_LOGIN_AUTHENTICATION_FAILURE_FORWARD_URL);
        WebConfigUtils.validateHttpRedirect(authenticationFailureForwardUrl, pc, source);
        authenticationSuccessForwardUrl = elt.getAttribute(ATT_FORM_LOGIN_AUTHENTICATION_SUCCESS_FORWARD_URL);
        WebConfigUtils.validateHttpRedirect(authenticationSuccessForwardUrl, pc, source);

        if (!StringUtils.hasText(loginPage)) {
            loginPage = null;
        }
        WebConfigUtils.validateHttpRedirect(loginPage, pc, source);
        usernameParameter = elt.getAttribute(ATT_USERNAME_PARAMETER);
        passwordParameter = elt.getAttribute(ATT_PASSWORD_PARAMETER);
    }

    filterBean = createFilterBean(loginUrl, defaultTargetUrl, alwaysUseDefault, loginPage,
            authenticationFailureUrl, successHandlerRef, failureHandlerRef, authDetailsSourceRef,
            authenticationFailureForwardUrl, authenticationSuccessForwardUrl);

    if (StringUtils.hasText(usernameParameter)) {
        filterBean.getPropertyValues().addPropertyValue("usernameParameter", usernameParameter);
    }
    if (StringUtils.hasText(passwordParameter)) {
        filterBean.getPropertyValues().addPropertyValue("passwordParameter", passwordParameter);
    }

    filterBean.setSource(source);

    BeanDefinitionBuilder entryPointBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(LoginUrlAuthenticationEntryPoint.class);
    entryPointBuilder.getRawBeanDefinition().setSource(source);
    entryPointBuilder.addConstructorArgValue(loginPage != null ? loginPage : DEF_LOGIN_PAGE);
    entryPointBuilder.addPropertyValue("portMapper", portMapper);
    entryPointBuilder.addPropertyValue("portResolver", portResolver);
    entryPointBean = (RootBeanDefinition) entryPointBuilder.getBeanDefinition();

    return null;
}