Example usage for org.springframework.security.config Elements ACCESS_DENIED_HANDLER

List of usage examples for org.springframework.security.config Elements ACCESS_DENIED_HANDLER

Introduction

In this page you can find the example usage for org.springframework.security.config Elements ACCESS_DENIED_HANDLER.

Prototype

String ACCESS_DENIED_HANDLER

To view the source code for org.springframework.security.config Elements ACCESS_DENIED_HANDLER.

Click Source Link

Usage

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

private BeanMetadataElement createAccessDeniedHandler(Element element, ParserContext pc) {
    Element accessDeniedElt = DomUtils.getChildElementByTagName(element, Elements.ACCESS_DENIED_HANDLER);
    BeanDefinitionBuilder accessDeniedHandler = BeanDefinitionBuilder
            .rootBeanDefinition(AccessDeniedHandlerImpl.class);

    if (accessDeniedElt != null) {
        String errorPage = accessDeniedElt.getAttribute("error-page");
        String ref = accessDeniedElt.getAttribute("ref");

        if (StringUtils.hasText(errorPage)) {
            if (StringUtils.hasText(ref)) {
                pc.getReaderContext()//ww  w .  j a  v  a2 s  . c o m
                        .error("The attribute " + ATT_ACCESS_DENIED_ERROR_PAGE
                                + " cannot be used together with the 'ref' attribute within <"
                                + Elements.ACCESS_DENIED_HANDLER + ">", pc.extractSource(accessDeniedElt));

            }
            accessDeniedHandler.addPropertyValue("errorPage", errorPage);
        } else if (StringUtils.hasText(ref)) {
            return new RuntimeBeanReference(ref);
        }

    }

    return accessDeniedHandler.getBeanDefinition();
}