mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-12 21:49:01 +08:00
✨ Introducing new features. #2116 报表设计增加 spring security 安全控制
This commit is contained in:
1 parent
a648988bbf
commit
f0b24a8e40
4 files changed
+38
-22
No files matched your search
@@ -35,11 +35,6 @@
|
||||
<artifactId>ureport2-console</artifactId>
|
||||
<version>${ureport.version}</version>
|
||||
</dependency>
|
||||
<!--数据库-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!--web 模块-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -62,8 +57,12 @@
|
||||
</dependency>
|
||||
<!--security-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pigx-common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pigx-common-data</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
+2
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.ureport;
|
||||
|
||||
import com.pig4cloud.pigx.common.feign.annotation.EnablePigxFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
|
||||
@@ -28,6 +29,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
|
||||
* <p>
|
||||
* http://127.0.0.1:5006/ureport/designer
|
||||
*/
|
||||
@EnablePigxFeignClients
|
||||
@SpringCloudApplication
|
||||
public class PigxBiApplication {
|
||||
|
||||
|
||||
+28
-14
@@ -22,8 +22,14 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* WebSecurityConfigurer
|
||||
@@ -37,24 +43,13 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
@SneakyThrows
|
||||
protected void configure(HttpSecurity http) {
|
||||
http.formLogin()
|
||||
.loginPage("/login.html")
|
||||
.loginProcessingUrl("/login")
|
||||
.failureHandler((request, response, exception) -> {
|
||||
response.sendRedirect("/login.html?error=" + URLEncoder.encode(exception.getLocalizedMessage(), "utf-8"));
|
||||
})
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/login.html", "/login").permitAll()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
.and()
|
||||
.csrf().disable();
|
||||
http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").failureHandler(new LoginFailureHandler())
|
||||
.and().authorizeRequests().antMatchers("/login.html", "/login").permitAll().anyRequest().authenticated()
|
||||
.and().csrf().disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 不拦截静态资源
|
||||
*
|
||||
* @param web
|
||||
*/
|
||||
@Override
|
||||
@@ -62,5 +57,24 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
web.ignoring().antMatchers("/favicon.ico", "/css/**", "/error");
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录失败处理器,携带错误信息重定向到首页
|
||||
*/
|
||||
static class LoginFailureHandler implements AuthenticationFailureHandler {
|
||||
|
||||
/**
|
||||
* Called when an authentication attempt fails.
|
||||
* @param request the request during which the authentication attempt occurred.
|
||||
* @param response the response.
|
||||
* @param exception the exception which was thrown to reject the authentication
|
||||
*/
|
||||
@Override
|
||||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
|
||||
AuthenticationException exception) throws IOException {
|
||||
response.sendRedirect("/login.html?error="
|
||||
+ URLEncoder.encode(exception.getLocalizedMessage(), StandardCharsets.UTF_8.name()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+2
-1
@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
*/
|
||||
@Controller
|
||||
public class PageController {
|
||||
|
||||
/**
|
||||
* 表单设计URL
|
||||
*/
|
||||
@@ -18,11 +19,11 @@ public class PageController {
|
||||
|
||||
/**
|
||||
* 跳转至表单设计
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping
|
||||
public String designer() {
|
||||
return REDIRECT_UREPORT_DESIGNER;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user