SpringSecurity-1-AuthenticationSuccessHandler接口(登录成功之后的处理逻辑)

@EnableWebSecurity
public class A extends WebSecurityConfigrerAdapter{
		@Override
		protected void configure(HttpSecurity http) throws Exception{
				http.anthorizeRequests().anyRequest().authenticated().and()
				//我不太明白这个processingUrl是什么意思,难道表单中的action可以不写??
				formLogin().loginPage("你的登录页面.html").loginProcessingUrl("/login").
				//以下处理自定义逻辑
				successHandler(new AuthenticationSuccessHandler(){
						@Override
						public void onAuthenticationSuccess(HttpServletRequest request,HttpServletResponse,Authentication auth){
								//这里直接写自己的处理逻辑,比如下面这段代码
								response.setContentType("application/json;charset=UTF-8");
								PrintWriter out=response.getWriter();
								out.write("一个JSON串");
						}
				})
				//此处我们可以继续点失败的逻辑
		}
}

你可能感兴趣的:(SpringSecurity)