pig4j 它的登录白名单如何设置呢
时间: 2023-09-07 09:11:33 浏览: 33
关于 pig4j 的登录白名单设置,你可以按照以下步骤进行:
1. 打开 pig4j 的配置文件 application.yml(或者 application.properties);
2. 找到 spring.security.user.name 和 spring.security.user.password 两个配置项,分别设置登录用户名和登录密码;
3. 找到 spring.security.user.roles 配置项,设置该用户的角色,例如 ROLE_USER;
4. 找到 spring.security.allow-credentials 配置项,设置为 true,允许发送身份验证凭据;
5. 找到 spring.security.filter-dispatcher-types 配置项,设置为 ASYNC、REQUEST、ERROR,以确保安全过滤器在所有请求上都起作用;
6. 找到 spring.security.remember-me.key 配置项,设置记住我功能的密钥,确保在用户关闭浏览器后仍然可以保持登录状态;
7. 找到 spring.security.remember-me.token-validity-seconds 配置项,设置记住我功能的有效期,以秒为单位。
至于登录白名单的设置,可以使用 Spring Security 提供的 WebSecurityConfigurerAdapter 类进行配置。具体步骤如下:
1. 创建一个继承自 WebSecurityConfigurerAdapter 的类;
2. 重写 configure(HttpSecurity http) 方法,在该方法中进行登录白名单的设置;
3. 在 configure(HttpSecurity http) 方法中,通过 http.authorizeRequests() 方法来配置请求的权限;
4. 在 authorizeRequests() 方法中,使用 antMatchers() 方法来匹配请求路径,并通过 permitAll() 方法来允许该路径的访问;
5. 最后调用 http.csrf().disable() 方法来禁用 CSRF 防护。
举个例子,假设我们允许 /login 和 /register 路径的访问,可以这样进行配置:
```java
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login", "/register").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
http.csrf().disable();
}
}
```
这样就完成了登录白名单的设置。需要注意的是,这只是一个示例,具体的配置方式可以根据实际情况进行调整。