我正在使用 spring-data-rest 来开发我的 API,我必须使用 spring security 来验证请求。当我通过身份验证详细信息时,我必须生成一个 API+密钥并将其存储在客户端并与来自该主题的所有进一步请求一起发送。并且必须在每个请求中检查它,如果他们注销,我必须在他们再次登录时重新生成密钥。我已经像这样实现了安全性,
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth.inMemoryAuthentication()
.withUser("test").password("test").roles("test");
}
@Override protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.antMatchers("/**").hasRole("test")
.anyRequest().anonymous()
.and()
.httpBasic()
.and()
.csrf()
.disable();
}
}
并通过 java config 注册过滤器。
我已经看过这个教程,这与我正在寻找的完全一样。我不擅长弹簧,所以我需要知道移动是否正确。
我将在我的网站上实现 facebook 登录并且没有注册,每个人都将使用 facebook 登录来访问网站或我的应用程序。所以我也不会有密码。以适当的方式指导我如何取得进展以实现这一目标。提前致谢。