|
| 1 | +/* |
| 2 | + * Copyright [2019] [恒宇少年 - 于起宇] |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +package org.minbox.framework.api.boot.autoconfigure.logging.admin; |
| 19 | + |
| 20 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
| 21 | +import org.springframework.context.annotation.Configuration; |
| 22 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 23 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
| 24 | +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; |
| 25 | + |
| 26 | +/** |
| 27 | + * ApiBoot Logging Admin SpringSecurity Config |
| 28 | + * {@link WebSecurityConfigurerAdapter} |
| 29 | + * |
| 30 | + * @author 恒宇少年 |
| 31 | + */ |
| 32 | +@Configuration |
| 33 | +@ConditionalOnClass(WebSecurityConfigurerAdapter.class) |
| 34 | +public class ApiBootLoggingAdminSecurityAutoConfiguration extends WebSecurityConfigurerAdapter { |
| 35 | + /** |
| 36 | + * Logging Admin Login Page |
| 37 | + */ |
| 38 | + private static final String LOGIN_PAGE = "/login"; |
| 39 | + /** |
| 40 | + * Logging Admin UI Resource Prefix |
| 41 | + */ |
| 42 | + private static final String ASSETS_RESOURCE_PREFIX = "/assets/**"; |
| 43 | + |
| 44 | + @Override |
| 45 | + protected void configure(HttpSecurity http) throws Exception { |
| 46 | + SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); |
| 47 | + successHandler.setTargetUrlParameter("redirectTo"); |
| 48 | + http.authorizeRequests() |
| 49 | + .antMatchers(ASSETS_RESOURCE_PREFIX).permitAll() |
| 50 | + .antMatchers(LOGIN_PAGE).permitAll() |
| 51 | + .anyRequest().authenticated() |
| 52 | + .and() |
| 53 | + .formLogin().loginPage(LOGIN_PAGE).successHandler(successHandler).and() |
| 54 | + .logout().and() |
| 55 | + .httpBasic().and() |
| 56 | + .csrf().disable(); |
| 57 | + } |
| 58 | +} |
0 commit comments