【发布时间】:2018-09-10 15:33:13
【问题描述】:
我使用 Spring boot 作为我的 Rest API,使用 Angular 作为我的前端框架。
我是 Angular 的初学者,正在努力使用 Angular 进行身份验证。我在网上看了一些文章,但都很难掌握。
这是我的身份验证生成器配置方法:-
@Override
protected void configure(AuthenticationManagerBuilder auth) throws
Exception{
auth.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());
}
这是我的配置
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().requireCsrfProtectionMatcher(new AntPathRequestMatcher("**/login"))
.and()
.authorizeRequests()
.antMatchers("/profile").hasAnyRole("USER", "ADMIN")
.antMatchers("admin/**").hasRole("ADMIN")
.antMatchers("user/**").hasRole("USER")
.antMatchers("/","/faq","/donate","/recent","/signup","/register").permitAll()
.antMatchers("/adduser/**").permitAll()
.antMatchers("/h2/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error=true")
.successHandler(successHandler())
.defaultSuccessUrl("/user/profile")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/login?logout")
.permitAll();
}
我已经成功实现了用户认证和授权 使用百里香,但现在我正试图以角度实现它以用于学习目的。
我应该进行 JWT 身份验证(其中包括很多 Spring 的锅炉代码)?有没有其他方法或替代解决方案?
由于找不到任何其他解决方案,我可以通过哪些可能的方式来实现这一点。请帮忙...
【问题讨论】:
-
你有什么错误吗?你的数据库配置在哪里?
标签: spring angular spring-boot