001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.docs.web.security;
018
019import org.springframework.boot.autoconfigure.security.reactive.PathRequest;
020import org.springframework.context.annotation.Bean;
021import org.springframework.security.config.web.server.ServerHttpSecurity;
022import org.springframework.security.web.server.SecurityWebFilterChain;
023
024/**
025 * Example configuration for customizing security rules for a WebFlux application.
026 *
027 * @author Madhura Bhave
028 */
029public class CustomWebFluxSecurityExample {
030
031        // @formatter:off
032        // tag::configuration[]
033        @Bean
034        public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
035                return http
036                        .authorizeExchange()
037                                .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
038                                .pathMatchers("/foo", "/bar")
039                                        .authenticated().and()
040                                .formLogin().and()
041                        .build();
042        }
043        // end::configuration[]
044        // @formatter:on
045
046}