风人园

弱水三千,只取一瓢,便能解渴;佛法无边,奉行一法,便能得益。
随笔 - 99, 文章 - 181, 评论 - 56, 引用 - 0
数据加载中……

spring security 参数配置


  1.         // 自定义登录页面  
  2.         http.csrf().disable().formLogin().loginPage("/login")  //指定登录页的路径
  3.                 .failureUrl("/login?error=1")  
  4.                 .loginProcessingUrl("/j_spring_security_check")  
  5.                 .usernameParameter("j_username")  
  6.                 .passwordParameter("j_password").permitAll();  
  7.   
  8.         // 自定义注销  
  9.         http.logout().logoutUrl("/logout").logoutSuccessUrl("/login")  
  10.                 .invalidateHttpSession(true);  
  11.   
  12.         // session管理  
  13.         http.sessionManagement().sessionFixation().changeSessionId()  
  14.                 .maximumSessions(1).expiredUrl("/");  
  15.   
  16.         // RemeberMe  
  17.         http.rememberMe().key("webmvc#FD637E6D9C0F1A5A67082AF56CE32485"); 


// 自定义登录页面
.and()
.formLogin().loginPage("/jsp/login.jsp")
.failureUrl("/jsp/login.jsp?error=1")
.loginProcessingUrl
("/spring_security_check")
.usernameParameter("username")
.passwordParameter("password").permitAll().defaultSuccessUrl("/index.do"); //如果开启了CSRF 退出则需要使用POST访问,可以使用以下方式解决,但并不推荐
http
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
// 登陆成功后跳转的地址,以及删除的cookie名称
.logoutSuccessUrl("/jsp/login.jsp?error=logout") .invalidateHttpSession(true);


  1. .and()  
  2.         .formLogin()  
  3.         .loginPage("/login")//指定登录页是”/login”  
  4.         .permitAll()  
  5.         .successHandler(loginSuccessHandler()) //登录成功后可使用loginSuccessHandler()存储用户信息,可选。  

  1. public
     class LoginSuccessHandler extends  
  2.         SavedRequestAwareAuthenticationSuccessHandler {  
  3.     @Override    
  4.     public void onAuthenticationSuccess(HttpServletRequest request,    
  5.             HttpServletResponse response, Authentication authentication) throws IOException,    
  6.             ServletException {    
  7.         //获得授权后可得到用户信息   可使用SUserService进行数据库操作  
  8.         SysUser userDetails = (SysUser)authentication.getPrincipal();    
  9.         //输出登录提示信息    
  10.         System.out.println("管理员 " + userDetails.getName() + " 登录");    
  11.         super.onAuthenticationSuccess(request, response, authentication);    
  12.     }    }  




posted on 2018-03-19 20:33 风人园 阅读(410) 评论(0)  编辑  收藏 所属分类: SpringSecurity


只有注册用户登录后才能发表评论。


网站导航: