java - Spring Security 登录和注册
问题描述
我想用邮递员登录到我的网络应用程序,这是安全的。在网络浏览器中正常我可以写我的登录名和密码,但是当我想在端点下点击例如 /login 时如何通过邮递员登录?我应该创建将处理这种情况的休息控制器,或者可能是自动处理这种情况的方式?在 /login?username=admin&password=admin 之类的 url 中发送用户名和密码是一个好主意,还是在正文中更好?下面是我的安全配置:
安全配置.java
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private MyUserDetailsService userDetailsService;
@Autowired
private UserRepository userRepository;
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider());
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(encoder());
return authProvider;
}
@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder(11);
}
@Override
protected UserDetailsService userDetailsService() {
return userDetailsService;
}
@Bean
public SimpleSocialUserDetailsService simpleSocialUserDetailsService() {
return new SimpleSocialUserDetailsService(userRepository);
}
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.csrf().disable()
.headers().frameOptions().disable()
.and()
.authorizeRequests()
.antMatchers("/login*", "/success*").anonymous()
.antMatchers("/auth/**", "/signup/**", "/css/*", "/webjars/**","/js/*","/image/*").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/login")
.successForwardUrl("/tasks")
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/logout-success").permitAll()
.and()
.apply(new SpringSocialConfigurer());
}
}
解决方案
推荐阅读
- c# - 我的 int 'LastTwoChars' 导致“StartIndex 不能小于零”。例外。我了解异常,但无法解决
- android - 通过 firebase 云消息将数据从 api 发送到我的应用程序
- r - For 或 Repeat 循环根据字符串值而不是数字序列进行过滤
- python - 插入或替换添加一个全新的行 SQLite
- android - 如何在 Flutter 中将用户输入数据从一个页面传递到另一个页面?
- ios - 如何正确换行长文本?
- python - 我想弄清楚将 playerX 移动到屏幕有什么问题?我想移动 playerX += .1 但出现错误?
- python - Python - 从文件夹目录创建字典
- c# - 在 Identity Asp.net core 3 MVC 中创建服务 IUserStore 时出错
- java - 智能支付按钮服务器集成