風人園

          弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
          隨筆 - 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 風人園 閱讀(437) 評論(0)  編輯  收藏 所屬分類: SpringSecurity


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 海城市| 项城市| 射洪县| 嘉鱼县| 铁岭县| 南乐县| 建瓯市| 随州市| 平远县| 怀化市| 祁东县| 毕节市| 监利县| 孝感市| 确山县| 临安市| 神池县| 密云县| 西贡区| 江口县| 靖西县| 准格尔旗| 晋江市| 鄂托克前旗| 浪卡子县| 泸溪县| 宁城县| 永仁县| 黑河市| 安宁市| 山阴县| 怀远县| 万盛区| 邢台市| 青冈县| 铁岭县| 石楼县| 察哈| 满洲里市| 垣曲县| 准格尔旗|