企业级安全框架—spring security http basic基本认证(二)

1、创建受保护的资源controller接口

企业级安全框架—spring security http basic基本认证(二)

2、配置http basic authentication

2.1 继承WebSecurityConfigurerAdapter,@EnableWebSecurity 开启spring security保护机制

企业级安全框架—spring security http basic基本认证(二)

2.2 启动项目访问http://localhost:8080/getHomeInfo

企业级安全框架—spring security http basic基本认证(二)

2.3 输入用户名:user,密码:控制台打印的随机字符串。

企业级安全框架—spring security http basic基本认证(二)

2.4 访问:

企业级安全框架—spring security http basic基本认证(二)

ps: HTTP基本身份验证(BA)实现是强制对web资源进行访问控制的最简单技术,因为它不需要cookie、会话标识符或登录页面;相反,HTTP基本身份验证使用HTTP头中的标准字段。

http basic detail