Skip to content

Commit 2f5dfb8

Browse files
committed
添加Logging Admin 自动化整合SpringSecurity
1 parent 139bf9b commit 2f5dfb8

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/admin/ApiBootLoggingAdminAutoConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949
@ConditionalOnWebApplication
5050
@EnableConfigurationProperties(ApiBootLoggingAdminProperties.class)
5151
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
52-
@Import({ApiBootLoggingAdminUiAutoConfiguration.class, ApiBootLoggingStorageAutoConfiguration.class})
52+
@Import({
53+
ApiBootLoggingAdminUiAutoConfiguration.class,
54+
ApiBootLoggingStorageAutoConfiguration.class,
55+
ApiBootLoggingAdminSecurityAutoConfiguration.class
56+
})
5357
@EnableAsync
5458
public class ApiBootLoggingAdminAutoConfiguration {
5559
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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

Comments
 (0)