寻找与角4和更多的春季启动应用程序样本
问题描述:
我有一个完整的堆栈Web应用程序(角4 +春季启动+春季Web +春季安全)。 我想添加其他弹簧引导应用程序(微服务),但具有相同的身份验证。寻找与角4和更多的春季启动应用程序样本
如何分享会议?
现在,这里是我的我的第一个春天启动应用程序的配置:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.antMatchers("/health").hasRole("SUPERUSER")
.anyRequest().authenticated().and()
.formLogin().loginPage("/login").permitAll().and().logout().permitAll();
// @formatter:on
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
auth.inMemoryAuthentication().withUser("admin").password("secret").roles("SUPERUSER");
}
}
编辑1:
我添加其他的弹簧启动应用程序(Gateway与我的数据库)+在此网关和其他Spring引导应用程序之间使用JWT
编辑2:
我在github here
答
一个很好的例子中,你可以尝试从状态移动(与服务器端的会话)的无状态架构。在这种情况下,可以使用JSON Web Tokens执行认证。
+0
@lllia Smolii,我尝试使用io.jsonwebtoken:jjwt Maven依赖,谢谢 – sgrillon
[Spring Security:JWT token for API和session for web]的可能副本(https://stackoverflow.com/questions/44970848/spring-security-jwt-token-for-api-and-session-for- web) –
@kemsky, 投票比投票更容易!!!!! :( – sgrillon
@Andrei Epure,您阅读了Illia Smolii(JWT)的答案,并且将“复制后的帖子”添加到其他弹簧引导应用程序(网关与我的数据库)+在此网关和其他Spring引导应用程序之间使用JWT – sgrillon