Spring Security 入门之自定义表单登录开发实现(三)

Spring Security自定义登录验证及登录返回结果 Spring Security自定义登录验证及登录返回结果一.功能描述二.处理逻辑简单流程自定义UserDetails自定义UserDetailsDAO自定义UserDetailsService自定义用户登录验证逻辑AuthenticationProvider三.Spring Security基本配置信息四.登录登出自定义处理器登录成功处理器LocalAuthenticationSuccessHandler登录失败处理器LocalAuthenticationFailureHandler登出成功处理器Loca 阅读详情

1. 前言

在弄懂HelloWorld案例后,我们将自定义登陆页面并弄自定义一个登陆表单,然后覆盖Spring Security默认的登陆页面。首先在引入如下依赖:

    <!--引入thymeleaf-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
   <!--Spring boot Web容器-->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      <!--引入SpringSecurity依赖-->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-security</artifactId>
      </dependency>

在配置文件中禁用引入thymeleaf 缓存如下所示:

server:
  port: 8001
spring:
  application:
    name: gsr-auth
  security:
    user:
      name: admin
      password: admin123
  ##  thymeleaf配置
  thymeleaf:
    cache: false

2. 自定义认证

2.1 自定义登录页面

<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>login</title>
    <link href="favicon.ico" rel="shortcut icon" />
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body style=" background: url(https://img.zcool.cn/community/019e835c611d92a801203d22c2cb34.jpg@1280w_1l_2o_100sh.jpg) no-repeat center center fixed; background-size: 100%;">


<div class="modal-dialog" style="margin-top: 10%;">
    <div class="modal-content">
        <div class="modal-header">

            <h4 class="modal-title text-center" id="myModalLabel">自定义登录页面</h4>
        </div>
        <form id="loginForm" class="form" th:action="@{/doLogin}" method="post">
            <div class="modal-body" id = "model-body">

                <div class="form-group">
                    <input type="text" name="username" class="form-control"placeholder="请输入用户名" autocomplete="off">
                </div>
                <div class="form-group">
                    <input type="password" name="password" class="form-control" placeholder="请输入密码" autocomplete="off">
                </div>
            </div>
            <div class="modal-footer">
                <div class="form-group">
                    <input type="submit" class="form-control btn btn-info btn-md" name="submit"  value="登陆" autocomplete="off">
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>

2.2 后端认证逻辑

表单定义好以后,接下来定义三个个如下方法:

@Controller
public class HelloWorldController {

    @GetMapping("/helloWorld")
    public ResponseEntity<String> helloWorld(){
        return ResponseEntity.ok("helloWorld");
    }

    /**
     * spring Security 自定义登陆成功跳转的URL必须为post,否则会报错405的问题()
     * @return ResponseEntity<String>
     */
    @PostMapping("/index")
    public ResponseEntity<String> index() {
        return ResponseEntity.ok("login Success!");
    }

    @RequestMapping("/login.html")
    public String login() {
        return  "login";
    }
}

最后在配置一个Spring Security的配置类:

@Configuration
public class AuthSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests().antMatchers("/index","/login.html").permitAll().anyRequest().authenticated()
                .and().formLogin().loginPage("/login.html").loginProcessingUrl("/doLogin").successForwardUrl("/index")
                .usernameParameter("username").passwordParameter("password")
                .and().csrf().disable();
    }

Spring Security 提供了一个WebSecurityConfigurerAdapter 抽象类,此类提供了丰富的配置,后面我们在深入研究此类,此处略过。上面配置类的代码简单分析一下:

  1. configure 方法可以使用链式配置。
  2. authorizeHttpRequests 表示开启权限认证。
  3. antMatchers 表示url路径匹配,此方法参数是一个可变参数列表。
  4. permitAll 结合antMatchers 表示匹配到的url路径可以直接访问(无需任何权限)
  5. anyRequest().authenticated() 表示所有的请求都需要认证才能访问。
  6. formLogin() 表示开启表单登陆配置,loginPage 指定登陆页面地址。loginProcessingUrl 用来配置登陆访问的接口地址,successForwardUrl 登陆成功后转发地址,usernameParameter 指定表单登陆的用户名属性,passwordParameter 指定表单中登陆的密码属性。需要注意的是loginProcessingUrl、usernameParameter、passwordParameter这三个属性的值需要与自定义登陆页表单相关属性一致。
  7. csrf().disable()表示禁用csrf 安全防御机制。

配置完成后,浏览器中直接输入:http://127.0.0.1:8001/ 会自动跳转到登陆页面:
在这里插入图片描述
输入用户名和密码,登陆成功跳转到/index 如下所示:
在这里插入图片描述

3. 自定义登陆成功处理

在前面配置中,我们使用successForwardUrl 作为用户登陆成功后的跳转地址,除了这个方法以外,defaultSuccessUrl也可以作为用户跳转地址。两者的区别如下所示:

  1. defaultSuccessUrl 表示用户登陆成功后会自动重定向到登陆之前的地址上,如果在浏览器直接访问登陆页面(login.html)登陆成功后就会重定向到defaultSuccessUrl指定的页面中,但是如果在未认证的情况下直接访问/helloWorld,此时会自动重定向到登陆页面,当认证成功后就会自动重定向到/helloWorld。
  2. successForwardUrl 表示只要认证成功就会访问指定的地址而不会考虑之前访问的地址。
  3. defaultSuccessUrl 还有一个重载的方法,第二个参数传入true则作用与successForwardUrl一样,不会考虑认证前访问的地址,只要认证成功就会访问指定的地址。
  4. successForwardUrl是通过转发实现页面跳转,而defaultSuccessUrl是通过重定向实现页面跳转。

3.1 登陆成功原理

需要说明的是:无论是successForwardUrl还是defaultSuccessUrl都是通过配置AuthenticationSuccessHandler接口实现的。此接口定义如下:
在这里插入图片描述
我们可以看到AuthenticationSuccessHandler接口提供了一个默认方法,此方法从5.2后加入此接口中,这个方法专门为Authentication Filter 使用。另一个方法也是下面我们需要理解并需要使用的方法,此方法中封装了request与response,还有一个保存了登录成功的用户信息,AuthenticationSuccessHandler 一共有三个实现类如下所示:
在这里插入图片描述
其中 defaultSuccessUrl 功能实现是由SavedRequestAwareAuthenticationSuccessHandler完成的,此类定义如下:
在这里插入图片描述
可以看到onAuthenticationSuccess 方法 最后是通过重定向来实现页面跳转。
successForwardUrl 功能实现是通过ForwardAuthenticationSuccessHandler类完成的,此类接口定义如下:
在这里插入图片描述
这个类的onAuthenticationSuccess 最后是通过转发实现页面跳转。通过上面两个类的源码分析,我们也可以自定义登陆成功的逻辑,需要注意的是:上述两个类页面跳转并不满足目前流行的前后端分离架构场景中即,后端只需返回登陆成功的JSON数据给前端,然后由前端负责后续的逻辑处理。

3.2 自定义登陆成功响应处理

我们可以自定义类实现AuthenticationSuccessHandler接口并实现其onAuthenticationSuccess方法如下:

@Configuration
public class AuthSecurityConfig extends WebSecurityConfigurerAdapter implements AuthenticationSuccessHandler {

 private final static ObjectMapper objectMapper = new ObjectMapper();

    private final static String CONTENT_TYPE_UTF8 = "application/json;charset=utf-8";

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests().antMatchers("/index", "/login.html").permitAll().anyRequest().authenticated()
                .and().formLogin().loginPage("/login.html").loginProcessingUrl("/doLogin").defaultSuccessUrl("/index")
                .usernameParameter("username").passwordParameter("password").successHandler(this)
                .and().csrf().disable();
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setContentType(CONTENT_TYPE_UTF8);
        Map<String, Object> resp = new HashMap<>();
        resp.put("code", 200);
        resp.put("msg", "登陆成功");
        resp.put("authentication", authentication);
        // 将登陆成功消息返回给前端
        response.getWriter().write(objectMapper.writeValueAsString(resp));
    }
}

当重启应用时,并不会自动跳转指定的页面,而是返回如下JSON字符串:
在这里插入图片描述

4. 自定义登陆失败处理

默认情况下:登陆失败则直接重定向到登陆页面,而没有任何提示错误消息提醒,我们可以将登陆失败的异常信息输出到登陆页面上,首先在登陆页面添加如下内容:

  <div class="modal-header">

            <h4 class="modal-title text-center" id="errorMsh" th:text="{SPRING_SECURITY_LAST_EXCEPTION}"></h4>
        </div>

在这里插入图片描述
后端配置如下:

@Configuration
public class AuthSecurityConfig extends WebSecurityConfigurerAdapter implements AuthenticationSuccessHandler {

    private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    private final static String CONTENT_TYPE_UTF8 = "application/json;charset=utf-8";


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests().antMatchers("/index", "/login.html").permitAll().anyRequest().authenticated()
                .and().formLogin().loginPage("/login.html").loginProcessingUrl("/doLogin").defaultSuccessUrl("/index")
                .usernameParameter("username").passwordParameter("password").successHandler(this).failureForwardUrl("/login.html")
                .and().csrf().disable();
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setContentType(CONTENT_TYPE_UTF8);
        Map<String, Object> resp = new HashMap<>();
        resp.put("code", 200);
        resp.put("msg", "登陆成功");
        resp.put("authentication", authentication);
        // 将登陆成功消息返回给前端
        response.getWriter().write(OBJECT_MAPPER.writeValueAsString(resp));
    }

重启应用后当登陆失败时会输出如下错误:
在这里插入图片描述
除了failureForwardUrl,还可以使用failureUrl,修改代码逻辑如下:
在这里插入图片描述
同时修改静态页面取值:
在这里插入图片描述
重新尝试错误登陆如下:
在这里插入图片描述

4.1 登陆失败原理

无论是 failureForwardUrl,还是 failureUrl,都是通过配置AuthenticationFailureHandler接口实现登陆失败逻辑处理。此接口定义如下:
在这里插入图片描述
Spring Security为此接口提供了5个实现类,如下图所示:
在这里插入图片描述

  1. SimpleUrlAuthenticationFailureHandler 默认处理的逻辑就是通过重定向到登陆页面,failureUrl 方法底层就是通过此类进行实现。
    在这里插入图片描述通过上面源码可以看到也可以设置 forwardToDestination 为true属性实现转发,其默认为false则是重定向。
  2. ForwardAuthenticationFailureHandler类非常简单,其处理逻辑即为failureForwardUrl 实现效果。
    在这里插入图片描述
    那么我们登陆错误展示的错误信息来源哪里呢?首先来到SimpleUrlAuthenticationFailureHandler#onAuthenticationFailure,这个方法中有如下代码片段:
    在这里插入图片描述
    首先说明的是:forwardToDestination 默认为false,我们可以看到当session不为空,或者allowSessionCreation(此属性默认为true),所以当认证失败的时候默认在session域对象里设置了一个属性,即:**WebAttributes.AUTHENTICATION_EXCEPTION **的值为:SPRING_SECURITY_LAST_EXCEPTION
    在这里插入图片描述
    这个值也就是我们最开始在静态页面取的表达式设置的值:
    在这里插入图片描述
    让我们再来分析ForwardAuthenticationFailureHandler类的 onAuthenticationFailure方法如下所示:
    在这里插入图片描述
    这次我们看到了其是在request域对象存储的WebAttributes.AUTHENTICATION_EXCEPTION的值。

4.2 自定义登陆失败响应处理

一般在前后端分离系统中,当认证失败时候只需后端发送认证失败结果为给前端,然后由前端实现认证失败的后续处理逻辑,这个时候我们可以自定义AuthenticationFailureHandler接口实现,我们继续改造AuthSecurityConfig类如下:

@Configuration
public class AuthSecurityConfig extends WebSecurityConfigurerAdapter implements AuthenticationSuccessHandler, AuthenticationFailureHandler {

    private final static ObjectMapper objectMapper = new ObjectMapper();

    private final static String CONTENT_TYPE_UTF8 = "application/json;charset=utf-8";


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests().antMatchers("/index", "/login.html").permitAll().anyRequest().authenticated()
                .and().formLogin().loginPage("/login.html").loginProcessingUrl("/doLogin").defaultSuccessUrl("/index")
                .usernameParameter("username").passwordParameter("password").successHandler(this).failureHandler(this)
                .and().csrf().disable();
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setContentType(CONTENT_TYPE_UTF8);
        Map<String, Object> resp = new HashMap<>();
        resp.put("code", 200);
        resp.put("msg", "登陆成功");
        resp.put("authentication", authentication);
        // 将登陆成功消息返回给前端
        response.getWriter().write(objectMapper.writeValueAsString(resp));
    }

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        response.setContentType(CONTENT_TYPE_UTF8);
        Map<String, Object> resp = new HashMap<>();
        resp.put("code", 500);
        resp.put("msg", "登陆失败:"+exception.getMessage());
        // 将登陆成功消息返回给前端
        response.getWriter().write(objectMapper.writeValueAsString(resp));
    }
}

重启应用当再次认证失败的时候只会输出一个JSON如下所示:
在这里插入图片描述

5. 注销用户处理

5.1 注销原理

Spring Security 提供了LogoutSuccessHandler接口专门处理注销用户,此接口只有一个onLogoutSuccess
方法,接口定义如下:
在这里插入图片描述
spring Security一共提供了4个类实现此接口如下所示:
在这里插入图片描述
上文中我们配置的登出逻辑是由SimpleUrlLogoutSuccessHandler类实现的,这个类onLogoutSuccess
调用了抽象父类的方法:
在这里插入图片描述
父类相应方法如下所示,当登出成功后就重定向到指定的url。
在这里插入图片描述Spring Security 中提供了默认的注销登录页面如下:
在这里插入图片描述当点击logOut按钮后就会再次跳转到登陆页面如下:
在这里插入图片描述
这里我们使用自己开发的静态登陆页面,在配置类添加如下代码:
在这里插入图片描述

  1. logout() 方法开启了登出的配置,logoutUrl指定注销url
  2. invalidateHttpSession表示登出并使session失效,其属性默认为true。
  3. clearAuthentication 表示清除认证信息,其属性默认为true。
  4. logoutSuccessUrl 表示注销登出成功跳转的地址。
    当重启项目后登陆认证成功后,然后在浏览器输入:http://127.0.0.1:8001/logout ,注销成功后会自动跳转到login.html。
    我们还可以在配置多个登出的url,同时并制定请求url的请求类型为get或者是post,我们修改配置类如下:
    在这里插入图片描述
    此时myLogout1与myLogout2 都可以完成注销,上述注销触发页面跳转都是在后台进行控制的,并不满足前后端分离的场景中,我们可以自定义登出成功的json给前端,然后由前端去处理后续逻辑。整体配置类代码如下:
/**
 * 自定义Spring Security 配置类
 *
 * @author GalenGao
 * @version Id: AuthSecurityConfig.java, v 0.1 2022/5/17 19:09 GalenGao Exp $$
 */
@Configuration
public class AuthSecurityConfig extends WebSecurityConfigurerAdapter implements
        AuthenticationSuccessHandler, AuthenticationFailureHandler , LogoutSuccessHandler {

    private final static ObjectMapper objectMapper = new ObjectMapper();

    private final static String CONTENT_TYPE_UTF8 = "application/json;charset=utf-8";


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests()
                .antMatchers("/index", "/login.html")
                .permitAll()
                .anyRequest()
                .authenticated()
                .and()
                .formLogin()
                .loginPage("/login.html")
                .loginProcessingUrl("/doLogin")
                .defaultSuccessUrl("/index")
                .usernameParameter("username")
                .passwordParameter("password")
                .successHandler(this)
                .failureHandler(this)
                .and()
                .logout()
//                .logoutUrl("/logout")
                .logoutRequestMatcher(new OrRequestMatcher(new AntPathRequestMatcher("/myLogout1", HttpMethod.GET.name()),
                        new AntPathRequestMatcher("/myLogout2", HttpMethod.POST.name())))
                .logoutSuccessHandler(this)
                .invalidateHttpSession(true)
                .clearAuthentication(true)
                .logoutSuccessUrl("/login.html")
                .and()
                .csrf().disable();
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setContentType(CONTENT_TYPE_UTF8);
        Map<String, Object> resp = new HashMap<>();
        resp.put("code", 200);
        resp.put("msg", "登陆成功");
        resp.put("authentication", authentication);
        // 将登陆成功消息返回给前端
        response.getWriter().write(objectMapper.writeValueAsString(resp));
    }

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        response.setContentType(CONTENT_TYPE_UTF8);
        Map<String, Object> resp = new HashMap<>();
        resp.put("code", 500);
        resp.put("msg", "登陆失败:" + exception.getMessage());
        // 将登陆成功消息返回给前端
        response.getWriter().write(objectMapper.writeValueAsString(resp));
    }

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setContentType(CONTENT_TYPE_UTF8);
        Map<String, Object> resp = new HashMap<>();
        resp.put("code", 200);
        resp.put("msg", "注销成功");
        resp.put("authentication", authentication);
        // 将登出成功消息返回给前端
        response.getWriter().write(objectMapper.writeValueAsString(resp));
    }
}

重启项目后 再次尝试登出成功后就返回了如下JSON字符串:
在这里插入图片描述

总结

这里我们将自定义表单登录的环节已经做了一次实战,下面我们将深入学习Spring Security 是如何进行认证,尽请期待。

spring security实现多接口登录 1. 新建项目,导入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> &... 阅读详情

相关推荐

Spring Security + Jwt实现单点登录

Spring Security 功能强大的处理**认证**和**授权**的框架 添加框架后,在不添加任何配置时,访问任何页面都会重定向到框架自带的login页面 框架提供了默认的用户名:``user``与密码:启动时生成的``UUID``

weixin_72718065的博客 1959

Security详解—自定义登录页面(3)

新建一个配置类WebSecurityConfig,并且继承WebSecurityConfigurerAdapter(如果WebSecurityConfigurerAdapter。@Autowired/*** formLogin() 默认使用了UsernamePasswordAuthenticationFilter* 默认使用了DaoAuthenticationProvider认证逻辑,使用configure可以配置UserDetailsService*/@Override。

myli92的博客 583

Spring Security 6.x 系列【7】认证篇之表单登录的自定义配置

提供了默认的认证规则,也支持各种自定义配置,本篇文档主要学习中表单登录的相关自定义配置。未认证的请求会重定向到默认登录页面,也支持自定义登录页面,首先创建一个简单的登录页login.html。

记录知识、锤炼自我 3052

SpringSecurity创建一个简单的自定义表单的认证应用

在 Spring Security 中创建自定义表单认证应用是一个常见的需求,特别是在需要自定义登录页面、认证逻辑或添加额外的表单字段时。以下是一个详细的步骤指南,帮助你创建一个自定义表单认证应用。WebSecurityConfigurerAdapter 是 Spring Security 框架中的一个关键组件,它作为一个适配器类,允许开发者通过继承它并重写相关方法来自定义 Web 应用的安全设置。

pan_junbiao的博客 1002

Spring Security 6.x 系列(12)—— Form表单认证登录注销自定义配置

在本系列文章中介绍了 `Form` 表单认证和注销流程,对部分源码也进行详细分析。 本章主要学习 `Spring Security` 中表单认证登录注销的相关自定义配置。

gmHappy 6297

Windows 2008 R2虚拟机跑金蝶K3 WISE 12.1的5个关键配置细节(附避坑清单)

本文详细介绍了在Windows Server 2008 R2虚拟机中部署金蝶K3 WISE 12.1的5个关键配置细节,包括服务器角色与账户权限、组件服务调优、数据库与中间层协同部署、补丁管理策略及性能优化工具。这些实战经验可帮助企业IT团队避免常见陷阱,确保ERP系统稳定运行。

weixin_30847939的博客 318

【Spring Security】四、自定义页面

在前面例子中,登陆页面都是用的Spring Security自己提供的,这明显不符合实际开发场景,同时也没有退出和注销按钮,因此在每次测试的时候都要通过关闭浏览器来注销达到清除session的效果。 一 、自定义页面 login.jsp: &lt;%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco...

weixin_34237596的博客 247

无人机通信安全渗透测试:从信号拦截到GPS欺骗的完整攻防框架

在物联网和智能设备普及的背景下,无线通信安全成为关键基础设施防护的核心环节。其原理在于,通过软件定义无线电等设备对空中的射频信号进行捕获、分析与模拟,从而评估通信协议在加密、认证和防重放等方面的脆弱性。这项技术的价值在于,它能主动发现并修复系统设计缺陷,避免因信号被拦截或欺骗导致设备被劫持、数据泄露等重大安全事件。其应用场景广泛,涵盖消费电子、工业控制及关键基础设施等领域。本文聚焦于无人机这一典型移动物联网终端,深入探讨如何构建一套针对其通信链路的渗透测试方法论,其中涉及信号拦截、协议逆向等关键技术,旨在为

weixin_34128237的博客 391

http.authorizeRequests()详解

表示可以匿名访问匹配的URL。访问控制方法都很简单, 只要匹配到url后直接在后面追加调用这个方法就行了,链式调用特别简单,不演示了。如果有参数,参数表示IP地址,如果用户IP和参数匹配,则可以访问。下面分别讲一下url匹配规则都有哪些,权限控制方法都有哪些。如果有参数,参数表示角色,则其中任何一个角色可以访问。如果有参数,参数表示权限,则其中任何一个权限可以访问。如果有参数,参数表示角色,则其角色可以访问。如果有参数,参数表示权限,则其权限可以访问。表示所匹配的URL都不允许被访问。

lyy的博客 4536

DeepLearningTool-深度学习分类-和HALCON的详细过程

损失函数:衡量预测误差,用于模型优化。混淆矩阵:评估分类模型性能,提供详细预测结果分析。两者结合使用,可以全面评估和优化模型。过拟合:模型过于复杂,捕捉了噪声,表现为训练集误差低,测试集误差高。欠拟合:模型过于简单,无法捕捉数据模式,表现为训练集和测试集误差都高。调整参数过拟合:简化模型、增加数据、使用正则化、早停、Dropout。欠拟合:增加模型复杂度、特征工程、增加训练时间、调整学习率、使用集成方法。通过合理调整参数和方法,可以有效避免过拟合和欠拟合,提升模型性能。

weixin_36672036的博客 6188

告别Nginx原始日志!VictoriaLogs+Grafana构建企业级应用日志分析平台实战

描述:做为一个合格的运维工程师,在面对企业安全运维管理中,日志审计是一项非常重要的工作。授人以鱼不如授人以渔,各位运友们可参照作者的方案设计,在自己的项目中根据实际情况调整落地,例如,不在仅仅采集 NGINX 应用日志,而是采集 Apache、Tomcat、SpringBoot 等多种应用服务器的日志,又如,不再仅仅采集网络设备、安全审计审计日志,而是 Windows、Linux 等多种操作系统的审计日志等,大家可充分发挥想象、实践能力,也欢迎大家在知识星球中分享自己的方案设计,一起交流学习。

全栈工程师修炼指南-IT知识分享 2477

Spring | 实现用户登入

一. 要求: 学生在控制台输入用户名密码,如果用户账号密码正确则显示用户所属班级,如果登录失败则显示登录失败。 二. 显示效果如下: 三. 步骤 1.创建数据库:在MySQL中的spring数据库中创建一个名为student的表。 2.编写实体类:创建Student类,在该类中定义id、username、password和course属性,以及属性对应的getter/setter方法。 public class Student { ...

weixin_52109976的博客 6015

解决国内网页无法加载reCaptcha的方法

科普: reCaptcha是Google公司的验证码服务,方便快捷,改变了传统验证码需要输入n位失真字符的特点。reCaptcha在使用的时候是这样的: 只需要点一下复选框,Google会收集一些鼠标轨迹、网络信息、浏览器信息等等,依靠后端的神经网络判断是机器还是人,绝大多数验证会一键通过,无需像传统验证码一样。但是reCaptcha使用了google.com的域名,这个域名在国内是被墙的。所以,也就导致了官网上无法注册/登录的问题,挡住了不少人入正的脚步。 解决办法: 【第一步】安装fir

调皮李小怪博客 25万+

Spring Security实现短信登录

文章目录一、理论说明1.1 用户名密码登录逻辑1.2 短信验证码登录逻辑二、代码实战2.1 SmsAuthenticationToken2.2 SmsAuthenticationFilter2.3 SmsAuthenticationProviderhardcode的方式来模拟手机号查询用户信息2.4 成功与失败处理逻辑2.5 SmsCodeAuthenticationSecurityConfig将...

weixin_38927257的博客 3233

Figure 03人形机器人与Helix端到端控制系统:具身智能突破深度解析

2026年5月,Figure AI的Figure 03人形机器人在一场震撼业界的直播中完成了长达200小时的连续全自动作业,分拣近25万个包裹,零故障。这一里程碑式的成就标志着人形机器人正式从「实验室展示」迈入「规模化商用」阶段。本文深入剖析Figure 03的核心技术——Helix端到端神经网络控制系统,包括System 0/1/2三层架构、视觉运动策略、全身协同控制等关键技术,并提供完整的Python/Go代码示例,帮助开发者理解具身智能的核心原理与实现路径。关键词。

shao.bing的专栏 993

二、PCIE的TLP包的封包解包原理

熟悉 PCIE 的组建包的过程,以及内部的字段细节的定 义,掌握如何发送接收 Mrd(memory read TLP)、 Mwr(Memory write TLP)、Cpl (Completion TLP)和 Cpld(Completion with data TLP)命令包,深入理解 PCIE 底层协议工作过程

k7126685的博客 3929

spring security 5 (1)-formLogin表单登录和注销

表单登录即在form表单中输入用户名/密码,提交登录,在spring security中默认配置了formLogin来实现表单登录。 pom.xml &lt;parent&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-parent&l...

JAVA博客 1万+

电动汽车远程监控与诊断软件:BMW ConnectedDrive EV远程监控二次开发_7.数据安全与隐私保护

数据加密是保护数据安全的重要手段之一。在电动汽车远程监控与诊断软件中,加密技术可以确保数据在传输过程中的安全性和完整性。常见的加密技术包括对称加密和非对称加密。

zhubeibei168的博客 884

Spring Security04 - 基于表单的登陆身份验证

Spring Security04 - 基于表单的登陆身份验证

qq_43350524的博客 1084

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Spring Security自定义表单登录页

(1)初步配置自定义表单登录页 首先覆盖config方法 import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecur...

qq_28248897的博客 1103

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

spring security实现表单登录以及自定义URL权限认证

本文主要介绍怎么快速搭建一个带spring security安全认证的应用,其他基础介绍,基本操作,内容原理略过,着重介绍实现步骤,如需详细了解请阅读相关文档。 0.环境 jdk 1.8 spring boot MySQL 5 需要准备5张表: 以上为5张表需要的字段,可根据实际需求变更 1.引入spring security 创建一个spring boot工程,在pom....

coolwind的博客 5888

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Spring security自定义登录界面

介绍 通常情况下,Spring security提供的默认登录界面不一定符合我们的需求,所以我们需要自定义一个登录界面,下面会说明主要步骤。如果不清楚springboot如何集成Spring security, 请先看一下Springboot集成Spring security 开发步骤介绍1、SecurityConfig继承WebSecurityConfigurerAdapter2、编写自定义lo...

攀登Fox的博客 4756

spring security 入门基础,表单认证web页面跳转

帮助快速搭建springsecurity 基于form表单方式web 传统开发页面跳转流程分析

冬阳 1476

SpringBoot集成Spring Security(4)——自定义表单登录

通过前面三篇文章,应该大致了解了Spring Security的流程。你应该发现了,真正的登录请求是由Spring Security帮我们处理的,那么我们如何实现自定义表单登录呢,比如添加一个验证码… 一、添加验证码 1.1 验证码Servlet 1.2 修改Login.html 1.3 添加匿名访问Url 二、AJAX验证 三、过滤器验证 3.1 编写验证码过滤器 3.2 ...

Jitwxs 1万+

【Spring Security系列】Spring Security默认表单登录

上篇博客中,我们初步引入了Spring Security,并使用其默认生效的HTTP基本认证来保护URL资源,此处我们使用表单认证来保护URL资源。 首先,新建一个config包用于存放通用配置;然后,新建一个WebSecurityConfig类,使其继承WebSecurityConfigurerAdapter,WebSecurityConfigurerAdapter 类是个适配器, 在配置的时候,需要我们自己写个配置类去继承他,然后编写自己所需要的配置。 @EnableWebSecurity pub

qq_28248897的博客 1774

【深入浅出Spring Security(三)】默认登录认证的实现原理

思考:发送请求的登录界面是如何来的?用户名和密码为什么是user和一个UUID字符串呢?它又是如何进行用户名和密码验证的呢?得知道 DaoAuthenticationProvider retrieveUser 方法和 additionalAuthenticationChecks 方法(这俩方法分别应用了UserDetailsService和PasswordEncoder对象)。UsernamePasswordAuthenticationFilter 最后也是去通过 ProviderManager 中的 au

qq_63691275的博客 4321
上一篇: Spring Security 从入门到精通之环境搭建与HelloWorld案例源码详解(二)
下一篇: Spring Security 从入门到精通之获取认证用户信息(四)
Galen-gao
博客等级 码龄9年 931粉丝 137原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值