有没有办法禁用Spring Security和登录页面的重定向.我的要求指定登录应该是导航菜单的一部分.
例:
因此,没有专用的登录页面.登录信息需要通过Ajax提交.如果发生错误,则应返回指定错误的JSON并使用正确的HTTP状态代码.如果身份验证检出它应该返回200然后javascript可以从那里处理它.
我希望这是有道理的,除非有更简单的方法来实现Spring Security.我对Spring Security没有多少经验.我认为这必须是一种常见的做法,但我没有找到太多.
当前的弹簧安全配置
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/public/**").permitAll()
.antMatchers("/about").permitAll()
.anyRequest().fullyAuthenticated()
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error")
.usernameParameter("email")
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.deleteCookies("remember-me")
.logoutSuccessUrl("/")
.permitAll()
.and()
.rememberMe();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(new BCryptPasswordEncoder());
}
Run Code Online (Sandbox Code Playgroud)
更新:
我尝试使用HttpBasic()然后它要求登录信用无关紧要什么及其丑陋的浏览器弹出窗口是最终用户不能接受的.看起来我可能需要扩展AuthenticationEntryPoint.
在一天结束时,我需要Spring安全性发回JSON,说验证成功或失败.
我已经有了表单登录和Basic auth并在a的帮助下并排工作DelegatingAuthenticationEntryPoint.
我要做的是让用户通过登录表单通过标准"A"进行身份验证,并让用户通过基本身份验证请求根据标准"B"进行身份验证.
某些应用程序的资源通过RESTful服务公开(可通过Basic auth访问).他们可以输入生成的键/值对,而不是让用户输入自己的凭据来进行REST服务调用,而是专门用于REST服务,以后可以由用户或应用程序管理员撤销.
我更愿意在两种身份验证方法之间共享尽可能多的特定于安全性的bean.我知道我需要单独的UserDetailsServices,因为表单登录查询我的users表,Basic auth将查询我的service_credentials表.
在Spring Security中实现此类配置的正确方法是什么?