Example usage for org.springframework.security.config.annotation.web.builders HttpSecurity getConfigurer

List of usage examples for org.springframework.security.config.annotation.web.builders HttpSecurity getConfigurer

Introduction

In this page you can find the example usage for org.springframework.security.config.annotation.web.builders HttpSecurity getConfigurer.

Prototype

<C extends SecurityConfigurer<DefaultSecurityFilterChain, H>> C getConfigurer(Class<C> clazz);

Source Link

Document

Gets the SecurityConfigurer by its class name or null if not found.

Usage

From source file:sample.MyConfigurer.java

@SuppressWarnings("unchecked")
@Override//from ww w  .  j av a 2  s  .  c  o m
public void init(HttpSecurity http) throws Exception {
    // autowire this bean
    ApplicationContext context = http.getSharedObject(ApplicationContext.class);
    context.getAutowireCapableBeanFactory().autowireBean(this);

    // Our DSL allows to grant access to URLs defined by permitAllPattern in a property
    // and then requires authentication for any other request
    http.authorizeRequests().antMatchers(permitAllPattern).permitAll().anyRequest().authenticated();

    if (http.getConfigurer(FormLoginConfigurer.class) == null) {
        // only apply if formLogin() was not invoked by the user
        // this is a way of providing a default, but allow users to override
        http.formLogin().loginPage(loginPage);
    }
}